Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: reflex-support Changeset: r71117:3fb585ce5d69 Date: 2014-04-28 15:25 -0700 http://bitbucket.org/pypy/pypy/changeset/3fb585ce5d69/
Log: merge default into branch diff --git a/dotviewer/graphserver.py b/dotviewer/graphserver.py --- a/dotviewer/graphserver.py +++ b/dotviewer/graphserver.py @@ -160,15 +160,14 @@ " | instructions in dotviewer/sshgraphserver.py\n") try: import pygame - except ImportError: + if isinstance(e, pygame.error): + print >> f, help + except Exception, e: f.seek(0) f.truncate() - print >> f, "ImportError" + print >> f, "%s: %s" % (e.__class__.__name__, e) print >> f, " | Pygame is not installed; either install it, or" print >> f, help - else: - if isinstance(e, pygame.error): - print >> f, help io.sendmsg(msgstruct.MSG_ERROR, f.getvalue()) else: listen_server(sys.argv[1]) diff --git a/pypy/doc/getting-started.rst b/pypy/doc/getting-started.rst --- a/pypy/doc/getting-started.rst +++ b/pypy/doc/getting-started.rst @@ -76,7 +76,7 @@ .. code-block:: console $ curl -O http://python-distribute.org/distribute_setup.py - $ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py + $ curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py $ ./pypy-2.1/bin/pypy distribute_setup.py $ ./pypy-2.1/bin/pypy get-pip.py $ ./pypy-2.1/bin/pip install pygments # for example diff --git a/pypy/doc/release-2.3.0.rst b/pypy/doc/release-2.3.0.rst --- a/pypy/doc/release-2.3.0.rst +++ b/pypy/doc/release-2.3.0.rst @@ -1,11 +1,17 @@ ======================================= -PyPy 2.3 - XXXX TODO +PyPy 2.3 - Easier Than Ever ======================================= We're pleased to announce PyPy 2.3, which targets version 2.7.6 of the Python language. This release updates the stdlib from 2.7.3, jumping directly to 2.7.6. -This release also contains several bugfixes and performance improvements. +This release also contains several bugfixes and performance improvements, +many generated by real users finding corner cases our `TDD`_ methods missed. +`CFFI`_ has made it easier than ever to use existing C code with both cpython +and PyPy, easing the transition for packages like `cryptography`_, `Pillow`_ +(Python Imaging Library [Fork]), a basic port of `pygame-cffi`_, and others. + +PyPy can now be embedded in a hosting application, for instance inside `uWSGI`_ You can download the PyPy 2.3 release here: @@ -17,72 +23,112 @@ Please consider donating more so we can finish those projects! The three projects are: -* Py3k (supporting Python 3.x): the release PyPy3 2.2 is imminent. +* `Py3k`_ (supporting Python 3.x): the release PyPy3 2.2 is imminent. -* STM (software transactional memory): a preview will be released very soon, - as soon as we fix a few bugs +* `STM`_ (software transactional memory): a preview will be released very soon, + once we fix a few bugs -* NumPy: the work done is included in the PyPy 2.2 release. More details below. +* `NumPy`_ the work done is included in the PyPy 2.2 release. More details below. -.. _`Raspberry Pi Foundation`: http://www.raspberrypi.org +.. _`Py3k`: http://pypy.org/py3donate.html +.. _`STM`: http://pypy.org/tmdonate2.html +.. _ `Numpy`: http://pypy.org/numpydonate.html +.. _`TDD`: http://doc.pypy.org/en/latest/how-to-contribute.html +.. _`CFFI`: http://cffi.readthedocs.org +.. _`cryptography`: https://cryptography.io +.. _`Pillow`: https://pypi.python.org/pypi/Pillow/2.4.0 +.. _`pygame-cffi`: https://github.com/CTPUG/pygame_cffi +.. _`uWSGI`: http://uwsgi-docs.readthedocs.org/en/latest/PyPy.html What is PyPy? ============= PyPy is a very compliant Python interpreter, almost a drop-in replacement for -CPython 2.7. It's fast (`pypy 2.2 and cpython 2.7.2`_ performance comparison) +CPython 2.7. It's fast (`pypy 2.2 and cpython 2.7.2`_ performance comparison; +note that the latest cpython is not faster than cpython 2.7.2) due to its integrated tracing JIT compiler. -This release supports x86 machines running Linux 32/64, Mac OS X 64, Windows -32, or ARM (ARMv6 or ARMv7, with VFPv3). +This release supports x86 machines running Linux 32/64, Mac OS X 64, Windows, +and OpenBSD, +as well as newer ARM hardware (ARMv6 or ARMv7, with VFPv3) running Linux. -Work on the native Windows 64 is still stalling, we would welcome a volunteer -to handle that. +While we support 32 bit python on Windows, work on the native Windows 64 +bit python is still stalling, we would welcome a volunteer +to `handle that`_. .. _`pypy 2.2 and cpython 2.7.2`: http://speed.pypy.org +.. _`handle that`: http://doc.pypy.org/en/latest/windows.html#what-is-missing-for-a-full-64-bit-translation Highlights ========== -* Our Garbage Collector is now "incremental". It should avoid almost - all pauses due to a major collection taking place. Previously, it - would pause the program (rarely) to walk all live objects, which - could take arbitrarily long if your process is using a whole lot of - RAM. Now the same work is done in steps. This should make PyPy - more responsive, e.g. in games. There are still other pauses, from - the GC and the JIT, but they should be on the order of 5 - milliseconds each. +Bugfixes +-------- -* The JIT counters for hot code were never reset, which meant that a - process running for long enough would eventually JIT-compile more - and more rarely executed code. Not only is it useless to compile - such code, but as more compiled code means more memory used, this - gives the impression of a memory leak. This has been tentatively - fixed by decreasing the counters from time to time. +Many issues were cleaned up after being reported by users to https://bugs.pypy.org (ignore the bad SSL certificate) or on IRC at #pypy. Note that we consider +performance slowdowns as bugs. -* NumPy has been split: now PyPy only contains the core module, called - ``_numpypy``. The ``numpy`` module itself has been moved to - ``https://bitbucket.org/pypy/numpy`` and ``numpypy`` disappeared. - You need to install NumPy separately with a virtualenv: +* The ARM port no longer crashes on unaligned memory access to floats and doubles, + and singlefloats are supported in the JIT. + +* Generators are faster since they now skip unecessary cleanup + +* A first time contributor simplified JIT traces by adding integer bound + propagation in indexing and logical operations. + +* Optimize consecutive dictionary lookups of the same key in a chain + +* Our extensive pre-translation test suite now runs nightly on more platforms + +* Fix issues with reimporting builtin modules + +* Fix a rpython bug with loop-unrolling that appeared in the `HippyVM`_ PHP port + +.. _`HippyVM`: http://www.hippyvm.com + +New Platforms and Features +-------------------------- + +* Support for OpenBSD + +* Code cleanup: we continue to prune out old and unused code, and to refactor + large parts of the codebase. We have sepearated rpython from the PyPy python + interpreter, and rpython is seeing use in other dynamic language projects. + +* Support for precompiled headers in the build process for MSVC + +* Support for objects with __int__ and __float__ methods + +* Tweak support of errno in cpyext (the PyPy implemenation of the capi) + + +Numpy +----- +Numpy support has been split into a builtin ``_numpy`` module and a +fork of the numpy code base adapted to pypy at + ``https://bitbucket.org/pypy/numpy``. +You need to install NumPy separately with a virtualenv: ``pip install git+https://bitbucket.org/pypy/numpy.git``; or directly: ``git clone https://bitbucket.org/pypy/numpy.git``; ``cd numpy``; ``pypy setup.py install``. -* non-inlined calls have less overhead +* NumPy support has been improved, many failures in indexing, dtypes, + and scalars were corrected. We are slowly approaching our goal of passing + the numpy test suite. We still do not support object or unicode ndarrays. -* Things that use ``sys.set_trace`` are now JITted (like coverage) +* speed of iteration in dot() is now within 1.5x of the numpy c + implementation (without BLAS acceleration). Since the same array + iterator is used throughout the ``_numpy`` module, speed increases should + be apparent in all Numpy functionality. -* JSON decoding is now very fast (JSON encoding was already very fast) +* Most of the core functionality of nditer has been implemented. -* various buffer copying methods experience speedups (like list-of-ints to - ``int[]`` buffer from cffi) +* A cffi-based ``numpy.random`` module is available as a branch in the numpy + repository, it will be merged soon after this release. -* We finally wrote (hopefully) all the missing ``os.xxx()`` functions, - including ``os.startfile()`` on Windows and a handful of rare ones - on Posix. +* enhancements to the PyPy JIT were made to support virtualizing the raw_store/raw_load memory operations used in numpy arrays. Further work remains here in virtualizing the alloc_raw_storage when possible. This will allow scalars to have storages but still be virtualized when possible in loops. -* numpy has a rudimentary C API that cooperates with ``cpyext`` +Cheers +The PyPy Team -Cheers, -Armin Rigo and Maciej Fijalkowski diff --git a/pypy/doc/sandbox.rst b/pypy/doc/sandbox.rst --- a/pypy/doc/sandbox.rst +++ b/pypy/doc/sandbox.rst @@ -42,6 +42,10 @@ use this sandboxed PyPy from a regular Python interpreter (CPython, or an unsandboxed PyPy). Contributions welcome. +.. warning:: + + Tested with PyPy2. May not work out of the box with PyPy3. + Overview -------- diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -299,9 +299,13 @@ """ self._application_traceback = traceback -@specialize.memo() + +class ClearedOpErr: + def __init__(self, space): + self.operr = OperationError(space.w_None, space.w_None) + def get_cleared_operation_error(space): - return OperationError(space.w_None, space.w_None) + return space.fromcache(ClearedOpErr).operr # ____________________________________________________________ # optimization only: avoid the slowest operation -- the string diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py --- a/pypy/interpreter/executioncontext.py +++ b/pypy/interpreter/executioncontext.py @@ -205,11 +205,14 @@ def sys_exc_info(self): # attn: the result is not the wrapped sys.exc_info() !!! """Implements sys.exc_info(). Return an OperationError instance or None.""" - frame = self.gettopframe_nohidden() + frame = self.gettopframe() while frame: if frame.last_exception is not None: - return frame.last_exception - frame = self.getnextframe_nohidden(frame) + if (not frame.hide() or + frame.last_exception is + get_cleared_operation_error(self.space)): + return frame.last_exception + frame = frame.f_backref() return None def set_sys_exc_info(self, operror): diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py --- a/pypy/interpreter/main.py +++ b/pypy/interpreter/main.py @@ -15,10 +15,11 @@ space.setitem(w_modules, w_main, mainmodule) return mainmodule + def compilecode(space, source, filename, cmd='exec'): w = space.wrap - w_code = space.builtin.call('compile', - w(source), w(filename), w(cmd), w(0), w(0)) + w_code = space.builtin.call( + 'compile', w(source), w(filename), w(cmd), w(0), w(0)) pycode = space.interp_w(eval.Code, w_code) return pycode @@ -28,7 +29,7 @@ cmd = 'eval' else: cmd = 'exec' - + try: if space is None: from pypy.objspace.std import StdObjSpace @@ -55,18 +56,22 @@ operationerr.record_interpreter_traceback() raise + def run_string(source, filename=None, space=None): _run_eval_string(source, filename, space, False) + def eval_string(source, filename=None, space=None): return _run_eval_string(source, filename, space, True) + def run_file(filename, space=None): - if __name__=='__main__': + if __name__ == '__main__': print "Running %r with %r" % (filename, space) istring = open(filename).read() run_string(istring, filename, space) + def run_module(module_name, args, space=None): """Implements PEP 338 'Executing modules as scripts', overwriting sys.argv[1:] using `args` and executing the module `module_name`. @@ -89,7 +94,6 @@ return space.call_function(w_run_module, w(module_name), space.w_None, w('__main__'), space.w_True) -# ____________________________________________________________ def run_toplevel(space, f, verbose=False): """Calls f() and handle all OperationErrors. diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -351,17 +351,17 @@ self.promote_step = promote_step def descr_new(space, w_subtype, w_start, w_stop=None, w_step=None): - start = _toint(space, w_start) + start = space.int_w(w_start) if space.is_none(w_step): # no step argument provided step = 1 promote_step = True else: - step = _toint(space, w_step) + step = space.int_w(w_step) promote_step = False if space.is_none(w_stop): # only 1 argument provided start, stop = 0, start else: - stop = _toint(space, w_stop) + stop = space.int_w(w_stop) howmany = get_len_of_range(space, start, stop, step) obj = space.allocate_instance(W_XRange, w_subtype) W_XRange.__init__(obj, space, start, howmany, step, promote_step) @@ -425,11 +425,6 @@ minint = -sys.maxint - 1 return minint if last < minint - step else last + step -def _toint(space, w_obj): - # this also supports float arguments. CPython still does, too. - # needs a bit more thinking in general... - return space.int_w(space.int(w_obj)) - W_XRange.typedef = TypeDef("xrange", __new__ = interp2app(W_XRange.descr_new.im_func), __repr__ = interp2app(W_XRange.descr_repr), @@ -441,6 +436,7 @@ ) W_XRange.typedef.acceptable_as_base_class = False + class W_XRangeIterator(W_Root): def __init__(self, space, current, remaining, step): self.space = space @@ -488,7 +484,10 @@ ) W_XRangeIterator.typedef.acceptable_as_base_class = False + class W_XRangeStepOneIterator(W_XRangeIterator): + _immutable_fields_ = ['stop'] + def __init__(self, space, start, stop): self.space = space self.current = start diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py --- a/pypy/module/__builtin__/test/test_builtin.py +++ b/pypy/module/__builtin__/test/test_builtin.py @@ -311,14 +311,14 @@ def test_xrange_len(self): x = xrange(33) assert len(x) == 33 - x = xrange(33.2) - assert len(x) == 33 + exc = raises(TypeError, xrange, 33.2) + assert "integer" in str(exc.value) x = xrange(33,0,-1) assert len(x) == 33 x = xrange(33,0) assert len(x) == 0 - x = xrange(33,0.2) - assert len(x) == 0 + exc = raises(TypeError, xrange, 33, 0.2) + assert "integer" in str(exc.value) x = xrange(0,33) assert len(x) == 33 x = xrange(0,33,-1) diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py --- a/pypy/module/__builtin__/test/test_functional.py +++ b/pypy/module/__builtin__/test/test_functional.py @@ -1,5 +1,4 @@ class AppTestMap: - def test_trivial_map_one_seq(self): assert map(lambda x: x+2, [1, 2, 3, 4]) == [3, 4, 5, 6] @@ -77,6 +76,7 @@ assert result == [(2, 7), (1, 6), (None, 5), (None, 4), (None, 3), (None, 2), (None, 1)] + class AppTestZip: def test_one_list(self): assert zip([1,2,3]) == [(1,), (2,), (3,)] @@ -93,6 +93,7 @@ yield None assert zip(Foo()) == [] + class AppTestReduce: def test_None(self): raises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None) @@ -105,6 +106,7 @@ assert reduce(lambda x, y: x-y, [10, 2, 8]) == 0 assert reduce(lambda x, y: x-y, [2, 8], 10) == 0 + class AppTestFilter: def test_None(self): assert filter(None, ['a', 'b', 1, 0, None]) == ['a', 'b', 1] @@ -125,6 +127,7 @@ return i * 10 assert filter(lambda x: x != 20, T("abcd")) == (0, 10, 30) + class AppTestXRange: def test_xrange(self): x = xrange(2, 9, 3) @@ -155,7 +158,8 @@ assert list(xrange(0, 10, A())) == [0, 5] def test_xrange_float(self): - assert list(xrange(0.1, 2.0, 1.1)) == [0, 1] + exc = raises(TypeError, xrange, 0.1, 2.0, 1.1) + assert "integer" in str(exc.value) def test_xrange_long(self): import sys @@ -218,6 +222,7 @@ assert list(reversed(list(reversed("hello")))) == ['h','e','l','l','o'] raises(TypeError, reversed, reversed("hello")) + class AppTestApply: def test_apply(self): def f(*args, **kw): @@ -228,6 +233,7 @@ assert apply(f, args) == (args, {}) assert apply(f, args, kw) == (args, kw) + class AppTestAllAny: """ These are copied directly and replicated from the Python 2.5 source code. @@ -277,6 +283,7 @@ S = [10, 20, 30] assert any([x > 42 for x in S]) == False + class AppTestMinMax: def test_min(self): assert min(1, 2) == 1 diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py --- a/pypy/module/_continuation/interp_continuation.py +++ b/pypy/module/_continuation/interp_continuation.py @@ -1,6 +1,6 @@ from rpython.rlib.rstacklet import StackletThread from rpython.rlib import jit -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, get_cleared_operation_error from pypy.interpreter.executioncontext import ExecutionContext from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.typedef import TypeDef @@ -39,6 +39,7 @@ bottomframe.locals_stack_w[1] = w_callable bottomframe.locals_stack_w[2] = w_args bottomframe.locals_stack_w[3] = w_kwds + bottomframe.last_exception = get_cleared_operation_error(space) self.bottomframe = bottomframe # global_state.origin = self diff --git a/pypy/module/_continuation/test/test_stacklet.py b/pypy/module/_continuation/test/test_stacklet.py --- a/pypy/module/_continuation/test/test_stacklet.py +++ b/pypy/module/_continuation/test/test_stacklet.py @@ -684,3 +684,17 @@ execfile(self.translated, d) d['set_fast_mode']() d['test_various_depths']() + + def test_exc_info_doesnt_follow_continuations(self): + import sys + from _continuation import continulet + # + def f1(c1): + return sys.exc_info() + # + c1 = continulet(f1) + try: + 1 // 0 + except ZeroDivisionError: + got = c1.switch() + assert got == (None, None, None) diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx --- a/pypy/module/cppyy/src/dummy_backend.cxx +++ b/pypy/module/cppyy/src/dummy_backend.cxx @@ -521,6 +521,15 @@ /* misc helpers ----------------------------------------------------------- */ +#if defined(_MSC_VER) +long long cppyy_strtoll(const char* str) { + return _strtoi64(str, NULL, 0); +} + +extern "C" unsigned long long cppyy_strtoull(const char* str) { + return _strtoui64(str, NULL, 0); +} +#else long long cppyy_strtoll(const char* str) { return strtoll(str, NULL, 0); } @@ -528,6 +537,7 @@ extern "C" unsigned long long cppyy_strtoull(const char* str) { return strtoull(str, NULL, 0); } +#endif void cppyy_free(void* ptr) { free(ptr); diff --git a/pypy/module/cppyy/test/test_zjit.py b/pypy/module/cppyy/test/test_zjit.py --- a/pypy/module/cppyy/test/test_zjit.py +++ b/pypy/module/cppyy/test/test_zjit.py @@ -104,7 +104,6 @@ class dummy: pass self.config = dummy() self.config.translating = False - self.BUF_SIMPLE = 1 def issequence_w(self, w_obj): return True diff --git a/pypy/module/pypyjit/test_pypy_c/test_buffers.py b/pypy/module/pypyjit/test_pypy_c/test_buffers.py --- a/pypy/module/pypyjit/test_pypy_c/test_buffers.py +++ b/pypy/module/pypyjit/test_pypy_c/test_buffers.py @@ -3,16 +3,18 @@ class TestBuffers(BaseTestPyPyC): def test_re_match(self): - def main(): + def main(n): import re import array p = re.compile('.+') a = array.array('c', 'test' * 1000) i = 0 - while i < 5000: + while i < n: i += 1 p.match(a) # ID: match - log = self.run(main, []) + return i + log = self.run(main, [1000]) + assert log.result == 1000 loop, = log.loops_by_filename(self.filepath) assert loop.match_by_id('match', """ guard_not_invalidated(descr=...) @@ -21,8 +23,5 @@ guard_false(i67, descr=...) i69 = int_gt(., i65) guard_true(i69, descr=...) - guard_not_invalidated(descr=...) - i74 = getfield_raw(., descr=...) - i75 = int_lt(i74, 0) - guard_false(i75, descr=...) + --TICK-- """) diff --git a/pypy/module/pypyjit/test_pypy_c/test_weakref.py b/pypy/module/pypyjit/test_pypy_c/test_weakref.py --- a/pypy/module/pypyjit/test_pypy_c/test_weakref.py +++ b/pypy/module/pypyjit/test_pypy_c/test_weakref.py @@ -20,8 +20,7 @@ loop, = log.loops_by_filename(self.filepath) assert loop.match(""" i58 = getfield_gc(p18, descr=<FieldS pypy.module.__builtin__.functional.W_XRangeIterator.inst_current .>) - i59 = getfield_gc(p18, descr=<FieldS pypy.module.__builtin__.functional.W_XRangeStepOneIterator.inst_stop \d+>) - i60 = int_lt(i58, i59) + i60 = int_lt(i58, i31) guard_true(i60, descr=...) i61 = int_add(i58, 1) p62 = getfield_gc(ConstPtr(ptr37), descr=<FieldP pypy.objspace.std.dictmultiobject.W_DictMultiObject.inst_strategy \d+>) diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py --- a/pypy/module/sys/version.py +++ b/pypy/module/sys/version.py @@ -14,7 +14,8 @@ if platform.name == 'msvc': COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600) -elif platform.cc is not None and platform.cc.startswith(('gcc', 'clang')): +elif platform.cc is not None and \ + os.path.basename(platform.cc).startswith(('gcc', 'clang')): from rpython.rtyper.tool import rffi_platform COMPILER_INFO = 'GCC ' + rffi_platform.getdefinedstring('__VERSION__', '') else: diff --git a/pypy/module/termios/interp_termios.py b/pypy/module/termios/interp_termios.py --- a/pypy/module/termios/interp_termios.py +++ b/pypy/module/termios/interp_termios.py @@ -4,7 +4,7 @@ """ from pypy.interpreter.gateway import unwrap_spec -from pypy.interpreter.error import wrap_oserror +from pypy.interpreter.error import wrap_oserror, OperationError from rpython.rlib import rtermios import termios @@ -19,6 +19,10 @@ @unwrap_spec(when=int) def tcsetattr(space, w_fd, when, w_attributes): fd = space.c_filedescriptor_w(w_fd) + if not space.isinstance_w(w_attributes, space.w_list) or \ + space.len_w(w_attributes) != 7: + raise OperationError(space.w_TypeError, space.wrap( + "tcsetattr, arg 3: must be 7 element list")) w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed, w_cc = \ space.unpackiterable(w_attributes, expected_length=7) w_builtin = space.getbuiltinmodule('__builtin__') diff --git a/pypy/module/termios/test/test_termios.py b/pypy/module/termios/test/test_termios.py --- a/pypy/module/termios/test/test_termios.py +++ b/pypy/module/termios/test/test_termios.py @@ -86,7 +86,7 @@ child.expect('ok!') def test_ioctl_termios(self): - source = py.code.Source(""" + source = py.code.Source(r""" import termios import fcntl lgt = len(fcntl.ioctl(2, termios.TIOCGWINSZ, '\000'*8)) @@ -149,4 +149,7 @@ def test_error_tcsetattr(self): import termios - raises(ValueError, termios.tcsetattr, 0, 1, (1, 2)) + exc = raises(TypeError, termios.tcsetattr, 0, 1, (1, 2)) + assert str(exc.value) == "tcsetattr, arg 3: must be 7 element list" + exc = raises(TypeError, termios.tcsetattr, 0, 1, (1, 2, 3, 4, 5, 6, 7)) + assert str(exc.value) == "tcsetattr, arg 3: must be 7 element list" diff --git a/pypy/module/test_lib_pypy/test_greenlet.py b/pypy/module/test_lib_pypy/test_greenlet.py --- a/pypy/module/test_lib_pypy/test_greenlet.py +++ b/pypy/module/test_lib_pypy/test_greenlet.py @@ -289,6 +289,24 @@ greenlet(f).switch() + def test_exc_info_save_restore2(self): + import sys + from greenlet import greenlet + + result = [] + + def f(): + result.append(sys.exc_info()) + + g = greenlet(f) + try: + 1 / 0 + except ZeroDivisionError: + g.switch() + + assert result == [(None, None, None)] + + def test_gr_frame(self): from greenlet import greenlet import sys diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py --- a/pypy/module/zipimport/interp_zipimport.py +++ b/pypy/module/zipimport/interp_zipimport.py @@ -56,6 +56,8 @@ w = space.wrap w_d = space.newdict() for key, info in w_zipimporter.zip_file.NameToInfo.iteritems(): + if ZIPSEP != os.path.sep: + key = key.replace(ZIPSEP, os.path.sep) space.setitem(w_d, w(key), space.newtuple([ w(info.filename), w(info.compress_type), w(info.compress_size), w(info.file_size), w(info.file_offset), w(info.dostime), diff --git a/pypy/module/zipimport/test/test_undocumented.py b/pypy/module/zipimport/test/test_undocumented.py --- a/pypy/module/zipimport/test/test_undocumented.py +++ b/pypy/module/zipimport/test/test_undocumented.py @@ -135,8 +135,7 @@ importer = zipimport.zipimporter(os.path.join(zip_path, '_pkg')) assert zip_path in zipimport._zip_directory_cache file_set = set(zipimport._zip_directory_cache[zip_path].iterkeys()) - compare_set = set(path.replace(os.path.sep, '/') + '.py' - for path in self.created_paths) + compare_set = set(path + '.py' for path in self.created_paths) assert file_set == compare_set finally: self.cleanup_zipfile(self.created_paths) diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py --- a/pypy/module/zipimport/test/test_zipimport.py +++ b/pypy/module/zipimport/test/test_zipimport.py @@ -157,7 +157,6 @@ import sys, os self.writefile("uuu.py", "def f(x): return x") mod = __import__('uuu', globals(), locals(), []) - print mod assert mod.f(3) == 3 expected = { '__doc__' : None, @@ -334,7 +333,9 @@ self.writefile("directory/package/__init__.py", "") importer = zipimport.zipimporter(self.zipfile + "/directory") l = [i for i in zipimport._zip_directory_cache] - assert len(l) + assert len(l) == 1 + k = zipimport._zip_directory_cache[l[0]].keys() + assert k[0] == os.path.sep.join(['directory','package','__init__.py']) def test_path_hooks(self): import sys diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -3,13 +3,12 @@ """ import operator -from rpython.rlib.buffer import Buffer, StringBuffer, SubBuffer +from rpython.rlib.buffer import Buffer, SubBuffer from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef from rpython.rlib.objectmodel import compute_hash -from rpython.rlib.rstring import StringBuilder class W_Buffer(W_Root): diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -6,7 +6,7 @@ from rpython.rlib.buffer import Buffer, SubBuffer from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError -from pypy.interpreter.gateway import interp2app, unwrap_spec +from pypy.interpreter.gateway import interp2app from pypy.interpreter.typedef import TypeDef, GetSetProperty diff --git a/pypy/tool/release/force-builds.py b/pypy/tool/release/force-builds.py --- a/pypy/tool/release/force-builds.py +++ b/pypy/tool/release/force-builds.py @@ -9,7 +9,7 @@ modified by PyPy team """ -import os, sys, pwd, urllib +import os, sys, urllib from twisted.internet import reactor, defer from twisted.python import log @@ -34,6 +34,13 @@ 'build-pypy-c-jit-linux-armel', ] +def get_user(): + if sys.platform == 'win32': + return os.environ['USERNAME'] + else: + import pwd + return pwd.getpwuid(os.getuid())[0] + def main(): #XXX: handle release tags #XXX: handle validity checks @@ -49,7 +56,7 @@ print 'Forcing', builder, '...' url = "http://buildbot.pypy.org/builders/" + builder + "/force" args = [ - ('username', pwd.getpwuid(os.getuid())[0]), + ('username', get_user()), ('revision', ''), ('submit', 'Force Build'), ('branch', branch), diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py --- a/rpython/flowspace/test/test_objspace.py +++ b/rpython/flowspace/test/test_objspace.py @@ -1,5 +1,5 @@ from __future__ import with_statement -import new +import types import py from contextlib import contextmanager @@ -943,7 +943,7 @@ def monkey_patch_code(self, code, stacksize, flags, codestring, names, varnames): c = code - return new.code(c.co_argcount, c.co_nlocals, stacksize, flags, + return types.CodeType(c.co_argcount, c.co_nlocals, stacksize, flags, codestring, c.co_consts, names, varnames, c.co_filename, c.co_name, c.co_firstlineno, c.co_lnotab) @@ -964,7 +964,7 @@ # this code is generated by pypy-c when compiling above f pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\xc9\x01\x00\xca\x00\x00S' new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',)) - f2 = new.function(new_c, locals(), 'f') + f2 = types.FunctionType(new_c, locals(), 'f') graph = self.codetest(f2) all_ops = self.all_operations(graph) @@ -984,7 +984,7 @@ pypy_code = 'd\x01\x00\xcb\x00\x00D]\x0c\x00}\x00\x00|\x00\x00^\x02\x00q\x07\x00S' new_c = self.monkey_patch_code(f.func_code, 3, 67, pypy_code, (), ('i',)) - f2 = new.function(new_c, locals(), 'f') + f2 = types.FunctionType(new_c, locals(), 'f') graph = self.codetest(f2) all_ops = self.all_operations(graph) diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -5884,6 +5884,25 @@ """ self.optimize_loop(ops, expected) + def test_bug_unroll_with_immutables(self): + ops = """ + [p0] + i2 = getfield_gc_pure(p0, descr=immut_intval) + p1 = new_with_vtable(ConstClass(intobj_immut_vtable)) + setfield_gc(p1, 1242, descr=immut_intval) + jump(p1) + """ + preamble = """ + [p0] + i2 = getfield_gc_pure(p0, descr=immut_intval) + jump() + """ + expected = """ + [] + jump() + """ + self.optimize_loop(ops, expected, preamble) + def test_immutable_constantfold_recursive(self): ops = """ [] diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py b/rpython/jit/metainterp/optimizeopt/unroll.py --- a/rpython/jit/metainterp/optimizeopt/unroll.py +++ b/rpython/jit/metainterp/optimizeopt/unroll.py @@ -180,10 +180,11 @@ self.optimizer.clear_newoperations() for i in range(len(original_jump_args)): + srcbox = jump_args[i] if values[i].is_virtual(): - values[i].force_box(self.optimizer) - if original_jump_args[i] is not jump_args[i]: - op = ResOperation(rop.SAME_AS, [jump_args[i]], original_jump_args[i]) + srcbox = values[i].force_box(self.optimizer) + if original_jump_args[i] is not srcbox: + op = ResOperation(rop.SAME_AS, [srcbox], original_jump_args[i]) self.optimizer.emit_operation(op) inputarg_setup_ops = self.optimizer.get_newoperations() diff --git a/rpython/rlib/parsing/lexer.py b/rpython/rlib/parsing/lexer.py --- a/rpython/rlib/parsing/lexer.py +++ b/rpython/rlib/parsing/lexer.py @@ -107,7 +107,7 @@ self.matcher = matcher self.lineno = 0 self.columnno = 0 - + def find_next_token(self): while 1: self.state = 0 @@ -126,8 +126,8 @@ i = ~i stop = self.last_matched_index + 1 assert stop >= 0 - if start == stop: - source_pos = SourcePos(i - 1, self.lineno, self.columnno) + if start == stop: + source_pos = self.token_position_class(i - 1, self.lineno, self.columnno) raise deterministic.LexerError(self.text, self.state, source_pos) source = self.text[start:stop] @@ -147,7 +147,7 @@ else: raise StopIteration return result - source_pos = SourcePos(i - 1, self.lineno, self.columnno) + source_pos = self.token_position_class(i - 1, self.lineno, self.columnno) raise deterministic.LexerError(self.text, self.state, source_pos) def adjust_position(self, token): @@ -158,7 +158,7 @@ self.columnno += len(token) else: self.columnno = token.rfind("\n") - + # def inner_loop(self, i): # while i < len(self.text): # char = self.text[i] @@ -186,10 +186,15 @@ class LexingDFARunner(AbstractLexingDFARunner): def __init__(self, matcher, automaton, text, ignore, eof=False, token_class=None): - if token_class is None: + + if not token_class: self.token_class = Token + self.token_position_class = SourcePos + else: self.token_class = token_class + self.token_position_class = token_class.source_position_class + AbstractLexingDFARunner.__init__(self, matcher, automaton, text, eof) self.ignore = ignore @@ -198,8 +203,10 @@ def make_token(self, index, state, text, eof=False): assert (eof and state == -1) or 0 <= state < len(self.automaton.names) - source_pos = SourcePos(index, self.lineno, self.columnno) + + source_pos = self.token_position_class(index, self.lineno, self.columnno) if eof: return self.token_class("EOF", "EOF", source_pos) + return self.token_class(self.automaton.names[self.last_matched_state], text, source_pos) diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py --- a/rpython/rlib/rsocket.py +++ b/rpython/rlib/rsocket.py @@ -1146,9 +1146,9 @@ address_to_fill=None): # port_or_service is a string, not an int (but try str(port_number)). assert port_or_service is None or isinstance(port_or_service, str) - if _c._MACOSX: - if port_or_service is None or port_or_service == '0': - port_or_service = '00' + if _c._MACOSX and flags & AI_NUMERICSERV and \ + (port_or_service is None or port_or_service == '0'): + port_or_service = '00' hints = lltype.malloc(_c.addrinfo, flavor='raw', zero=True) rffi.setintfield(hints, 'c_ai_family', family) rffi.setintfield(hints, 'c_ai_socktype', socktype) diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py --- a/rpython/rlib/streamio.py +++ b/rpython/rlib/streamio.py @@ -40,7 +40,7 @@ from rpython.rlib import rposix from rpython.rlib.rstring import StringBuilder -from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC +from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND O_BINARY = getattr(os, "O_BINARY", 0) # (basemode, plus) @@ -48,8 +48,8 @@ ('r', True): O_RDWR, ('w', False): O_WRONLY | O_CREAT | O_TRUNC, ('w', True): O_RDWR | O_CREAT | O_TRUNC, - ('a', False): O_WRONLY | O_CREAT, - ('a', True): O_RDWR | O_CREAT, + ('a', False): O_WRONLY | O_CREAT | O_APPEND, + ('a', True): O_RDWR | O_CREAT | O_APPEND, } class MyNotImplementedError(Exception): diff --git a/rpython/rlib/test/test_streamio.py b/rpython/rlib/test/test_streamio.py --- a/rpython/rlib/test/test_streamio.py +++ b/rpython/rlib/test/test_streamio.py @@ -1104,6 +1104,21 @@ finally: signal(SIGALRM, SIG_DFL) + def test_append_mode(self): + tfn = str(udir.join('streamio-append-mode')) + fo = streamio.open_file_as_stream # shorthand + x = fo(tfn, 'w') + x.write('abc123') + x.close() + + x = fo(tfn, 'a') + x.seek(0, 0) + x.write('456') + x.close() + x = fo(tfn, 'r') + assert x.read() == 'abc123456' + x.close() + # Speed test diff --git a/rpython/tool/identity_dict.py b/rpython/tool/identity_dict.py --- a/rpython/tool/identity_dict.py +++ b/rpython/tool/identity_dict.py @@ -3,15 +3,15 @@ except ImportError: idict = None -from UserDict import DictMixin +from collections import MutableMapping -class IdentityDictPurePython(object, DictMixin): +class IdentityDictPurePython(MutableMapping): __slots__ = "_dict _keys".split() def __init__(self): self._dict = {} - self._keys = {} # id(obj) -> obj + self._keys = {} # id(obj) -> obj def __getitem__(self, arg): return self._dict[id(arg)] @@ -24,8 +24,11 @@ del self._keys[id(arg)] del self._dict[id(arg)] - def keys(self): - return self._keys.values() + def __iter__(self): + return self._keys.itervalues() + + def __len__(self): + return len(self._keys) def __contains__(self, arg): return id(arg) in self._dict @@ -37,8 +40,7 @@ return d -class IdentityDictPyPy(object, DictMixin): - __slots__ = ["_dict"] +class IdentityDictPyPy(MutableMapping): def __init__(self): self._dict = idict() @@ -52,8 +54,11 @@ def __delitem__(self, arg): del self._dict[arg] - def keys(self): - return self._dict.keys() + def __iter__(self): + return iter(self._dict.keys()) + + def __len__(self): + return len(self._dict) def __contains__(self, arg): return arg in self._dict @@ -64,8 +69,10 @@ assert len(d) == len(self) return d + def __nonzero__(self): + return bool(self._dict) + if idict is None: identity_dict = IdentityDictPurePython else: identity_dict = IdentityDictPyPy - diff --git a/rpython/tool/sourcetools.py b/rpython/tool/sourcetools.py --- a/rpython/tool/sourcetools.py +++ b/rpython/tool/sourcetools.py @@ -6,7 +6,7 @@ # XXX We should try to generalize and single out one approach to dynamic # XXX code compilation. -import sys, os, inspect, new +import sys, os, inspect, types import py def render_docstr(func, indent_str='', closing_str=''): @@ -127,7 +127,7 @@ for name in names: if name not in kwargs: kwargs[name] = getattr(fromcode, name) - return new.code( + return types.CodeType( kwargs['co_argcount'], kwargs['co_nlocals'], kwargs['co_stacksize'], @@ -218,9 +218,8 @@ """Make a renamed copy of a function.""" if globals is None: globals = func.func_globals - f = new.function(func.func_code, globals, - newname, func.func_defaults, - func.func_closure) + f = types.FunctionType(func.func_code, globals, newname, + func.func_defaults, func.func_closure) if func.func_dict: f.func_dict = {} f.func_dict.update(func.func_dict) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit