[pypy-commit] pypy default: import cffi/ad45ea3e4614 (version 1.3.0)

arigo noreply at buildbot.pypy.org
Wed Oct 21 07:31:17 EDT 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r80375:2b91e218456f
Date: 2015-10-21 12:55 +0200
http://bitbucket.org/pypy/pypy/changeset/2b91e218456f/

Log:	import cffi/ad45ea3e4614 (version 1.3.0)

diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -86,9 +86,13 @@
     # but should be fine for all the common types.
     look_for_words = set(COMMON_TYPES)
     look_for_words.add(';')
+    look_for_words.add(',')
+    look_for_words.add('(')
+    look_for_words.add(')')
     look_for_words.add('typedef')
     words_used = set()
     is_typedef = False
+    paren = 0
     previous_word = ''
     for word in _r_words.findall(csource):
         if word in look_for_words:
@@ -99,6 +103,15 @@
                     is_typedef = False
             elif word == 'typedef':
                 is_typedef = True
+                paren = 0
+            elif word == '(':
+                paren += 1
+            elif word == ')':
+                paren -= 1
+            elif word == ',':
+                if is_typedef and paren == 0:
+                    words_used.discard(previous_word)
+                    look_for_words.discard(previous_word)
             else:   # word in COMMON_TYPES
                 words_used.add(word)
         previous_word = word
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
@@ -434,6 +434,7 @@
             py.test.skip("Windows-only test")
         if self.Backend is CTypesBackend:
             py.test.skip("not with the ctypes backend")
+        win64 = (sys.maxsize > 2**32)
         #
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
@@ -457,8 +458,11 @@
         """)
         m = ffi.dlopen("Kernel32.dll")
         tps = ffi.typeof(m.QueryPerformanceFrequency)
-        assert tps is not tpc
-        assert str(tps) == "<ctype 'int(__stdcall *)(long long *)'>"
+        if win64:
+            assert tps is tpc
+        else:
+            assert tps is not tpc
+            assert str(tps) == "<ctype 'int(__stdcall *)(long long *)'>"
         #
         ffi = FFI(backend=self.Backend())
         ffi.cdef("typedef int (__cdecl *fnc_t)(int);")
@@ -466,21 +470,27 @@
         tpc = ffi.typeof("fnc_t")
         tps = ffi.typeof("fns_t")
         assert str(tpc) == "<ctype 'int(*)(int)'>"
-        assert str(tps) == "<ctype 'int(__stdcall *)(int)'>"
+        if win64:
+            assert tps is tpc
+        else:
+            assert str(tps) == "<ctype 'int(__stdcall *)(int)'>"
         #
         fnc = ffi.cast("fnc_t", 0)
         fns = ffi.cast("fns_t", 0)
         ffi.new("fnc_t[]", [fnc])
-        py.test.raises(TypeError, ffi.new, "fnc_t[]", [fns])
-        py.test.raises(TypeError, ffi.new, "fns_t[]", [fnc])
+        if not win64:
+            py.test.raises(TypeError, ffi.new, "fnc_t[]", [fns])
+            py.test.raises(TypeError, ffi.new, "fns_t[]", [fnc])
         ffi.new("fns_t[]", [fns])
 
     def test_stdcall_only_on_windows(self):
-        if sys.platform == 'win32':
-            py.test.skip("not-Windows-only test")
         ffi = FFI(backend=self.Backend())
         ffi.cdef("double __stdcall sin(double x);")     # stdcall ignored
         m = ffi.dlopen(lib_m)
-        assert "double(*)(double)" in str(ffi.typeof(m.sin))
+        if (sys.platform == 'win32' and sys.maxint < 2**32 and 
+                self.Backend is not CTypesBackend):
+            assert "double(__stdcall *)(double)" in str(ffi.typeof(m.sin))
+        else:
+            assert "double(*)(double)" in str(ffi.typeof(m.sin))
         x = m.sin(1.23)
         assert x == math.sin(1.23)
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
@@ -259,6 +259,12 @@
     assert repr(ffi.cast("FILE", 123)) == "<cdata 'char' %s'{'>" % prefix
     ffi.cdef("typedef char int32_t;")
     assert repr(ffi.cast("int32_t", 123)) == "<cdata 'char' %s'{'>" % prefix
+    ffi = FFI()
+    ffi.cdef("typedef int bool, *FILE;")
+    assert repr(ffi.cast("bool", 123)) == "<cdata 'int' 123>"
+    assert repr(ffi.cast("FILE", 123)) == "<cdata 'int *' 0x7b>"
+    ffi = FFI()
+    ffi.cdef("typedef bool (*fn_t)(bool, bool);")   # "bool," but within "( )"
 
 def test_bool():
     ffi = FFI()
@@ -371,7 +377,7 @@
     tp = ffi.typeof("int(*)(int __stdcall x(int),"
                     "       long (__cdecl*y)(void),"
                     "       short(WINAPI *z)(short))")
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and sys.maxsize < 2**32:
         stdcall = '__stdcall '
     else:
         stdcall = ''
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
@@ -2286,7 +2286,7 @@
     #print '...'
     assert res == -500*999*3
     #print 'done'
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and sys.maxsize < 2**32:
         assert '__stdcall' in str(ffi.typeof(cb2))
         assert '__stdcall' not in str(ffi.typeof(cb1))
         py.test.raises(TypeError, lib.call1, cb2)
@@ -2412,7 +2412,7 @@
             return result;
         }
     """)
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and sys.maxsize < 2**32:
         py.test.raises(TypeError, lib.call1, lib.cb2)
         py.test.raises(TypeError, lib.call2, lib.cb1)
     pt = lib.call1(lib.cb1)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_realize_c_type.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_realize_c_type.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_realize_c_type.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_realize_c_type.py
