Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r94983:f938ea58f52c Date: 2018-08-09 16:32 +0200 http://bitbucket.org/pypy/pypy/changeset/f938ea58f52c/
Log: hg merge default (and port the changes from 2.7/types.py to 3/types.py) diff --git a/lib-python/3/types.py b/lib-python/3/types.py --- a/lib-python/3/types.py +++ b/lib-python/3/types.py @@ -41,9 +41,19 @@ FrameType = type(tb.tb_frame) tb = None; del tb -# For Jython, the following two types are identical +# +# On CPython, FunctionType.__code__ is a 'getset_descriptor', but +# FunctionType.__globals__ is a 'member_descriptor', just like app-level +# slots. On PyPy, all descriptors of built-in types are +# 'getset_descriptor', but the app-level slots are 'member_descriptor' +# as well. (On Jython the situation might still be different.) +# +# Note that MemberDescriptorType was equal to GetSetDescriptorType in +# PyPy <= 6.0. +# GetSetDescriptorType = type(FunctionType.__code__) -MemberDescriptorType = type(FunctionType.__globals__) +class _C: __slots__ = 's' +MemberDescriptorType = type(_C.s) del sys, _f, _g, _C, _c, # Not for export diff --git a/lib_pypy/cffi/_cffi_errors.h b/lib_pypy/cffi/_cffi_errors.h --- a/lib_pypy/cffi/_cffi_errors.h +++ b/lib_pypy/cffi/_cffi_errors.h @@ -50,7 +50,9 @@ "import sys\n" "class FileLike:\n" " def write(self, x):\n" - " of.write(x)\n" + " try:\n" + " of.write(x)\n" + " except: pass\n" " self.buf += x\n" "fl = FileLike()\n" "fl.buf = ''\n" diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -2076,7 +2076,7 @@ else: skip_leading_underscores = False for name in all: - if skip_leading_underscores and name[0]=='_': + if skip_leading_underscores and name and name[0] == '_': continue into_locals[name] = getattr(module, name) ''', filename=__file__) diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -101,8 +101,8 @@ foobar = "found = 123", barbaz = "other = 543") setuppkg("pkg.withoutall", - __init__ = "", - foobar = "found = 123") + __init__ = "globals()[''] = 456", + foobar = "found = 123\n") setuppkg("pkg.bogusall", __init__ = "__all__ = 42") setuppkg("pkg_r", inpkg = "import x.y") @@ -703,6 +703,13 @@ exec("from pkg.withoutall import *", d) assert d["foobar"].found == 123 + def test_import_star_empty_string(self): + for case in ["not-imported-yet", "already-imported"]: + d = {} + exec("from pkg.withoutall import *", d) + assert "" in d + + def test_import_star_with_bogus___all__(self): for case in ["not-imported-yet", "already-imported"]: try: diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py @@ -1946,3 +1946,30 @@ # only works with the Python FFI instances ffi = FFI(backend=self.Backend()) assert ffi.sizeof("struct{int a;}") == ffi.sizeof("int") + + def test_callback_large_struct(self): + ffi = FFI(backend=self.Backend()) + # more than 8 bytes + ffi.cdef("struct foo_s { unsigned long a, b, c; };") + # + @ffi.callback("void(struct foo_s)") + def cb(s): + seen.append(ffi.typeof(s)) + s.a += 1 + s.b += 2 + s.c += 3 + seen.append(s.a) + seen.append(s.b) + seen.append(s.c) + # + s1 = ffi.new("struct foo_s *", {'a': 100, 'b': 200, 'c': 300}) + seen = [] + cb(s1[0]) + assert len(seen) == 4 + assert s1.a == 100 # unmodified + assert s1.b == 200 + assert s1.c == 300 + assert seen[0] == ffi.typeof("struct foo_s") + assert seen[1] == 101 + assert seen[2] == 202 + assert seen[3] == 303 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py @@ -103,6 +103,11 @@ { return (unsigned int)(a + 42); } + +EXPORT void modify_struct_value(RECT r) +{ + r.left = r.right = r.top = r.bottom = 500; +} """ class TestOwnLib(object): @@ -331,3 +336,25 @@ assert lib.foo_2bytes(u+'\u1234') == u+'\u125e' assert lib.foo_4bytes(u+'\u1234') == u+'\u125e' assert lib.foo_4bytes(u+'\U00012345') == u+'\U0001236f' + + def test_modify_struct_value(self): + if self.module is None: + py.test.skip("fix the auto-generation of the tiny test lib") + ffi = FFI(backend=self.Backend()) + ffi.cdef(""" + typedef struct { + long left; + long top; + long right; + long bottom; + } RECT; + + void modify_struct_value(RECT r); + """) + lib = ffi.dlopen(self.module) + s = ffi.new("RECT *", [11, 22, 33, 44]) + lib.modify_struct_value(s[0]) + assert s.left == 11 + assert s.top == 22 + assert s.right == 33 + assert s.bottom == 44 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_zdist.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_zdist.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_zdist.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_zdist.py @@ -3,6 +3,8 @@ import subprocess import cffi from pypy.module.test_lib_pypy.cffi_tests.udir import udir +from shutil import rmtree +from tempfile import mkdtemp def chdir_to_tmp(f): @@ -34,13 +36,20 @@ env = os.environ.copy() # a horrible hack to prevent distutils from finding ~/.pydistutils.cfg # (there is the --no-user-cfg option, but not in Python 2.6...) - env['HOME'] = '/this/path/does/not/exist' + # NOTE: pointing $HOME to a nonexistent directory can break certain things + # that look there for configuration (like ccache). + tmp_home = mkdtemp() + assert tmp_home != None, "cannot create temporary homedir" + env['HOME'] = tmp_home if cwd is None: newpath = self.rootdir if 'PYTHONPATH' in env: newpath += os.pathsep + env['PYTHONPATH'] env['PYTHONPATH'] = newpath - subprocess.check_call([self.executable] + args, cwd=cwd, env=env) + try: + subprocess.check_call([self.executable] + args, cwd=cwd, env=env) + finally: + rmtree(tmp_home) def _prepare_setuptools(self): if hasattr(TestDist, '_setuptools_ready'): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit