Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r91629:4b2c32aaaf36 Date: 2017-06-21 11:40 +0200 http://bitbucket.org/pypy/pypy/changeset/4b2c32aaaf36/
Log: update to cffi/f06010593f74 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 @@ -36,7 +36,11 @@ if (result == NULL) goto error; +#if PY_MAJOR_VERSION >= 3 + bi = PyImport_ImportModule("builtins"); +#else bi = PyImport_ImportModule("__builtin__"); +#endif if (bi == NULL) goto error; PyDict_SetItemString(result, "__builtins__", bi); diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py --- a/lib_pypy/cffi/api.py +++ b/lib_pypy/cffi/api.py @@ -765,7 +765,7 @@ if sys.platform != "win32": return backend.load_library(None, flags) name = "c" # Windows: load_library(None) fails, but this works - # (backward compatibility hack only) + # on Python 2 (backward compatibility hack only) first_error = None if '.' in name or '/' in name or os.sep in name: try: @@ -775,6 +775,9 @@ import ctypes.util path = ctypes.util.find_library(name) if path is None: + if name == "c" and sys.platform == "win32" and sys.version_info >= (3,): + raise OSError("dlopen(None) cannot work on Windows for Python 3 " + "(see http://bugs.python.org/issue23606)") msg = ("ctypes.util.find_library() did not manage " "to locate a library called %r" % (name,)) if first_error is not None: diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py --- a/pypy/module/_cffi_backend/test/_backend_test_c.py +++ b/pypy/module/_cffi_backend/test/_backend_test_c.py @@ -50,6 +50,10 @@ path = None else: path = ctypes.util.find_library(name) + if path is None and name == 'c': + assert sys.platform == 'win32' + assert sys.version_info >= (3,) + py.test.skip("dlopen(None) cannot work on Windows with Python 3") return load_library(path, flags) def test_load_library(): 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 @@ -11,6 +11,10 @@ SIZE_OF_PTR = ctypes.sizeof(ctypes.c_void_p) SIZE_OF_WCHAR = ctypes.sizeof(ctypes.c_wchar) +def needs_dlopen_none(): + if sys.platform == 'win32' and sys.version_info >= (3,): + py.test.skip("dlopen(None) cannot work on Windows for Python 3") + class BackendTests: @@ -355,7 +359,6 @@ # p = ffi.new("wchar_t[]", u+'\U00023456') if SIZE_OF_WCHAR == 2: - assert sys.maxunicode == 0xffff assert len(p) == 3 assert p[0] == u+'\ud84d' assert p[1] == u+'\udc56' @@ -938,6 +941,7 @@ def test_enum_partial(self): ffi = FFI(backend=self.Backend()) ffi.cdef(r"enum foo {A, ...}; enum bar { B, C };") + needs_dlopen_none() lib = ffi.dlopen(None) assert lib.B == 0 py.test.raises(VerificationMissing, getattr, lib, "A") @@ -1845,6 +1849,7 @@ #define DOT_UL 1000UL enum foo {AA, BB=DOT, CC}; """) + needs_dlopen_none() lib = ffi.dlopen(None) assert ffi.string(ffi.cast("enum foo", 100)) == "BB" assert lib.DOT_0 == 0 @@ -1874,6 +1879,7 @@ ffi = FFI() ffi.include(ffi1) ffi.cdef("enum { EE2, EE3 };") + needs_dlopen_none() lib = ffi.dlopen(None) assert lib.EE1 == 0 assert lib.EE2 == 0 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_function.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_function.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_function.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_function.py @@ -6,6 +6,7 @@ from cffi.backend_ctypes import CTypesBackend from pypy.module.test_lib_pypy.cffi_tests.udir import udir from pypy.module.test_lib_pypy.cffi_tests.support import FdWriteCapture +from .backend_tests import needs_dlopen_none try: from StringIO import StringIO @@ -112,6 +113,7 @@ int fputs(const char *, void *); void *stderr; """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) ffi.C.fputs # fetch before capturing, for easier debugging with FdWriteCapture() as fd: @@ -128,6 +130,7 @@ int fputs(char *, void *); void *stderr; """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) ffi.C.fputs # fetch before capturing, for easier debugging with FdWriteCapture() as fd: @@ -144,6 +147,7 @@ int fprintf(void *, const char *format, ...); void *stderr; """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) with FdWriteCapture() as fd: ffi.C.fprintf(ffi.C.stderr, b"hello with no arguments\n") @@ -170,6 +174,7 @@ ffi.cdef(""" int printf(const char *format, ...); """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) e = py.test.raises(TypeError, ffi.C.printf, b"hello %d\n", 42) assert str(e.value) == ("argument 2 passed in the variadic part " @@ -180,6 +185,7 @@ ffi.cdef(""" int puts(const char *); """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) fptr = ffi.C.puts assert ffi.typeof(fptr) == ffi.typeof("int(*)(const char*)") @@ -203,6 +209,7 @@ int fputs(const char *, void *); void *stderr; """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) fptr = ffi.cast("int(*)(const char *txt, void *)", ffi.C.fputs) assert fptr == ffi.C.fputs @@ -236,6 +243,7 @@ ffi.cdef(""" int strlen(char[]); """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) p = ffi.new("char[]", b"hello") res = ffi.C.strlen(p) @@ -248,6 +256,7 @@ ffi.cdef(""" void *stdout; """) + needs_dlopen_none() C = ffi.dlopen(None) pout = C.stdout C.stdout = ffi.NULL @@ -260,6 +269,7 @@ ffi.cdef(""" char *strchr(const char *s, int c); """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) p = ffi.new("char[]", b"hello world!") q = ffi.C.strchr(p, ord('w')) @@ -276,6 +286,7 @@ struct in_addr { unsigned int s_addr; }; char *inet_ntoa(struct in_addr in); """) + needs_dlopen_none() ffi.C = ffi.dlopen(None) ina = ffi.new("struct in_addr *", [0x04040404]) a = ffi.C.inet_ntoa(ina[0]) @@ -297,6 +308,7 @@ filename = str(udir.join('fputs_custom_FILE')) ffi = FFI(backend=self.Backend()) ffi.cdef("int fputs(const char *, FILE *);") + needs_dlopen_none() C = ffi.dlopen(None) with open(filename, 'wb') as f: f.write(b'[') @@ -312,6 +324,7 @@ ffi = FFI(backend=self.Backend()) ffi.cdef("""enum foo_e { AA, BB, CC=5, DD }; typedef enum { EE=-5, FF } some_enum_t;""") + needs_dlopen_none() lib = ffi.dlopen(None) assert lib.AA == 0 assert lib.BB == 1 @@ -323,6 +336,7 @@ def test_void_star_accepts_string(self): ffi = FFI(backend=self.Backend()) ffi.cdef("""int strlen(const void *);""") + needs_dlopen_none() lib = ffi.dlopen(None) res = lib.strlen(b"hello") assert res == 5 @@ -332,6 +346,7 @@ py.test.skip("not supported by the ctypes backend") ffi = FFI(backend=self.Backend()) ffi.cdef("""int strlen(signed char *);""") + needs_dlopen_none() lib = ffi.dlopen(None) res = lib.strlen(b"hello") assert res == 5 @@ -341,6 +356,7 @@ py.test.skip("not supported by the ctypes backend") ffi = FFI(backend=self.Backend()) ffi.cdef("""int strlen(unsigned char *);""") + needs_dlopen_none() lib = ffi.dlopen(None) res = lib.strlen(b"hello") assert res == 5 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_parsing.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_parsing.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_parsing.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_parsing.py @@ -1,6 +1,8 @@ # Generated by pypy/tool/import_cffi.py import py, sys, re from cffi import FFI, FFIError, CDefError, VerificationError +from .backend_tests import needs_dlopen_none + class FakeBackend(object): @@ -91,6 +93,7 @@ def test_pipe(): ffi = FFI(backend=FakeBackend()) ffi.cdef("int pipe(int pipefd[2]);") + needs_dlopen_none() C = ffi.dlopen(None) func = C.pipe assert func.name == 'pipe' @@ -99,6 +102,7 @@ def test_vararg(): ffi = FFI(backend=FakeBackend()) ffi.cdef("short foo(int, ...);") + needs_dlopen_none() C = ffi.dlopen(None) func = C.foo assert func.name == 'foo' @@ -109,6 +113,7 @@ ffi.cdef(""" int foo(void); """) + needs_dlopen_none() C = ffi.dlopen(None) assert C.foo.BType == '<func (), <int>, False>' @@ -119,6 +124,7 @@ typedef UInt UIntReally; UInt foo(void); """) + needs_dlopen_none() C = ffi.dlopen(None) assert str(ffi.typeof("UIntReally")) == '<unsigned int>' assert C.foo.BType == '<func (), <unsigned int>, False>' @@ -129,6 +135,7 @@ typedef struct { int a, b; } foo_t, *foo_p; int foo(foo_p[]); """) + needs_dlopen_none() C = ffi.dlopen(None) assert str(ffi.typeof("foo_t")) == '<int>a, <int>b' assert str(ffi.typeof("foo_p")) == '<pointer to <int>a, <int>b>' @@ -218,6 +225,7 @@ def test_override(): ffi = FFI(backend=FakeBackend()) + needs_dlopen_none() C = ffi.dlopen(None) ffi.cdef("int foo(void);") py.test.raises(FFIError, ffi.cdef, "long foo(void);") @@ -404,6 +412,7 @@ ffi.cdef(""" enum Enum { POS = +1, TWO = 2, NIL = 0, NEG = -1, OP = (POS+TWO)-1}; """) + needs_dlopen_none() C = ffi.dlopen(None) assert C.POS == 1 assert C.TWO == 2 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_new_ffi_1.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_new_ffi_1.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_new_ffi_1.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_new_ffi_1.py @@ -419,7 +419,6 @@ # p = ffi.new("wchar_t[]", u+'\U00023456') if SIZE_OF_WCHAR == 2: - assert sys.maxunicode == 0xffff assert len(p) == 3 assert p[0] == u+'\ud84d' assert p[1] == u+'\udc56' diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py @@ -95,6 +95,8 @@ if sys.platform == 'win32': import ctypes.util name = ctypes.util.find_msvcrt() + if name is None: + py.test.skip("dlopen(None) cannot work on Windows with Python 3") lib = ffi.dlopen(name) assert lib.strlen(b"hello") == 5 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py @@ -2260,6 +2260,9 @@ assert ffi.typeof("int16_t") is ffi.typeof("char16_t") is ffi.typeof("long") def test_char16_char32_type(no_cpp=False): + if no_cpp is False and sys.platform == "win32": + py.test.skip("aaaaaaa why do modern MSVC compilers still define " + "a very old __cplusplus value") ffi = FFI() ffi.cdef(""" char16_t foo_2bytes(char16_t); @@ -2270,7 +2273,7 @@ typedef uint_least16_t char16_t; typedef uint_least32_t char32_t; #endif - + char16_t foo_2bytes(char16_t a) { return (char16_t)(a + 42); } char32_t foo_4bytes(char32_t a) { return (char32_t)(a + 42); } """, no_cpp=no_cpp) diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/initerror.py b/pypy/module/test_lib_pypy/cffi_tests/embedding/initerror.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/initerror.py @@ -0,0 +1,19 @@ +# Generated by pypy/tool/import_cffi.py +import cffi + +ffi = cffi.FFI() + +ffi.embedding_api(""" + int add1(int, int); +""") + +ffi.embedding_init_code(r""" + raise KeyError +""") + +ffi.set_source("_initerror_cffi", """ +""") + +fn = ffi.compile(verbose=True) +print('FILENAME: %s' % (fn,)) + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit