[pypy-commit] pypy cpyext-test-A: Make test_version compatible with pytest.py -A.
Author: Devin JeanpierreBranch: cpyext-test-A Changeset: r84076:7e8bd9d01613 Date: 2016-04-30 22:30 -0700 http://bitbucket.org/pypy/pypy/changeset/7e8bd9d01613/ Log:Make test_version compatible with pytest.py -A. diff --git a/pypy/module/cpyext/test/test_version.py b/pypy/module/cpyext/test/test_version.py --- a/pypy/module/cpyext/test/test_version.py +++ b/pypy/module/cpyext/test/test_version.py @@ -1,4 +1,6 @@ -import py +import sys + +import py, pytest from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase @@ -22,8 +24,6 @@ PyModule_AddIntConstant(m, "py_major_version", PY_MAJOR_VERSION); PyModule_AddIntConstant(m, "py_minor_version", PY_MINOR_VERSION); PyModule_AddIntConstant(m, "py_micro_version", PY_MICRO_VERSION); -PyModule_AddStringConstant(m, "pypy_version", PYPY_VERSION); -PyModule_AddIntConstant(m, "pypy_version_num", PYPY_VERSION_NUM); } """ module = self.import_module(name='foo', init=init) @@ -31,6 +31,18 @@ assert module.py_major_version == sys.version_info.major assert module.py_minor_version == sys.version_info.minor assert module.py_micro_version == sys.version_info.micro + +@pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, reason='pypy only test') +def test_pypy_versions(self): +import sys +init = """ +if (Py_IsInitialized()) { +PyObject *m = Py_InitModule("foo", NULL); +PyModule_AddStringConstant(m, "pypy_version", PYPY_VERSION); +PyModule_AddIntConstant(m, "pypy_version_num", PYPY_VERSION_NUM); +} +""" +module = self.import_module(name='foo', init=init) v = sys.pypy_version_info s = '%d.%d.%d' % (v[0], v[1], v[2]) if v.releaselevel != 'final': ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: start release cycle
Author: Matti PicusBranch: Changeset: r84074:0b2e75889888 Date: 2016-05-01 07:29 +0300 http://bitbucket.org/pypy/pypy/changeset/0b2e75889888/ Log:start release cycle diff --git a/pypy/doc/release-5.1.1.rst b/pypy/doc/release-5.1.1.rst new file mode 100644 --- /dev/null +++ b/pypy/doc/release-5.1.1.rst @@ -0,0 +1,45 @@ +== +PyPy 5.1.1 +== + +We have released a bugfix for PyPy 5.1, due to a regression_ in +installing third-party packages dependant on numpy (using our numpy fork +available at https://bitbucket.org/pypy/numpy ). + +Thanks to those who reported the issue. We also fixed a regression in +translating PyPy which increased the memory required to translate. Improvement +will be noticed by downstream packagers and those who translate rather than +download pre-built binaries. + +.. _regression: https://bitbucket.org/pypy/pypy/issues/2282 + +What is PyPy? += + +PyPy is a very compliant Python interpreter, almost a drop-in replacement for +CPython 2.7. It's fast (`PyPy and CPython 2.7.x`_ performance comparison) +due to its integrated tracing JIT compiler. + +We also welcome developers of other +`dynamic languages`_ to see what RPython can do for them. + +This release supports: + + * **x86** machines on most common operating systems +(Linux 32/64, Mac OS X 64, Windows 32, OpenBSD, FreeBSD), + + * newer **ARM** hardware (ARMv6 or ARMv7, with VFPv3) running Linux, + + * big- and little-endian variants of **PPC64** running Linux, + + * **s390x** running Linux + +.. _`PyPy and CPython 2.7.x`: http://speed.pypy.org +.. _`dynamic languages`: http://pypyjs.org + +Please update, and continue to help us make PyPy better. + +Cheers + +The PyPy Team + diff --git a/pypy/tool/release/repackage.sh b/pypy/tool/release/repackage.sh --- a/pypy/tool/release/repackage.sh +++ b/pypy/tool/release/repackage.sh @@ -1,7 +1,7 @@ # Edit these appropriately before running this script maj=5 min=1 -rev=0 +rev=1 branchname=release-$maj.x # ==OR== release-$maj.$min.x tagname=release-$maj.$min # ==OR== release-$maj.$min.$rev ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Added tag release-5.1.1 for changeset b0a649e90b66
Author: Matti PicusBranch: Changeset: r84075:ce68e84f6208 Date: 2016-05-01 07:32 +0300 http://bitbucket.org/pypy/pypy/changeset/ce68e84f6208/ Log:Added tag release-5.1.1 for changeset b0a649e90b66 diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -21,3 +21,4 @@ 246c9cf22037b11dc0e8c29ce3f291d3b8c5935a release-5.0 bbd45126bc691f669c4ebdfbd74456cd274c6b92 release-5.0.1 3260adbeba4a8b6659d1cc0d0b41f266769b74da release-5.1 +b0a649e90b6642251fb4a765fe5b27a97b1319a9 release-5.1.1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: shorten
Author: Matti PicusBranch: extradoc Changeset: r5641:8a43ad85184c Date: 2016-05-01 05:50 +0300 http://bitbucket.org/pypy/extradoc/changeset/8a43ad85184c/ Log:shorten diff --git a/talk/pycon-il-2016/talk.pdf b/talk/pycon-il-2016/talk.pdf index 51c1443ef77403e7affefca9ed3b4d748cf0c7c2..c46cf494a4303e80ce9d2fe2f79795fd8e25118e GIT binary patch [cut] diff --git a/talk/pycon-il-2016/talk.rst b/talk/pycon-il-2016/talk.rst --- a/talk/pycon-il-2016/talk.rst +++ b/talk/pycon-il-2016/talk.rst @@ -107,8 +107,8 @@ - Opportunity??? -PyPy and C (1/3) - +PyPy and Third-party libraries +-- * PyPy and CFFI (Armin Rigo, Maciej Fijakowski) @@ -116,17 +116,14 @@ * Use CFFI to call python from C - - This means you can create your own C API in pure Python ! - -PyPy and C (2/3) - - * CFFI enables embedded Python (and PyPy) in a C application (uWSGI) * Very fast on PyPy, fast enough on CPython -PyPy and C (3/3) - +PyPy and Third-party libraries +-- + +* Not everyone will rewrite in CFFI * What about C-API (glad you asked) @@ -145,8 +142,10 @@ * Hint - good things are coming -NumPyPy +PyPy and Third-party libriaries: NumPyPy + + +* Numpy (and its ecosystem) is the last frontier for PyPy * https://bitbucket.org/pypy/numpy + pypy @@ -179,81 +178,6 @@ * But what about SciPy? -PyMetabiosis - - -* https://github.com/rguillebert/pymetabiosis - -* Proof of concept (Romain Guillebert) - -* Allows you to use any CPython module on PyPy (scipy for example) - -* Embeds CPython into PyPy with CFFI - -* Numpy arrays can be shared between PyPy and CPython - -PyMetabiosis - - -|scriptsize| - -.. sourcecode:: python - -from pymetabiosis import import_module - -cpython_virtualenv_path = -"/tmp/venv/bin/activate_this.py" - -builtin = import_module("__builtin__") - -# Activate a virtualenv for the cpython interpreter -builtin.execfile(cpython_virtualenv_path, -{"__file__" : cpython_virtualenv_path} -) - -pylab = import_module("matplotlib.pylab") - -pylab.plot([1, 2, 3, 4]) -pylab.show() - -|end_scriptsize| - -JitPy -- - -* http://jitpy.readthedocs.io - -* Proof of concept (Maciej Fijakowski) - -* Embeds PyPy into CPython - -* Provides a decorator that allows you to run specific functions on PyPy - -* Is used the same way as numba, but different performance characteristics - - -JitPy -- - -|scriptsize| - -.. sourcecode:: python - -import numpy as np -from jitpy import setup -setup('') -from jitpy.wrapper import jittify - -@jittify(['array', float], float) -def f(a, s): -r = 0 -for i in xrange(a.shape[0]): -r += a[i] * s -return s -func(np.arange(1), 1.2) - -|end_scriptsize| - Future - wouldn't it be great if @@ -265,10 +189,14 @@ The Future is Now! -- +* Merged major upgrade of the C-API + * (Applause) * Native numpy (tweaked) passes 90% of tests +* Download a nightly and try http://github.com/pypy/numpy + * How to leverage the JIT and NumPyPy? Why this makes sense @@ -294,8 +222,6 @@ Questions ? Examples: -* What about this other interpreter I heard of? - * How can I get involved? * What about commercial involvement? @@ -303,3 +229,6 @@ * How can I get support? * What about Python 3.5? + +* What about this other interpreter I heard of? + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy_broadcast_nd: merge default into branch
Author: Matti PicusBranch: numpy_broadcast_nd Changeset: r84068:4d1e324b4a8e Date: 2016-04-30 22:40 +0300 http://bitbucket.org/pypy/pypy/changeset/4d1e324b4a8e/ Log:merge default into branch diff too long, truncating to 2000 out of 12991 lines diff --git a/TODO b/TODO new file mode 100644 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +* reduce size of generated c code from slot definitions in slotdefs. +* remove broken DEBUG_REFCOUNT from pyobject.py diff --git a/lib-python/2.7/distutils/cmd.py b/lib-python/2.7/distutils/cmd.py --- a/lib-python/2.7/distutils/cmd.py +++ b/lib-python/2.7/distutils/cmd.py @@ -298,8 +298,16 @@ src_cmd_obj.ensure_finalized() for (src_option, dst_option) in option_pairs: if getattr(self, dst_option) is None: -setattr(self, dst_option, -getattr(src_cmd_obj, src_option)) +try: +setattr(self, dst_option, +getattr(src_cmd_obj, src_option)) +except AttributeError: +# This was added after problems with setuptools 18.4. +# It seems that setuptools 20.9 fixes the problem. +# But e.g. on Ubuntu 14.04 with /usr/bin/virtualenv +# if I say "virtualenv -p pypy venv-pypy" then it +# just installs setuptools 18.4 from some cache... +pass def get_finalized_command(self, command, create=1): diff --git a/lib-python/stdlib-upgrade.txt b/lib-python/stdlib-upgrade.txt --- a/lib-python/stdlib-upgrade.txt +++ b/lib-python/stdlib-upgrade.txt @@ -5,15 +5,23 @@ overly detailed -1. check out the branch vendor/stdlib +0. make sure your working dir is clean +1. check out the branch vendor/stdlib (for 2.7) or vendor/stdlib-3-* (for py3k) + or create branch vendor/stdlib-3-* 2. upgrade the files there + 2a. remove lib-python/2.7/ or lib-python/3/ + 2b. copy the files from the cpython repo + 2c. hg add lib-python/2.7/ or lib-python/3/ + 2d. hg remove --after + 2e. show copied files in cpython repo by running `hg diff --git -r v -r v Lib | grep '^copy \(from\|to\)'` + 2f. fix copies / renames manually by running `hg copy --after ` for each copied file 3. update stdlib-version.txt with the output of hg -id from the cpython repo 4. commit -5. update to default/py3k +5. update to default / py3k 6. create a integration branch for the new stdlib (just hg branch stdlib-$version) -7. merge vendor/stdlib +7. merge vendor/stdlib or vendor/stdlib-3-* 8. commit 10. fix issues 11. commit --close-branch -12. merge to default +12. merge to default / py3k diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -204,15 +204,6 @@ BoolOption("withstrbuf", "use strings optimized for addition (ver 2)", default=False), -BoolOption("withprebuiltchar", - "use prebuilt single-character string objects", - default=False), - -BoolOption("sharesmallstr", - "always reuse the prebuilt string objects " - "(the empty string and potentially single-char strings)", - default=False), - BoolOption("withspecialisedtuple", "use specialised tuples", default=False), @@ -222,39 +213,14 @@ default=False, requires=[("objspace.honor__builtins__", False)]), -BoolOption("withmapdict", - "make instances really small but slow without the JIT", - default=False, - requires=[("objspace.std.getattributeshortcut", True), - ("objspace.std.withtypeversion", True), - ]), - -BoolOption("withrangelist", - "enable special range list implementation that does not " - "actually create the full list until the resulting " - "list is mutated", - default=False), BoolOption("withliststrategies", "enable optimized ways to store lists of primitives ", default=True), -BoolOption("withtypeversion", - "version type objects when changing them", - cmdline=None, - default=False, - # weakrefs needed, because of get_subclasses() - requires=[("translation.rweakref", True)]), - -BoolOption("withmethodcache", - "try to cache method lookups", - default=False, - requires=[("objspace.std.withtypeversion", True), - ("translation.rweakref", True)]), BoolOption("withmethodcachecounter", "try to cache
[pypy-commit] pypy py3k: minor cleanup
Author: Philip JenveyBranch: py3k Changeset: r84073:ee02e1bd2dd3 Date: 2016-04-30 13:50 -0700 http://bitbucket.org/pypy/pypy/changeset/ee02e1bd2dd3/ Log:minor cleanup diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -167,11 +167,7 @@ def path_or_fd(allow_fd=True): return _PathOrFd if allow_fd else _JustPath - -if hasattr(rposix, 'AT_FDCWD'): -DEFAULT_DIR_FD = rposix.AT_FDCWD -else: -DEFAULT_DIR_FD = -100 +DEFAULT_DIR_FD = getattr(rposix, 'AT_FDCWD', -100) DIR_FD_AVAILABLE = False @specialize.arg(2) @@ -204,10 +200,8 @@ dir_fd = unwrap_fd(space, w_value) if dir_fd == DEFAULT_DIR_FD: return dir_fd -else: -raise oefmt( -space.w_NotImplementedError, -"dir_fd unavailable on this platform") +raise oefmt(space.w_NotImplementedError, +"dir_fd unavailable on this platform") def DirFD(available=False): return _DirFD if available else _DirFD_Unavailable @@ -559,7 +553,8 @@ raise wrap_oserror(space, e) @unwrap_spec(mode=c_int, -dir_fd=DirFD(rposix.HAVE_FACCESSAT), effective_ids=kwonly(bool), follow_symlinks=kwonly(bool)) +dir_fd=DirFD(rposix.HAVE_FACCESSAT), effective_ids=kwonly(bool), +follow_symlinks=kwonly(bool)) def access(space, w_path, mode, dir_fd=DEFAULT_DIR_FD, effective_ids=True, follow_symlinks=True): """\ @@ -903,7 +898,8 @@ raise wrap_oserror(space, e) return space.newtuple([space.wrap(fd1), space.wrap(fd2)]) -@unwrap_spec(mode=c_int, dir_fd=DirFD(rposix.HAVE_FCHMODAT), follow_symlinks=kwonly(bool)) +@unwrap_spec(mode=c_int, dir_fd=DirFD(rposix.HAVE_FCHMODAT), + follow_symlinks=kwonly(bool)) def chmod(space, w_path, mode, dir_fd=DEFAULT_DIR_FD, follow_symlinks=True): """chmod(path, mode, *, dir_fd=None, follow_symlinks=True) @@ -924,12 +920,11 @@ if not rposix.HAVE_FCHMODAT: if not follow_symlinks: raise argument_unavailable(space, "chmod", "follow_symlinks") -else: -try: -dispatch_filename(rposix.chmod)(space, w_path, mode) -return -except OSError as e: -raise wrap_oserror2(space, e, w_path) +try: +dispatch_filename(rposix.chmod)(space, w_path, mode) +return +except OSError as e: +raise wrap_oserror2(space, e, w_path) try: path = space.fsencode_w(w_path) @@ -947,8 +942,7 @@ # fchmodat() doesn't actually implement follow_symlinks=False # so raise NotImplementedError in this case raise argument_unavailable(space, "chmod", "follow_symlinks") -else: -raise wrap_oserror2(space, e, w_path) +raise wrap_oserror2(space, e, w_path) def _chmod_path(path, mode, dir_fd, follow_symlinks): if dir_fd != DEFAULT_DIR_FD or not follow_symlinks: @@ -1359,7 +1353,8 @@ path=path_or_fd(allow_fd=rposix.HAVE_FUTIMENS), w_times=WrappedDefault(None), w_ns=kwonly(WrappedDefault(None)), dir_fd=DirFD(rposix.HAVE_UTIMENSAT), follow_symlinks=kwonly(bool)) -def utime(space, path, w_times, w_ns, dir_fd=DEFAULT_DIR_FD, follow_symlinks=True): +def utime(space, path, w_times, w_ns, dir_fd=DEFAULT_DIR_FD, + follow_symlinks=True): """utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True) Set the access and modified time of path. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: minor cleanup
Author: Philip JenveyBranch: py3k Changeset: r84072:f424e2be88dd Date: 2016-04-30 13:49 -0700 http://bitbucket.org/pypy/pypy/changeset/f424e2be88dd/ Log:minor cleanup diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py --- a/pypy/module/itertools/interp_itertools.py +++ b/pypy/module/itertools/interp_itertools.py @@ -836,39 +836,32 @@ class W_TeeChainedListNode(W_Root): def __init__(self, space): -self.space = space self.w_next = None self.w_obj = None -def reduce_w(self): +def reduce_w(self, space): list_w = [] node = self -while node is not None: -if node.w_obj is not None: -list_w.append(node.w_obj) -node = node.w_next -else: -break -space = self.space -if list_w: -return self.space.newtuple([space.type(self), -space.newtuple([]), -space.newtuple([space.newlist(list_w)]) - ]) -else: -return self.space.newtuple([space.type(self), -space.newtuple([])]) +while node is not None and node.w_obj is not None: +list_w.append(node.w_obj) +node = node.w_next +if not list_w: +return space.newtuple([space.type(self), space.newtuple([])]) +return space.newtuple( +[space.type(self), + space.newtuple([]), + space.newtuple([space.newlist(list_w)]) +]) def descr_setstate(self, space, w_state): state = space.unpackiterable(w_state) if len(state) != 1: -raise OperationError(space.w_ValueError, - space.wrap("invalid arguments")) +raise oefmt(space.w_ValueError, "invalid arguments") obj_list_w = space.unpackiterable(state[0]) node = self for w_obj in obj_list_w: node.w_obj = w_obj -node.w_next = W_TeeChainedListNode(self.space) +node.w_next = W_TeeChainedListNode(space) node = node.w_next def W_TeeChainedListNode___new__(space, w_subtype): @@ -883,7 +876,6 @@ __reduce__ = interp2app(W_TeeChainedListNode.reduce_w), __setstate__ = interp2app(W_TeeChainedListNode.descr_setstate) ) - W_TeeChainedListNode.typedef.acceptable_as_base_class = False class W_TeeIterable(W_Root): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-werror: merge default into branch
Author: Matti PicusBranch: cpyext-werror Changeset: r84071:1846e020572e Date: 2016-04-30 23:25 +0300 http://bitbucket.org/pypy/pypy/changeset/1846e020572e/ Log:merge default into branch diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -24,7 +24,11 @@ remove-objspace-options. .. branch: cpyext-for-merge -Update cpyext C-API support: + +Update cpyext C-API support After this branch, we are almost able to support +upstream numpy via cpyext, so we created (yet another) fork of numpy at +github.com/pypy/numpy with the needed changes. Among the significant changes +to cpyext: - allow c-snippet tests to be run with -A so we can verify we are compatible - fix many edge cases exposed by fixing tests to run with -A - issequence() logic matches cpython @@ -40,6 +44,8 @@ - rewrite slot assignment for typeobjects - improve tracking of PyObject to rpython object mapping - support tp_as_{number, sequence, mapping, buffer} slots -After this branch, we are almost able to support upstream numpy via cpyext, so -we created (yet another) fork of numpy at github.com/pypy/numpy with the needed -changes + +.. branch: share-mapdict-methods-2 + +Reduce generated code for subclasses by using the same function objects in all +generated subclasses. diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py --- a/pypy/module/cpyext/ndarrayobject.py +++ b/pypy/module/cpyext/ndarrayobject.py @@ -253,12 +253,8 @@ check_return, w_signature): funcs_w = [None] * ntypes dtypes_w = [None] * ntypes * (nin + nout) -# XXX For some reason funcs[i] segfaults, but this does not: -# cast(gufunctype, cast(CArrayPtr(CArrayPtr(gufunctype)), funcs)[i]) -# Something is very wrong here. -funcs_wrong_type = rffi.cast(rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)), funcs) for i in range(ntypes): -funcs_w[i] = ufuncs.W_GenericUFuncCaller(rffi.cast(gufunctype, funcs_wrong_type[i]), data) +funcs_w[i] = ufuncs.W_GenericUFuncCaller(funcs[i], data) for i in range(ntypes*(nin+nout)): dtypes_w[i] = get_dtype_cache(space).dtypes_by_num[ord(types[i])] w_funcs = space.newlist(funcs_w) diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py --- a/pypy/module/cpyext/test/test_ndarrayobject.py +++ b/pypy/module/cpyext/test/test_ndarrayobject.py @@ -366,7 +366,7 @@ def test_ufunc(self): if self.runappdirect: from numpy import arange -py.test.xfail('why does this segfault on cpython?') +py.test.xfail('segfaults on cpython: PyUFunc_API == NULL?') else: from _numpypy.multiarray import arange mod = self.import_extension('foo', [ diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py --- a/rpython/rtyper/lltypesystem/ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/ll2ctypes.py @@ -231,17 +231,7 @@ assert max_n >= 0 ITEM = A.OF ctypes_item = get_ctypes_type(ITEM, delayed_builders) -# Python 2.5 ctypes can raise OverflowError on 64-bit builds -for n in [maxint, 2**31]: -MAX_SIZE = n/64 -try: -PtrType = ctypes.POINTER(MAX_SIZE * ctypes_item) -except (OverflowError, AttributeError), e: -pass #^^^ bah, blame ctypes -else: -break -else: -raise e +ctypes_item_ptr = ctypes.POINTER(ctypes_item) class CArray(ctypes.Structure): if is_emulated_long: @@ -265,35 +255,9 @@ bigarray.length = n return bigarray -_ptrtype = None - -@classmethod -def _get_ptrtype(cls): -if cls._ptrtype: -return cls._ptrtype -# ctypes can raise OverflowError on 64-bit builds -# on windows it raises AttributeError even for 2**31 (_length_ missing) -if _MS_WINDOWS: -other_limit = 2**31-1 -else: -other_limit = 2**31 -for n in [maxint, other_limit]: -cls.MAX_SIZE = n / ctypes.sizeof(ctypes_item) -try: -cls._ptrtype = ctypes.POINTER(cls.MAX_SIZE * ctypes_item) -except (OverflowError, AttributeError), e: -pass -else: -break -else: -raise e -return cls._ptrtype - def _indexable(self, index): -PtrType = self._get_ptrtype() -assert index + 1 < self.MAX_SIZE -p = ctypes.cast(ctypes.pointer(self.items), PtrType) -return p.contents +p = ctypes.cast(self.items, ctypes_item_ptr) +return p def _getitem(self, index, boundscheck=True): if
[pypy-commit] pypy numpy_broadcast_nd: W_Broadcast (micronumpy) is rewritten using W_FlatIterator for implementation of iters attribute. W_FlatIterator gets optional arguments in constructor.
Author: Sergey MatyuninBranch: numpy_broadcast_nd Changeset: r84065:c0d40603d40b Date: 2016-04-24 13:36 +0200 http://bitbucket.org/pypy/pypy/changeset/c0d40603d40b/ Log:W_Broadcast (micronumpy) is rewritten using W_FlatIterator for implementation of iters attribute. W_FlatIterator gets optional arguments in constructor. diff --git a/pypy/module/micronumpy/broadcast.py b/pypy/module/micronumpy/broadcast.py --- a/pypy/module/micronumpy/broadcast.py +++ b/pypy/module/micronumpy/broadcast.py @@ -1,12 +1,12 @@ import pypy.module.micronumpy.constants as NPY -from nditer import ConcreteIter, parse_op_flag, parse_op_arg from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import interp2app from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.module.micronumpy import support -from pypy.module.micronumpy.base import W_NDimArray, convert_to_array, W_NumpyObject +from pypy.module.micronumpy.base import convert_to_array, W_NumpyObject +from pypy.module.micronumpy.flatiter import W_FlatIterator from rpython.rlib import jit -from strides import calculate_broadcast_strides, shape_agreement_multiple +from strides import shape_agreement_multiple def descr_new_broadcast(space, w_subtype, __args__): return W_Broadcast(space, __args__.arguments_w) @@ -26,45 +26,21 @@ self.seq = [convert_to_array(space, w_elem) for w_elem in args] -self.op_flags = parse_op_arg(space, 'op_flags', space.w_None, - len(self.seq), parse_op_flag) - self.shape = shape_agreement_multiple(space, self.seq, shape=None) self.order = NPY.CORDER -self.iters = [] +self.list_iter_state = [] self.index = 0 try: self.size = support.product_check(self.shape) except OverflowError as e: raise oefmt(space.w_ValueError, "broadcast dimensions too large.") -for i in range(len(self.seq)): -it = self.get_iter(space, i) -it.contiguous = False -self.iters.append((it, it.reset())) + +self.list_iter_state = [W_FlatIterator(arr, self.shape, arr.get_order() != self.order) +for arr in self.seq] self.done = False -pass - -def get_iter(self, space, i): -arr = self.seq[i] -imp = arr.implementation -if arr.is_scalar(): -return ConcreteIter(imp, 1, [], [], [], self.op_flags[i], self) -shape = self.shape - -backward = imp.order != self.order - -r = calculate_broadcast_strides(imp.strides, imp.backstrides, imp.shape, -shape, backward) - -iter_shape = shape -if len(shape) != len(r[0]): -# shape can be shorter when using an external loop, just return a view -iter_shape = imp.shape -return ConcreteIter(imp, imp.get_size(), iter_shape, r[0], r[1], -self.op_flags[i], self) def descr_iter(self, space): return space.wrap(self) @@ -79,28 +55,26 @@ return space.wrap(self.index) def descr_get_numiter(self, space): -return space.wrap(len(self.iters)) +return space.wrap(len(self.list_iter_state)) def descr_get_number_of_dimensions(self, space): return space.wrap(len(self.shape)) +def descr_get_iters(self, space): +return space.newtuple(self.list_iter_state) + @jit.unroll_safe def descr_next(self, space): if self.index >= self.size: self.done = True raise OperationError(space.w_StopIteration, space.w_None) self.index += 1 -res = [] -for i, (it, st) in enumerate(self.iters): -res.append(self._get_item(it, st)) -self.iters[i] = (it, it.next(st)) +res = [it.descr_next(space) for it in self.list_iter_state] + if len(res) < 2: return res[0] return space.newtuple(res) -def _get_item(self, it, st): -return W_NDimArray(it.getoperand(st)) - W_Broadcast.typedef = TypeDef("numpy.broadcast", __new__=interp2app(descr_new_broadcast), @@ -111,4 +85,5 @@ index=GetSetProperty(W_Broadcast.descr_get_index), numiter=GetSetProperty(W_Broadcast.descr_get_numiter), nd=GetSetProperty(W_Broadcast.descr_get_number_of_dimensions), + iters=GetSetProperty(W_Broadcast.descr_get_iters), ) diff --git a/pypy/module/micronumpy/flatiter.py b/pypy/module/micronumpy/flatiter.py --- a/pypy/module/micronumpy/flatiter.py +++ b/pypy/module/micronumpy/flatiter.py @@ -33,9 +33,9 @@ class W_FlatIterator(W_NDimArray): -def __init__(self, arr): +def __init__(self,
[pypy-commit] pypy numpy_broadcast_nd: fixed compilation error for W_Broadcast
Author: Sergey MatyuninBranch: numpy_broadcast_nd Changeset: r84067:23fae214f255 Date: 2016-04-24 14:28 +0200 http://bitbucket.org/pypy/pypy/changeset/23fae214f255/ Log:fixed compilation error for W_Broadcast diff --git a/pypy/module/micronumpy/broadcast.py b/pypy/module/micronumpy/broadcast.py --- a/pypy/module/micronumpy/broadcast.py +++ b/pypy/module/micronumpy/broadcast.py @@ -69,7 +69,7 @@ self.done = True raise OperationError(space.w_StopIteration, space.w_None) self.index += 1 -res = [it.descr_next(space) for it in self.list_iter_state] +res = [space.call_method(it, 'next') for it in self.list_iter_state] if len(res) < 2: return res[0] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy_broadcast_nd: add failing test - W_Broadcast.__init__
Author: Matti PicusBranch: numpy_broadcast_nd Changeset: r84069:e1729cba05e7 Date: 2016-04-30 22:42 +0300 http://bitbucket.org/pypy/pypy/changeset/e1729cba05e7/ Log:add failing test - W_Broadcast.__init__ diff --git a/pypy/module/micronumpy/test/test_broadcast.py b/pypy/module/micronumpy/test/test_broadcast.py --- a/pypy/module/micronumpy/test/test_broadcast.py +++ b/pypy/module/micronumpy/test/test_broadcast.py @@ -136,4 +136,19 @@ assert b.index == 0 assert b.next() == (1, 4) - +def test_broadcast_in_args(self): +# gh-5881 +import numpy as np +arrs = [np.empty((6, 7)), np.empty((5, 6, 1)), np.empty((7,)), +np.empty((5, 1, 7))] +mits = [np.broadcast(*arrs), +np.broadcast(np.broadcast(*arrs[:2]), np.broadcast(*arrs[2:])), +np.broadcast(arrs[0], np.broadcast(*arrs[1:-1]), arrs[-1])] +print [mit.shape for mit in mits] +for mit in mits: +assert mit.shape == (5, 6, 7) +assert mit.nd == 3 +assert mit.numiter == 4 +for a, ia in zip(arrs, mit.iters): +assert a is ia.base + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy_broadcast_nd: try to treat W_Broadcast as true W_NumpyObjects
Author: Matti PicusBranch: numpy_broadcast_nd Changeset: r84070:96c7090938b3 Date: 2016-04-30 23:12 +0300 http://bitbucket.org/pypy/pypy/changeset/96c7090938b3/ Log:try to treat W_Broadcast as true W_NumpyObjects diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py --- a/pypy/module/micronumpy/base.py +++ b/pypy/module/micronumpy/base.py @@ -169,6 +169,6 @@ def convert_to_array(space, w_obj): from pypy.module.micronumpy.ctors import array -if isinstance(w_obj, W_NDimArray): +if isinstance(w_obj, W_NumpyObject) and not w_obj.is_scalar(): return w_obj return array(space, w_obj) diff --git a/pypy/module/micronumpy/broadcast.py b/pypy/module/micronumpy/broadcast.py --- a/pypy/module/micronumpy/broadcast.py +++ b/pypy/module/micronumpy/broadcast.py @@ -42,6 +42,21 @@ self.done = False +def get_shape(self): +return self.shape + +def get_order(self): +return self.order + +def get_dtype(self): +return self.seq[0].get_dtype() #XXX Fixme + +def get_size(self): +return 0 #XXX Fixme + +def create_iter(self, shape=None, backward_broadcast=False): +return self, self.list_iter_state # XXX Fixme + def descr_iter(self, space): return space.wrap(self) diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py --- a/pypy/module/micronumpy/strides.py +++ b/pypy/module/micronumpy/strides.py @@ -1,7 +1,7 @@ from pypy.interpreter.error import OperationError, oefmt from rpython.rlib import jit from pypy.module.micronumpy import support, constants as NPY -from pypy.module.micronumpy.base import W_NDimArray +from pypy.module.micronumpy.base import W_NDimArray, W_NumpyObject # structures to describe slicing @@ -218,7 +218,7 @@ def shape_agreement(space, shape1, w_arr2, broadcast_down=True): if w_arr2 is None: return shape1 -assert isinstance(w_arr2, W_NDimArray) +assert isinstance(w_arr2, W_NumpyObject) shape2 = w_arr2.get_shape() ret = _shape_agreement(shape1, shape2) if len(ret) < max(len(shape1), len(shape2)): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy_broadcast_nd: In W_Broadcast (micronumpy) implemented nd attribute
Author: Sergey MatyuninBranch: numpy_broadcast_nd Changeset: r84064:2bcbec2ef549 Date: 2016-04-24 11:46 +0200 http://bitbucket.org/pypy/pypy/changeset/2bcbec2ef549/ Log:In W_Broadcast (micronumpy) implemented nd attribute diff --git a/pypy/module/micronumpy/broadcast.py b/pypy/module/micronumpy/broadcast.py --- a/pypy/module/micronumpy/broadcast.py +++ b/pypy/module/micronumpy/broadcast.py @@ -81,6 +81,9 @@ def descr_get_numiter(self, space): return space.wrap(len(self.iters)) +def descr_get_number_of_dimensions(self, space): +return space.wrap(len(self.shape)) + @jit.unroll_safe def descr_next(self, space): if self.index >= self.size: @@ -107,4 +110,5 @@ size=GetSetProperty(W_Broadcast.descr_get_size), index=GetSetProperty(W_Broadcast.descr_get_index), numiter=GetSetProperty(W_Broadcast.descr_get_numiter), + nd=GetSetProperty(W_Broadcast.descr_get_number_of_dimensions), ) diff --git a/pypy/module/micronumpy/test/test_broadcast.py b/pypy/module/micronumpy/test/test_broadcast.py --- a/pypy/module/micronumpy/test/test_broadcast.py +++ b/pypy/module/micronumpy/test/test_broadcast.py @@ -57,7 +57,6 @@ def test_broadcast_failures(self): import numpy as np -import sys x = np.array([1, 2, 3]) y = np.array([4, 5]) raises(ValueError, np.broadcast, x, y) @@ -95,3 +94,11 @@ else: mit = np.broadcast(*arrs) assert mit.numiter == j + +def test_broadcast_nd(self): +import numpy as np +arg1, arg2 = np.empty((6, 7)), np.empty((5, 6, 1)) +b = np.broadcast(arg1, arg2) + +assert hasattr(b, 'nd') +assert b.nd == 3 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy_broadcast_nd: Implemented reset for numpy broadcast object.
Author: Sergey MatyuninBranch: numpy_broadcast_nd Changeset: r84066:d52b849b3779 Date: 2016-04-24 13:54 +0200 http://bitbucket.org/pypy/pypy/changeset/d52b849b3779/ Log:Implemented reset for numpy broadcast object. diff --git a/pypy/module/micronumpy/broadcast.py b/pypy/module/micronumpy/broadcast.py --- a/pypy/module/micronumpy/broadcast.py +++ b/pypy/module/micronumpy/broadcast.py @@ -75,6 +75,11 @@ return res[0] return space.newtuple(res) +def descr_reset(self, space): +self.index = 0 +self.done = False +for it in self.list_iter_state: +it.reset() W_Broadcast.typedef = TypeDef("numpy.broadcast", __new__=interp2app(descr_new_broadcast), @@ -86,4 +91,5 @@ numiter=GetSetProperty(W_Broadcast.descr_get_numiter), nd=GetSetProperty(W_Broadcast.descr_get_number_of_dimensions), iters=GetSetProperty(W_Broadcast.descr_get_iters), + reset=interp2app(W_Broadcast.descr_reset), ) diff --git a/pypy/module/micronumpy/flatiter.py b/pypy/module/micronumpy/flatiter.py --- a/pypy/module/micronumpy/flatiter.py +++ b/pypy/module/micronumpy/flatiter.py @@ -76,7 +76,7 @@ base.get_order(), w_instance=base) return loop.flatiter_getitem(res, self.iter, state, step) finally: -self.iter.reset(self.state, mutate=True) +self.reset() def descr_setitem(self, space, w_idx, w_value): if not (space.isinstance_w(w_idx, space.w_int) or @@ -96,11 +96,14 @@ arr = convert_to_array(space, w_value) loop.flatiter_setitem(space, dtype, arr, self.iter, state, step, length) finally: -self.iter.reset(self.state, mutate=True) +self.reset() def descr___array_wrap__(self, space, obj, w_context=None): return obj +def reset(self): +self.iter.reset(self.state, mutate=True) + W_FlatIterator.typedef = TypeDef("numpy.flatiter", base = GetSetProperty(W_FlatIterator.descr_base), index = GetSetProperty(W_FlatIterator.descr_index), diff --git a/pypy/module/micronumpy/test/test_broadcast.py b/pypy/module/micronumpy/test/test_broadcast.py --- a/pypy/module/micronumpy/test/test_broadcast.py +++ b/pypy/module/micronumpy/test/test_broadcast.py @@ -123,3 +123,15 @@ assert step_in_y == y[0, 0] # == 3 assert step_in_broadcast == (1, 3) assert step2_in_y == y[1, 0] # == 4 + +def test_broadcast_reset(self): +import numpy as np +x = np.array([1, 2, 3]) +y = np.array([[4], [5], [6]]) + +b = np.broadcast(x, y) +b.next(), b.next(), b.next() +b.reset() + +assert b.index == 0 +assert b.next() == (1, 4) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k-update: Fix pointer types in test module creation
Author: Ronan LamyBranch: py3k-update Changeset: r84063:61f551d2e3fc Date: 2016-04-30 20:29 +0100 http://bitbucket.org/pypy/pypy/changeset/61f551d2e3fc/ Log:Fix pointer types in test module creation diff --git a/pypy/module/cpyext/test/banana.c b/pypy/module/cpyext/test/banana.c --- a/pypy/module/cpyext/test/banana.c +++ b/pypy/module/cpyext/test/banana.c @@ -9,11 +9,11 @@ "banana", "Module Doc", -1, -_functions +banana_functions, }; PyMODINIT_FUNC -*PyInit_banana(void) +PyInit_banana(void) { return PyModule_Create(); } diff --git a/pypy/module/cpyext/test/comparisons.c b/pypy/module/cpyext/test/comparisons.c --- a/pypy/module/cpyext/test/comparisons.c +++ b/pypy/module/cpyext/test/comparisons.c @@ -83,7 +83,7 @@ PyMODINIT_FUNC -*PyInit_comparisons(void) +PyInit_comparisons(void) { PyObject *m, *d; diff --git a/pypy/module/cpyext/test/date.c b/pypy/module/cpyext/test/date.c --- a/pypy/module/cpyext/test/date.c +++ b/pypy/module/cpyext/test/date.c @@ -9,11 +9,11 @@ "date", "Module Doc", -1, -_functions +date_functions, }; PyMODINIT_FUNC -*PyInit_date(void) +PyInit_date(void) { PyObject *module, *othermodule; module = PyModule_Create(); diff --git a/pypy/module/cpyext/test/dotted.c b/pypy/module/cpyext/test/dotted.c --- a/pypy/module/cpyext/test/dotted.c +++ b/pypy/module/cpyext/test/dotted.c @@ -9,11 +9,11 @@ "pypy.module.cpyext.test.dotted", "Module Doc", -1, -_functions +dotted_functions }; PyMODINIT_FUNC -*PyInit_dotted(void) +PyInit_dotted(void) { return PyModule_Create(); } diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c --- a/pypy/module/cpyext/test/foo.c +++ b/pypy/module/cpyext/test/foo.c @@ -654,7 +654,11 @@ "foo", "Module Doc", -1, -_functions +foo_functions, +NULL, +NULL, +NULL, +NULL, }; /* Initialize this module. */ @@ -665,7 +669,7 @@ #endif PyMODINIT_FUNC -*PyInit_foo(void) +PyInit_foo(void) { PyObject *m, *d; diff --git a/pypy/module/cpyext/test/foo3.c b/pypy/module/cpyext/test/foo3.c --- a/pypy/module/cpyext/test/foo3.c +++ b/pypy/module/cpyext/test/foo3.c @@ -67,7 +67,7 @@ "foo", "Module Doc", -1, -, +sbkMethods, NULL, NULL, NULL, diff --git a/pypy/module/cpyext/test/modinit.c b/pypy/module/cpyext/test/modinit.c --- a/pypy/module/cpyext/test/modinit.c +++ b/pypy/module/cpyext/test/modinit.c @@ -14,7 +14,7 @@ "modinit", "", -1, - +methods }; PyMODINIT_FUNC diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -395,7 +395,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ % dict(methods='\n'.join(methods_table), modname=modname) init = """PyObject *mod = PyModule_Create();""" @@ -519,7 +519,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ module = self.import_module(name='foo', body=body) @@ -547,7 +547,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ module = self.import_module(name='foo', body=body) @@ -670,7 +670,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ module = self.import_module(name='foo', body=body) @@ -701,7 +701,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ module = self.import_module(name='foo', body=body) @@ -724,7 +724,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ }; """ module = self.import_module(name='foo', body=body) @@ -780,7 +780,7 @@ "%(modname)s", /* m_name */ NULL, /* m_doc */ -1, /* m_size */ -/* m_methods */ +methods,/* m_methods */ };
[pypy-commit] pypy default: document merged branch
Author: Matti PicusBranch: Changeset: r84062:d70b2bdcba73 Date: 2016-04-30 21:00 +0300 http://bitbucket.org/pypy/pypy/changeset/d70b2bdcba73/ Log:document merged branch diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -24,7 +24,11 @@ remove-objspace-options. .. branch: cpyext-for-merge -Update cpyext C-API support: + +Update cpyext C-API support After this branch, we are almost able to support +upstream numpy via cpyext, so we created (yet another) fork of numpy at +github.com/pypy/numpy with the needed changes. Among the significant changes +to cpyext: - allow c-snippet tests to be run with -A so we can verify we are compatible - fix many edge cases exposed by fixing tests to run with -A - issequence() logic matches cpython @@ -40,6 +44,8 @@ - rewrite slot assignment for typeobjects - improve tracking of PyObject to rpython object mapping - support tp_as_{number, sequence, mapping, buffer} slots -After this branch, we are almost able to support upstream numpy via cpyext, so -we created (yet another) fork of numpy at github.com/pypy/numpy with the needed -changes + +.. branch: share-mapdict-methods-2 + +Reduce generated code for subclasses by using the same function objects in all +generated subclasses. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: RPython: using "is" to compare functions does not really work
Author: Armin RigoBranch: Changeset: r84057:c8b5120f31d2 Date: 2016-04-30 18:04 +0200 http://bitbucket.org/pypy/pypy/changeset/c8b5120f31d2/ Log:RPython: using "is" to compare functions does not really work depending on the small-function-set optimization diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py --- a/rpython/rtyper/rpbc.py +++ b/rpython/rtyper/rpbc.py @@ -544,6 +544,21 @@ ll_compress = compression_function(r_set) return llops.gendirectcall(ll_compress, v) +class __extend__(pairtype(FunctionReprBase, FunctionReprBase)): +def rtype_is_((robj1, robj2), hop): +if hop.s_result.is_constant(): +return inputconst(Bool, hop.s_result.const) +s_pbc = annmodel.unionof(robj1.s_pbc, robj2.s_pbc) +r_pbc = hop.rtyper.getrepr(s_pbc) +v1, v2 = hop.inputargs(r_pbc, r_pbc) +assert v1.concretetype == v2.concretetype +if v1.concretetype == Char: +return hop.genop('char_eq', [v1, v2], resulttype=Bool) +elif isinstance(v1.concretetype, Ptr): +return hop.genop('ptr_eq', [v1, v2], resulttype=Bool) +else: +raise TyperError("unknown type %r" % (v1.concretetype,)) + def conversion_table(r_from, r_to): if r_to in r_from._conversion_tables: diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py --- a/rpython/rtyper/test/test_rpbc.py +++ b/rpython/rtyper/test/test_rpbc.py @@ -1497,6 +1497,47 @@ res = self.interpret(f, [2]) assert res == False +def test_is_among_functions_2(self): +def g1(): pass +def g2(): pass +def f(n): +if n > 5: +g = g2 +else: +g = g1 +g() +return g is g2 +res = self.interpret(f, [2]) +assert res == False +res = self.interpret(f, [8]) +assert res == True + +def test_is_among_functions_3(self): +def g0(): pass +def g1(): pass +def g2(): pass +def g3(): pass +def g4(): pass +def g5(): pass +def g6(): pass +def g7(): pass +glist = [g0, g1, g2, g3, g4, g5, g6, g7] +def f(n): +if n > 5: +g = g2 +else: +g = g1 +h = glist[n] +g() +h() +return g is h +res = self.interpret(f, [2]) +assert res == False +res = self.interpret(f, [1]) +assert res == True +res = self.interpret(f, [6]) +assert res == False + def test_shrink_pbc_set(self): def g1(): return 10 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: More result_is_ll
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84059:6c55da8738b8 Date: 2016-04-30 13:00 +0100 http://bitbucket.org/pypy/pypy/changeset/6c55da8738b8/ Log:More result_is_ll diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -328,7 +328,7 @@ return unicodeobject.encode_object(space, w_unicode, 'unicode-escape', 'strict') -@cpython_api([CONST_WSTRING, Py_ssize_t], PyObject) +@cpython_api([CONST_WSTRING, Py_ssize_t], PyObject, result_is_ll=True) def PyUnicode_FromUnicode(space, wchar_p, length): """Create a Unicode Object from the Py_UNICODE buffer u of the given size. u may be NULL which causes the contents to be undefined. It is the user's @@ -342,14 +342,14 @@ else: return rffi.cast(PyObject, new_empty_unicode(space, length)) -@cpython_api([CONST_WSTRING, Py_ssize_t], PyObject) +@cpython_api([CONST_WSTRING, Py_ssize_t], PyObject, result_is_ll=True) def PyUnicode_FromWideChar(space, wchar_p, length): """Create a Unicode object from the wchar_t buffer w of the given size. Return NULL on failure.""" # PyPy supposes Py_UNICODE == wchar_t return PyUnicode_FromUnicode(space, wchar_p, length) -@cpython_api([PyObject, CONST_STRING], PyObject) +@cpython_api([PyObject, CONST_STRING], PyObject, result_is_ll=True) def _PyUnicode_AsDefaultEncodedString(space, ref, errors): # Returns a borrowed reference. py_uni = rffi.cast(PyUnicodeObject, ref) @@ -430,7 +430,7 @@ w_str = space.wrap(rffi.charp2str(s)) return space.call_method(w_str, 'decode', space.wrap("utf-8")) -@cpython_api([CONST_STRING, Py_ssize_t], PyObject) +@cpython_api([CONST_STRING, Py_ssize_t], PyObject, result_is_ll=True) def PyUnicode_FromStringAndSize(space, s, size): """Create a Unicode Object from the char buffer u. The bytes will be interpreted as being UTF-8 encoded. u may also be NULL which causes the ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: hg merge default
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84061:d69ecfcd442d Date: 2016-04-30 17:11 +0100 http://bitbucket.org/pypy/pypy/changeset/d69ecfcd442d/ Log:hg merge default diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py --- a/rpython/rtyper/rpbc.py +++ b/rpython/rtyper/rpbc.py @@ -544,6 +544,21 @@ ll_compress = compression_function(r_set) return llops.gendirectcall(ll_compress, v) +class __extend__(pairtype(FunctionReprBase, FunctionReprBase)): +def rtype_is_((robj1, robj2), hop): +if hop.s_result.is_constant(): +return inputconst(Bool, hop.s_result.const) +s_pbc = annmodel.unionof(robj1.s_pbc, robj2.s_pbc) +r_pbc = hop.rtyper.getrepr(s_pbc) +v1, v2 = hop.inputargs(r_pbc, r_pbc) +assert v1.concretetype == v2.concretetype +if v1.concretetype == Char: +return hop.genop('char_eq', [v1, v2], resulttype=Bool) +elif isinstance(v1.concretetype, Ptr): +return hop.genop('ptr_eq', [v1, v2], resulttype=Bool) +else: +raise TyperError("unknown type %r" % (v1.concretetype,)) + def conversion_table(r_from, r_to): if r_to in r_from._conversion_tables: diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py --- a/rpython/rtyper/test/test_rpbc.py +++ b/rpython/rtyper/test/test_rpbc.py @@ -1497,6 +1497,47 @@ res = self.interpret(f, [2]) assert res == False +def test_is_among_functions_2(self): +def g1(): pass +def g2(): pass +def f(n): +if n > 5: +g = g2 +else: +g = g1 +g() +return g is g2 +res = self.interpret(f, [2]) +assert res == False +res = self.interpret(f, [8]) +assert res == True + +def test_is_among_functions_3(self): +def g0(): pass +def g1(): pass +def g2(): pass +def g3(): pass +def g4(): pass +def g5(): pass +def g6(): pass +def g7(): pass +glist = [g0, g1, g2, g3, g4, g5, g6, g7] +def f(n): +if n > 5: +g = g2 +else: +g = g1 +h = glist[n] +g() +h() +return g is h +res = self.interpret(f, [2]) +assert res == False +res = self.interpret(f, [1]) +assert res == True +res = self.interpret(f, [6]) +assert res == False + def test_shrink_pbc_set(self): def g1(): return 10 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: more translation fixes
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84060:c042ef987a6a Date: 2016-04-30 13:40 +0100 http://bitbucket.org/pypy/pypy/changeset/c042ef987a6a/ Log:more translation fixes diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -684,18 +684,21 @@ def __init__(self, space): self.space = space self.wrapper_gens = {}# {signature: WrapperGen()} -self.callable2name = {} self.stats = [0, 0] class WrapperGen(object): +wrapper_second_level = None + def __init__(self, space, signature): self.space = space -self.callable2name = {} -self.wrapper_second_level = make_wrapper_second_level( -self.space, self.callable2name, *signature) +self.signature = signature +self.callable2name = [] def make_wrapper(self, callable): -self.callable2name[callable] = callable.__name__ +self.callable2name.append((callable, callable.__name__)) +if self.wrapper_second_level is None: +self.wrapper_second_level = make_wrapper_second_level( +self.space, self.callable2name, *self.signature) wrapper_second_level = self.wrapper_second_level def wrapper(*args): @@ -747,12 +750,12 @@ @dont_inline def deadlock_error(funcname): fatalerror_notb("GIL deadlock detected when a CPython C extension " -"module calls %r" % (funcname,)) +"module calls '%s'" % (funcname,)) @dont_inline def no_gil_error(funcname): fatalerror_notb("GIL not held when a CPython C extension " -"module calls %r" % (funcname,)) +"module calls '%s'" % (funcname,)) @dont_inline def not_supposed_to_fail(funcname): @@ -794,6 +797,18 @@ if error_value is not CANNOT_FAIL: assert lltype.typeOf(error_value) == lltype.typeOf(fatal_value) +def invalid(err): +"NOT_RPYTHON: translation-time crash if this ends up being called" +raise ValueError(err) +invalid.__name__ = 'invalid_%s' % (callable2name[0][1],) + +def nameof(callable): +for c, n in callable2name: +if c is callable: +return n +return '' +nameof._dont_inline_ = True + def wrapper_second_level(*args): from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj from pypy.module.cpyext.pyobject import as_pyobj @@ -806,7 +821,7 @@ tid = rthread.get_or_make_ident() if gil_acquire: if cpyext_glob_tid_ptr[0] == tid: -deadlock_error(callable2name[callable]) +deadlock_error(nameof(callable)) rgil.acquire() assert cpyext_glob_tid_ptr[0] == 0 elif pygilstate_ensure: @@ -819,7 +834,7 @@ args += (pystate.PyGILState_UNLOCKED,) else: if cpyext_glob_tid_ptr[0] != tid: -no_gil_error(callable2name[callable]) +no_gil_error(nameof(callable)) cpyext_glob_tid_ptr[0] = 0 rffi.stackcounter.stacks_counter += 1 @@ -865,14 +880,16 @@ if failed: if error_value is CANNOT_FAIL: -raise not_supposed_to_fail(callable2name[callable]) +raise not_supposed_to_fail(nameof(callable)) retval = error_value elif is_PyObject(restype): if is_pyobj(result): -assert result_is_ll +if not result_is_ll: +raise invalid("missing result_is_ll=True") else: -assert not result_is_ll +if result_is_ll: +raise invalid("result_is_ll=True but not ll PyObject") if result_borrowed: result = as_pyobj(space, result) else: @@ -883,7 +900,7 @@ retval = rffi.cast(restype, result) except Exception, e: -unexpected_exception(callable2name[callable], e, tb) +unexpected_exception(nameof(callable), e, tb) return fatal_value assert lltype.typeOf(retval) == restype diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -308,7 +308,7 @@ w_res = PyObject_RichCompare(space, ref1, ref2, opid) return int(space.is_true(w_res)) -@cpython_api([PyObject], PyObject) +@cpython_api([PyObject], PyObject, result_is_ll=True) def PyObject_SelfIter(space, ref): """Undocumented function, this is what CPython does.""" Py_IncRef(space, ref) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: Give up on this test, which is also half-not-passing in default
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84058:c1ee0447bc68 Date: 2016-04-30 13:00 +0100 http://bitbucket.org/pypy/pypy/changeset/c1ee0447bc68/ Log:Give up on this test, which is also half-not-passing in default diff --git a/pypy/module/cpyext/test/test_pyerrors.py b/pypy/module/cpyext/test/test_pyerrors.py --- a/pypy/module/cpyext/test/test_pyerrors.py +++ b/pypy/module/cpyext/test/test_pyerrors.py @@ -365,6 +365,8 @@ assert "in test_PyErr_Display\n" in output assert "ZeroDivisionError" in output +@pytest.mark.skipif(True, reason= +"XXX seems to pass, but doesn't: 'py.test -s' shows errors in PyObject_Free") def test_GetSetExcInfo(self): import sys if self.runappdirect and (sys.version_info.major < 3 or ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: more translation fighting
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84054:bfce7130fc86 Date: 2016-04-30 11:32 +0100 http://bitbucket.org/pypy/pypy/changeset/bfce7130fc86/ Log:more translation fighting diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -862,21 +862,19 @@ elif is_PyObject(restype): if is_pyobj(result): -retval = result +assert 0, "XXX retval = result" else: -if result is not None: -if result_borrowed: -retval = as_pyobj(space, result) -else: -retval = make_ref(space, result) -retval = rffi.cast(restype, retval) +if result_borrowed: +result = as_pyobj(space, result) else: -retval = lltype.nullptr(restype.TO) -elif restype is not lltype.Void: -retval = rffi.cast(restype, result) +result = make_ref(space, result) +retval = rffi.cast(restype, result) + except Exception, e: unexpected_exception(callable2name[callable], e, tb) +return fatal_value +assert lltype.typeOf(retval) == restype rffi.stackcounter.stacks_counter -= 1 # see "Handling of the GIL" above ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: hg merge default
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84055:4c3d9f56e6d4 Date: 2016-04-30 11:32 +0100 http://bitbucket.org/pypy/pypy/changeset/4c3d9f56e6d4/ Log:hg merge default diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst --- a/pypy/doc/faq.rst +++ b/pypy/doc/faq.rst @@ -117,13 +117,22 @@ On which platforms does PyPy run? - -PyPy is regularly and extensively tested on Linux machines. It mostly +PyPy currently supports: + + * **x86** machines on most common operating systems +(Linux 32/64 bits, Mac OS X 64 bits, Windows 32 bits, OpenBSD, FreeBSD), + + * newer **ARM** hardware (ARMv6 or ARMv7, with VFPv3) running Linux, + + * big- and little-endian variants of **PPC64** running Linux, + + * **s390x** running Linux + +PyPy is regularly and extensively tested on Linux machines. It works on Mac and Windows: it is tested there, but most of us are running -Linux so fixes may depend on 3rd-party contributions. PyPy's JIT -works on x86 (32-bit or 64-bit) and on ARM (ARMv6 or ARMv7). -Support for POWER (64-bit) is stalled at the moment. +Linux so fixes may depend on 3rd-party contributions. -To bootstrap from sources, PyPy can use either CPython (2.6 or 2.7) or +To bootstrap from sources, PyPy can use either CPython 2.7 or another (e.g. older) PyPy. Cross-translation is not really supported: e.g. to build a 32-bit PyPy, you need to have a 32-bit environment. Cross-translation is only explicitly supported between a 32-bit Intel diff --git a/pypy/interpreter/test/test_typedef.py b/pypy/interpreter/test/test_typedef.py --- a/pypy/interpreter/test/test_typedef.py +++ b/pypy/interpreter/test/test_typedef.py @@ -362,6 +362,45 @@ """) assert seen == [1] +def test_mapdict_number_of_slots(self): +space = self.space +a, b, c = space.unpackiterable(space.appexec([], """(): +class A(object): +pass +a = A() +a.x = 1 +class B: +pass +b = B() +b.x = 1 +class C(int): +pass +c = C(1) +c.x = 1 +return a, b, c +"""), 3) +assert not hasattr(a, "storage") +assert not hasattr(b, "storage") +assert hasattr(c, "storage") + +def test_del(self): +space = self.space +a, b, c, d = space.unpackiterable(space.appexec([], """(): +class A(object): +pass +class B(object): +def __del__(self): +pass +class F(file): +pass +class G(file): +def __del__(self): +pass +return A(), B(), F("xyz", "w"), G("ghi", "w") +""")) +assert type(b).__base__ is type(a) +assert hasattr(c, "__del__") +assert type(d) is type(c) class AppTestTypeDef: diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -103,43 +103,61 @@ # we need two subclasses of the app-level type, one to add mapdict, and then one # to add del to not slow down the GC. -def get_unique_interplevel_subclass(config, cls, needsdel=False): +def get_unique_interplevel_subclass(space, cls, needsdel=False): "NOT_RPYTHON: initialization-time only" if hasattr(cls, '__del__') and getattr(cls, "handle_del_manually", False): needsdel = False assert cls.typedef.acceptable_as_base_class -key = config, cls, needsdel +key = space, cls, needsdel try: return _subclass_cache[key] except KeyError: # XXX can save a class if cls already has a __del__ -if needsdel: -cls = get_unique_interplevel_subclass(config, cls, False) -subcls = _getusercls(config, cls, needsdel) +keys = [key] +base_has_del = hasattr(cls, '__del__') +if base_has_del: +# if the base has a __del__, we only need one class +keys = [(space, cls, True), (space, cls, False)] +needsdel = True +elif needsdel: +cls = get_unique_interplevel_subclass(space, cls, False) +subcls = _getusercls(space, cls, needsdel) assert key not in _subclass_cache -_subclass_cache[key] = subcls +for key in keys: +_subclass_cache[key] = subcls return subcls get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo" _subclass_cache = {} -def _getusercls(config, cls, wants_del, reallywantdict=False): +def _getusercls(space, cls, wants_del, reallywantdict=False): from rpython.rlib import objectmodel +from pypy.objspace.std.objectobject import W_ObjectObject +from pypy.module.__builtin__.interp_classobj import W_InstanceObject from pypy.objspace.std.mapdict import (BaseUserClassMapdict,
[pypy-commit] pypy share-cpyext-cpython-api: mess in progress
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84056:e4d93f6ca982 Date: 2016-04-30 12:11 +0100 http://bitbucket.org/pypy/pypy/changeset/e4d93f6ca982/ Log:mess in progress diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -256,7 +256,7 @@ class ApiFunction: def __init__(self, argtypes, restype, callable, error=_NOT_SPECIFIED, - c_name=None, gil=None, result_borrowed=False): + c_name=None, gil=None, result_borrowed=False, result_is_ll=False): self.argtypes = argtypes self.restype = restype self.functype = lltype.Ptr(lltype.FuncType(argtypes, restype)) @@ -277,6 +277,9 @@ assert len(self.argnames) == len(self.argtypes) self.gil = gil self.result_borrowed = result_borrowed +self.result_is_ll = result_is_ll +if result_is_ll:# means 'returns a low-level PyObject pointer' +assert is_PyObject(restype) # def get_llhelper(space): return llhelper(self.functype, self.get_wrapper(space)) @@ -298,7 +301,7 @@ DEFAULT_HEADER = 'pypy_decl.h' def cpython_api(argtypes, restype, error=_NOT_SPECIFIED, header=DEFAULT_HEADER, -gil=None, result_borrowed=False): +gil=None, result_borrowed=False, result_is_ll=False): """ Declares a function to be exported. - `argtypes`, `restype` are lltypes and describe the function signature. @@ -337,7 +340,8 @@ c_name = func_name api_function = ApiFunction(argtypes, restype, func, error, c_name=c_name, gil=gil, - result_borrowed=result_borrowed) + result_borrowed=result_borrowed, + result_is_ll=result_is_ll) func.api_func = api_function if error is _NOT_SPECIFIED: @@ -613,6 +617,9 @@ def is_PyObject(TYPE): if not isinstance(TYPE, lltype.Ptr): return False +if TYPE == PyObject: +return True +assert not isinstance(TYPE.TO, lltype.ForwardReference) return hasattr(TYPE.TO, 'c_ob_refcnt') and hasattr(TYPE.TO, 'c_ob_type') # a pointer to PyObject @@ -710,7 +717,7 @@ argnames = callable.api_func.argnames argtypesw = zip(callable.api_func.argtypes, [_name.startswith("w_") for _name in argnames]) -error_value = callable.api_func.error_value +error_value = getattr(callable.api_func, "error_value", CANNOT_FAIL) if (isinstance(callable.api_func.restype, lltype.Ptr) and error_value is not CANNOT_FAIL): assert lltype.typeOf(error_value) == callable.api_func.restype @@ -720,6 +727,7 @@ signature = (tuple(argtypesw), callable.api_func.restype, callable.api_func.result_borrowed, + callable.api_func.result_is_ll, error_value, gil) @@ -769,7 +777,7 @@ assert False def make_wrapper_second_level(space, callable2name, argtypesw, restype, - result_borrowed, error_value, gil): + result_borrowed, result_is_ll, error_value, gil): from rpython.rlib import rgil argtypes_enum_ui = unrolling_iterable(enumerate(argtypesw)) fatal_value = restype._defl() @@ -862,13 +870,17 @@ elif is_PyObject(restype): if is_pyobj(result): -assert 0, "XXX retval = result" +assert result_is_ll else: +assert not result_is_ll if result_borrowed: result = as_pyobj(space, result) else: result = make_ref(space, result) -retval = rffi.cast(restype, result) +retval = rffi.cast(restype, result) + +elif restype is not lltype.Void: +retval = rffi.cast(restype, result) except Exception, e: unexpected_exception(callable2name[callable], e, tb) diff --git a/pypy/module/cpyext/bytesobject.py b/pypy/module/cpyext/bytesobject.py --- a/pypy/module/cpyext/bytesobject.py +++ b/pypy/module/cpyext/bytesobject.py @@ -124,7 +124,7 @@ #___ -@cpython_api([CONST_STRING, Py_ssize_t], PyObject) +@cpython_api([CONST_STRING, Py_ssize_t], PyObject, result_is_ll=True) def PyString_FromStringAndSize(space, char_p, length): if char_p: s = rffi.charpsize2str(char_p, length) diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py --- a/pypy/module/cpyext/frameobject.py +++ b/pypy/module/cpyext/frameobject.py @@ -67,7 +67,8 @@ track_reference(space, py_obj, w_obj) return w_obj
[pypy-commit] pypy default: The bogus casting is not needed any more after 9f9c409ee27e
Author: Armin RigoBranch: Changeset: r84053:ac2d62414b37 Date: 2016-04-30 10:42 +0200 http://bitbucket.org/pypy/pypy/changeset/ac2d62414b37/ Log:The bogus casting is not needed any more after 9f9c409ee27e diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py --- a/pypy/module/cpyext/ndarrayobject.py +++ b/pypy/module/cpyext/ndarrayobject.py @@ -239,9 +239,7 @@ gufunctype = lltype.Ptr(ufuncs.GenericUfunc) -# XXX single rffi.CArrayPtr(gufunctype) does not work, this does, is there -# a problem with casting function pointers? -@cpython_api([rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)), rffi.VOIDP, rffi.CCHARP, Py_ssize_t, Py_ssize_t, +@cpython_api([rffi.CArrayPtr(gufunctype), rffi.VOIDP, rffi.CCHARP, Py_ssize_t, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.CCHARP, rffi.CCHARP, Py_ssize_t, rffi.CCHARP], PyObject, header=HEADER) def PyUFunc_FromFuncAndDataAndSignature(space, funcs, data, types, ntypes, @@ -256,7 +254,7 @@ funcs_w = [None] * ntypes dtypes_w = [None] * ntypes * (nin + nout) for i in range(ntypes): -funcs_w[i] = ufuncs.W_GenericUFuncCaller(rffi.cast(gufunctype, funcs[i]), data) +funcs_w[i] = ufuncs.W_GenericUFuncCaller(funcs[i], data) for i in range(ntypes*(nin+nout)): dtypes_w[i] = get_dtype_cache(space).dtypes_by_num[ord(types[i])] w_funcs = space.newlist(funcs_w) @@ -268,7 +266,7 @@ w_signature, w_identity, w_name, w_doc, stack_inputs=True) return ufunc_generic -@cpython_api([rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)), rffi.VOIDP, rffi.CCHARP, Py_ssize_t, Py_ssize_t, +@cpython_api([rffi.CArrayPtr(gufunctype), rffi.VOIDP, rffi.CCHARP, Py_ssize_t, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.CCHARP, rffi.CCHARP, Py_ssize_t], PyObject, header=HEADER) def PyUFunc_FromFuncAndData(space, funcs, data, types, ntypes, nin, nout, identity, name, doc, check_return): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Test and fix for yet another very obscure misfeature of ctypes
Author: Armin RigoBranch: Changeset: r84052:9f9c409ee27e Date: 2016-04-30 10:40 +0200 http://bitbucket.org/pypy/pypy/changeset/9f9c409ee27e/ Log:Test and fix for yet another very obscure misfeature of ctypes diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py --- a/rpython/rtyper/lltypesystem/ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/ll2ctypes.py @@ -1009,12 +1009,22 @@ container = _array_of_known_length(T.TO) container._storage = type(cobj)(cobj.contents) elif isinstance(T.TO, lltype.FuncType): +# cobj is a CFunctionType object. We naively think +# that it should be a function pointer. No no no. If +# it was read out of an array, say, then it is a *pointer* +# to a function pointer. In other words, the read doesn't +# read anything, it just takes the address of the function +# pointer inside the array. If later the array is modified +# or goes out of scope, then we crash. CTypes is fun. +# It works if we cast it now to an int and back. cobjkey = intmask(ctypes.cast(cobj, ctypes.c_void_p).value) if cobjkey in _int2obj: container = _int2obj[cobjkey] else: +name = getattr(cobj, '__name__', '?') +cobj = ctypes.cast(cobjkey, type(cobj)) _callable = get_ctypes_trampoline(T.TO, cobj) -return lltype.functionptr(T.TO, getattr(cobj, '__name__', '?'), +return lltype.functionptr(T.TO, name, _callable=_callable) elif isinstance(T.TO, lltype.OpaqueType): if T == llmemory.GCREF: diff --git a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py --- a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py @@ -1405,6 +1405,45 @@ a2 = ctypes2lltype(lltype.Ptr(A), lltype2ctypes(a)) assert a2._obj.getitem(0)._obj._parentstructure() is a2._obj +def test_array_of_function_pointers(self): +c_source = py.code.Source(r""" +#include "src/precommondefs.h" +#include + +typedef int(*funcptr_t)(void); +static int forty_two(void) { return 42; } +static int forty_three(void) { return 43; } +static funcptr_t testarray[2]; +RPY_EXPORTED void runtest(void cb(funcptr_t *)) { +testarray[0] = _two; +testarray[1] = _three; +fprintf(stderr, "_two = %p\n", testarray[0]); +fprintf(stderr, "_three = %p\n", testarray[1]); +cb(testarray); +testarray[0] = 0; +testarray[1] = 0; +} +""") +eci = ExternalCompilationInfo(include_dirs=[cdir], + separate_module_sources=[c_source]) + +PtrF = lltype.Ptr(lltype.FuncType([], rffi.INT)) +ArrayPtrF = rffi.CArrayPtr(PtrF) +CALLBACK = rffi.CCallback([ArrayPtrF], lltype.Void) + +runtest = rffi.llexternal('runtest', [CALLBACK], lltype.Void, + compilation_info=eci) +seen = [] + +def callback(testarray): +seen.append(testarray[0]) # read a PtrF out of testarray +seen.append(testarray[1]) + +runtest(callback) +assert seen[0]() == 42 +assert seen[1]() == 43 + + class TestPlatform(object): def test_lib_on_libpaths(self): from rpython.translator.platform import platform ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Simplify stuff
Author: Armin RigoBranch: Changeset: r84051:bc001996d331 Date: 2016-04-30 10:33 +0200 http://bitbucket.org/pypy/pypy/changeset/bc001996d331/ Log:Simplify stuff diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py --- a/rpython/rtyper/lltypesystem/ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/ll2ctypes.py @@ -231,17 +231,7 @@ assert max_n >= 0 ITEM = A.OF ctypes_item = get_ctypes_type(ITEM, delayed_builders) -# Python 2.5 ctypes can raise OverflowError on 64-bit builds -for n in [maxint, 2**31]: -MAX_SIZE = n/64 -try: -PtrType = ctypes.POINTER(MAX_SIZE * ctypes_item) -except (OverflowError, AttributeError), e: -pass #^^^ bah, blame ctypes -else: -break -else: -raise e +ctypes_item_ptr = ctypes.POINTER(ctypes_item) class CArray(ctypes.Structure): if is_emulated_long: @@ -265,35 +255,9 @@ bigarray.length = n return bigarray -_ptrtype = None - -@classmethod -def _get_ptrtype(cls): -if cls._ptrtype: -return cls._ptrtype -# ctypes can raise OverflowError on 64-bit builds -# on windows it raises AttributeError even for 2**31 (_length_ missing) -if _MS_WINDOWS: -other_limit = 2**31-1 -else: -other_limit = 2**31 -for n in [maxint, other_limit]: -cls.MAX_SIZE = n / ctypes.sizeof(ctypes_item) -try: -cls._ptrtype = ctypes.POINTER(cls.MAX_SIZE * ctypes_item) -except (OverflowError, AttributeError), e: -pass -else: -break -else: -raise e -return cls._ptrtype - def _indexable(self, index): -PtrType = self._get_ptrtype() -assert index + 1 < self.MAX_SIZE -p = ctypes.cast(ctypes.pointer(self.items), PtrType) -return p.contents +p = ctypes.cast(self.items, ctypes_item_ptr) +return p def _getitem(self, index, boundscheck=True): if boundscheck: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: More precise info about why this segfaults on CPython
Author: Armin RigoBranch: Changeset: r84050:7fdc241191af Date: 2016-04-30 09:41 +0200 http://bitbucket.org/pypy/pypy/changeset/7fdc241191af/ Log:More precise info about why this segfaults on CPython diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py --- a/pypy/module/cpyext/test/test_ndarrayobject.py +++ b/pypy/module/cpyext/test/test_ndarrayobject.py @@ -366,7 +366,7 @@ def test_ufunc(self): if self.runappdirect: from numpy import arange -py.test.xfail('why does this segfault on cpython?') +py.test.xfail('segfaults on cpython: PyUFunc_API == NULL?') else: from _numpypy.multiarray import arange mod = self.import_extension('foo', [ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy share-cpyext-cpython-api: translation fixes (in-progress)
Author: Armin RigoBranch: share-cpyext-cpython-api Changeset: r84049:ea76859f9845 Date: 2016-04-29 18:30 +0100 http://bitbucket.org/pypy/pypy/changeset/ea76859f9845/ Log:translation fixes (in-progress) diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -747,6 +747,11 @@ "module calls %r" % (funcname,)) @dont_inline +def not_supposed_to_fail(funcname): +raise SystemError("The function '%s' was not supposed to fail" + % (funcname,)) + +@dont_inline def unexpected_exception(funcname, e, tb): print 'Fatal error in cpyext, CPython compatibility layer, calling',funcname print 'Either report a bug or consider not using this particular extension' @@ -778,6 +783,8 @@ if isinstance(restype, lltype.Ptr) and error_value == 0: error_value = lltype.nullptr(restype.TO) +if error_value is not CANNOT_FAIL: +assert lltype.typeOf(error_value) == lltype.typeOf(fatal_value) def wrapper_second_level(*args): from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj @@ -785,7 +792,7 @@ # we hope that malloc removal removes the newtuple() that is # inserted exactly here by the varargs specializer callable = args[-1] -args = args[:len(args)-1] +args = args[:-1] # see "Handling of the GIL" above (careful, we don't have the GIL here) tid = rthread.get_or_make_ident() @@ -850,8 +857,7 @@ if failed: if error_value is CANNOT_FAIL: -raise SystemError("The function '%s' was not supposed to fail" - % (callable.__name__,)) +raise not_supposed_to_fail(callable2name[callable]) retval = error_value elif is_PyObject(restype): @@ -865,7 +871,7 @@ retval = make_ref(space, result) retval = rffi.cast(restype, retval) else: -retval = lltype.nullptr(PyObject.TO) +retval = lltype.nullptr(restype.TO) elif restype is not lltype.Void: retval = rffi.cast(restype, result) except Exception, e: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy.org extradoc: update the values
Author: Armin RigoBranch: extradoc Changeset: r741:8b13f0f2008d Date: 2016-04-30 09:16 +0200 http://bitbucket.org/pypy/pypy.org/changeset/8b13f0f2008d/ Log:update the values diff --git a/don1.html b/don1.html --- a/don1.html +++ b/don1.html @@ -9,13 +9,13 @@ $(function() { $("#progressbar").progressbar({ - value: 60.8 + value: 60.9 }); }); - $63833 of $105000 (60.8%) + $63928 of $105000 (60.9%) @@ -23,7 +23,7 @@ This donation goes towards supporting Python 3 in PyPy. Current status: -we have $8907 left +we have $8995 left in the account. Read proposal ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit