Permalink
Browse files

Merge branch 'branch3.2'

  • Loading branch information...
2 parents 5a9194f + 1cb446e commit de480f941b0859da809ed449acc254591e2ad0cf @bdarnell bdarnell committed Jan 17, 2014
Showing with 45 additions and 11 deletions.
  1. +9 −1 .travis.yml
  2. +8 −2 setup.py
  3. +8 −5 tornado/speedups.c
  4. +14 −0 tornado/test/websocket_test.py
  5. +6 −3 tornado/websocket.py
View
@@ -19,10 +19,17 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy' && $DEPS == true ]]; then pip install --use-mirrors futures mock; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.2' && $DEPS == true ]]; then pip install --use-mirrors pycares mock; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.3' && $DEPS == true ]]; then pip install --use-mirrors pycares; fi
+ # On travis the extension should always be built
+ - if [[ $TRAVIS_PYTHON_VERSION != 'pypy' ]]; then export TORNADO_EXTENSION=1; fi
- python setup.py install
- pip install --use-mirrors coveralls
script:
+ # Get out of the source directory before running tests to avoid PYTHONPATH
+ # confusion. This is necessary to ensure that the speedups module can
+ # be found in the installation directory.
+ - cd maint
+ - if [[ $TRAVIS_PYTHON_VERSION != 'pypy' ]]; then export TORNADO_EXTENSION=1; fi
- export TARGET="-m tornado.test.runtests"
# We use "python -m coverage" instead of the "bin/coverage" script
# so we can pass additional arguments to python. However, this doesn't
@@ -41,7 +48,8 @@ script:
- if [[ $TRAVIS_PYTHON_VERSION == 2* && $DEPS == true ]]; then python $TARGET --resolver=tornado.platform.twisted.TwistedResolver; fi
- if [[ $TRAVIS_PYTHON_VERSION != pypy && $DEPS == true ]]; then python $TARGET --resolver=tornado.platform.caresresolver.CaresResolver; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then python $TARGET --ioloop_time_monotonic; fi
- - if [[ $TRAVIS_PYTHON_VERSION == '2.7' && $DEPS == true ]]; then cd docs && mkdir sphinx-out && sphinx-build -E -n -W -b html . sphinx-out; fi
+ - export TORNADO_EXTENSION=0
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' && $DEPS == true ]]; then cd ../docs && mkdir sphinx-out && sphinx-build -E -n -W -b html . sphinx-out; fi
after_success:
coveralls
View
@@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import os
import platform
import sys
import warnings
@@ -118,14 +119,20 @@ def build_extension(self, ext):
with open('README.rst') as f:
kwargs['long_description'] = f.read()
-if platform.python_implementation() == 'CPython':
+if (platform.python_implementation() == 'CPython' and
+ os.environ.get('TORNADO_EXTENSION') != '0'):
# This extension builds and works on pypy as well, although pypy's jit
# produces equivalent performance.
kwargs['ext_modules'] = [
Extension('tornado.speedups',
sources=['tornado/speedups.c']),
]
+ if os.environ.get('TORNADO_EXTENSION') != '1':
+ # Unless the user has specified that the extension is mandatory,
+ # fall back to the pure-python implementation on any build failure.
+ kwargs['cmdclass'] = {'build_ext': custom_build_ext}
+
if setuptools is not None:
# If setuptools is not available, you're on your own for dependencies.
if sys.version_info < (3, 2):
@@ -170,6 +177,5 @@ def build_extension(self, ext):
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
- cmdclass={"build_ext": custom_build_ext},
**kwargs
)
View
@@ -1,21 +1,24 @@
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
static PyObject* websocket_mask(PyObject* self, PyObject* args) {
const char* mask;
- int mask_len;
+ Py_ssize_t mask_len;
const char* data;
- int data_len;
- int i;
+ Py_ssize_t data_len;
+ Py_ssize_t i;
+ PyObject* result;
+ char* buf;
if (!PyArg_ParseTuple(args, "s#s#", &mask, &mask_len, &data, &data_len)) {
return NULL;
}
- PyObject* result = PyBytes_FromStringAndSize(NULL, data_len);
+ result = PyBytes_FromStringAndSize(NULL, data_len);
if (!result) {
return NULL;
}
- char* buf = PyBytes_AsString(result);
+ buf = PyBytes_AsString(result);
for (i = 0; i < data_len; i++) {
buf[i] = data[i] ^ mask[i % 4];
}
@@ -1,10 +1,24 @@
from __future__ import absolute_import, division, print_function, with_statement
+
+import traceback
+
from tornado.concurrent import Future
from tornado.httpclient import HTTPError, HTTPRequest
from tornado.log import gen_log
from tornado.testing import AsyncHTTPTestCase, gen_test, bind_unused_port, ExpectLog
from tornado.test.util import unittest, skipOnTravis
from tornado.web import Application, RequestHandler
+
+try:
+ import tornado.websocket
+except ImportError:
+ # The unittest module presents misleading errors on ImportError
+ # (it acts as if websocket_test could not be found, hiding the underlying
+ # error). If we get an ImportError here (which could happen due to
+ # TORNADO_EXTENSION=1), print some extra information before failing.
+ traceback.print_exc()
+ raise
+
from tornado.websocket import WebSocketHandler, websocket_connect, WebSocketError, _websocket_mask_python
try:
View
@@ -913,12 +913,15 @@ def _websocket_mask_python(mask, data):
else:
return unmasked.tostring()
-if os.environ.get('TORNADO_NO_EXTENSION'):
- # This environment variable exists to make it easier to do performance comparisons;
- # it's not guaranteed to remain supported in the future.
+if (os.environ.get('TORNADO_NO_EXTENSION') or
+ os.environ.get('TORNADO_EXTENSION') == '0'):
+ # These environment variables exist to make it easier to do performance
+ # comparisons; they are not guaranteed to remain supported in the future.
_websocket_mask = _websocket_mask_python
else:
try:
from tornado.speedups import websocket_mask as _websocket_mask
except ImportError:
+ if os.environ.get('TORNADO_EXTENSION') == '1':
+ raise
_websocket_mask = _websocket_mask_python

0 comments on commit de480f9

Please sign in to comment.