@@ -54,7 +54,7 @@
     ffi = _cffi_backend.FFI()
     ct = ffi.typeof(ffi.callback(input, lambda: None))
     assert isinstance(ct, ffi.CType)
-    if sys.platform != 'win32':
+    if sys.platform != 'win32' or sys.maxsize > 2**32:
         expected_output = expected_output.replace('__stdcall *', '*')
     assert ct.cname == expected_output
 
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
@@ -22,7 +22,7 @@
     kwds.setdefault('undef_macros', ['NDEBUG'])
     module_name = '_CFFI_' + module_name
     ffi.set_source(module_name, source)
-    if 1:     # test the .cpp mode too
+    if not os.environ.get('NO_CPP'):     # test the .cpp mode too
         kwds.setdefault('source_extension', '.cpp')
         source = 'extern "C" {\n%s\n}' % (source,)
     else:
@@ -199,7 +199,7 @@
     vals = ['42', '-42', '0x80000000', '-2147483648',
             '0', '9223372036854775809ULL',
             '-9223372036854775807LL']
-    if sys.maxsize <= 2**32:
+    if sys.maxsize <= 2**32 or sys.platform == 'win32':
         vals.remove('-2147483648')
     ffi = FFI()
     cdef_lines = ['#define FOO_%d_%d %s' % (i, j, vals[i])
@@ -459,7 +459,7 @@
     ffi.cdef("typedef enum { AA=%d } e1;" % sys.maxsize)
     lib = verify(ffi, 'test_verify_anonymous_enum_with_typedef2',
                  "typedef enum { AA=%d } e1;" % sys.maxsize)
-    assert lib.AA == sys.maxsize
+    assert lib.AA == int(ffi.cast("long", sys.maxsize))
     assert ffi.sizeof("e1") == ffi.sizeof("long")
 
 def test_unique_types():
@@ -1321,7 +1321,7 @@
     res = lib.call2(cb2)
     assert res == -500*999*3
     assert res == ffi.addressof(lib, 'call2')(cb2)
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and not sys.maxsize > 2**32:
         assert '__stdcall' in str(ffi.typeof(cb2))
         assert '__stdcall' not in str(ffi.typeof(cb1))
         py.test.raises(TypeError, lib.call1, cb2)
@@ -1409,7 +1409,7 @@
     """)
     ptr_call1 = ffi.addressof(lib, 'call1')
     ptr_call2 = ffi.addressof(lib, 'call2')
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and not sys.maxsize > 2**32:
         py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2'))
         py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2'))
         py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1'))
@@ -1465,7 +1465,7 @@
     """)
     ptr_call1 = ffi.addressof(lib, 'call1')
     ptr_call2 = ffi.addressof(lib, 'call2')
-    if sys.platform == 'win32':
+    if sys.platform == 'win32' and not sys.maxsize > 2**32:
         py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2'))
         py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2'))
         py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1'))


More information about the pypy-commit mailing list