[pypy-commit] cffi default: Fix.

arigo noreply at buildbot.pypy.org
Thu Aug 23 17:45:40 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r882:1f90b6973510
Date: 2012-08-23 17:45 +0200
http://bitbucket.org/cffi/cffi/changeset/1f90b6973510/

Log:	Fix.

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -390,6 +390,10 @@
         tp.fldnames = tuple(fldnames)
         tp.fldtypes = tuple(fldtypes)
         tp.fldbitsize = tuple(fldbitsize)
+        if fldbitsize != [-1] * len(fldbitsize):
+            if isinstance(tp, model.StructType) and tp.partial:
+                raise NotImplementedError("%s: using both bitfields and '...;'"
+                                          % (tp,))
         return tp
 
     def _make_partial(self, tp):
diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py
--- a/cffi/vengine_cpy.py
+++ b/cffi/vengine_cpy.py
@@ -388,7 +388,8 @@
             prnt('  static Py_ssize_t nums[] = {')
             prnt('    sizeof(%s),' % cname)
             prnt('    offsetof(struct _cffi_aligncheck, y),')
-            for fname in tp.fldnames:
+            for fname, fbitsize in zip(tp.fldnames, tp.fldbitsize):
+                assert fbitsize < 0
                 prnt('    offsetof(%s, %s),' % (cname, fname))
                 prnt('    sizeof(((%s *)0)->%s),' % (cname, fname))
             prnt('    -1')
@@ -401,7 +402,10 @@
                 'sizeof(%s) != %d' % (cname, ffi.sizeof(BStruct)),
                 'offsetof(struct _cffi_aligncheck, y) != %d' % (
                     ffi.alignof(BStruct),)]
-            for fname, ftype in zip(tp.fldnames, tp.fldtypes):
+            for fname, ftype, fbitsize in zip(tp.fldnames, tp.fldtypes,
+                                              tp.fldbitsize):
+                if fbitsize >= 0:
+                    continue        # xxx ignore fbitsize for now
                 BField = ffi._get_cached_btype(ftype)
                 conditions += [
                     'offsetof(%s, %s) != %d' % (
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -208,7 +208,8 @@
             prnt('  static ssize_t nums[] = {')
             prnt('    1, sizeof(%s),' % cname)
             prnt('    offsetof(struct _cffi_aligncheck, y),')
-            for fname in tp.fldnames:
+            for fname, fbitsize in zip(tp.fldnames, tp.fldbitsize):
+                assert fbitsize < 0
                 prnt('    offsetof(%s, %s),' % (cname, fname))
                 prnt('    sizeof(((%s *)0)->%s),' % (cname, fname))
             prnt('    -1')
@@ -221,7 +222,10 @@
                 'sizeof(%s) != %d' % (cname, ffi.sizeof(BStruct)),
                 'offsetof(struct _cffi_aligncheck, y) != %d' % (
                     ffi.alignof(BStruct),)]
-            for fname, ftype in zip(tp.fldnames, tp.fldtypes):
+            for fname, ftype, fbitsize in zip(tp.fldnames, tp.fldtypes,
+                                              tp.fldbitsize):
+                if fbitsize >= 0:
+                    continue        # xxx ignore fbitsize for now
                 BField = ffi._get_cached_btype(ftype)
                 conditions += [
                     'offsetof(%s, %s) != %d' % (
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -396,6 +396,11 @@
     py.test.raises(OverflowError, "s.b = 4")
     assert s.b == 3
 
+def test_unsupported_struct_with_bitfield_ellipsis():
+    ffi = FFI()
+    py.test.raises(NotImplementedError, ffi.cdef,
+                   "struct foo_s { int a:2, b:3; ...; };")
+
 def test_global_constants():
     ffi = FFI()
     # use 'static const int', as generally documented, although in this


More information about the pypy-commit mailing list