Author: Armin Rigo <[email protected]>
Branch:
Changeset: r886:4208a40e9af3
Date: 2012-08-23 17:47 +0200
http://bitbucket.org/cffi/cffi/changeset/4208a40e9af3/
Log: merge heads
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -396,6 +396,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
@@ -386,7 +386,8 @@
prnt(' static Py_ssize_t nums[] = {')
prnt(' sizeof(%s),' % cname)
prnt(' offsetof(struct _cffi_aligncheck, y),')
- for fname, _, _ in tp.enumfields():
+ for fname, _, fbitsize in tp.enumfields():
+ assert fbitsize < 0
prnt(' offsetof(%s, %s),' % (cname, fname))
prnt(' sizeof(((%s *)0)->%s),' % (cname, fname))
prnt(' -1')
@@ -399,7 +400,9 @@
'sizeof(%s) != %d' % (cname, ffi.sizeof(BStruct)),
'offsetof(struct _cffi_aligncheck, y) != %d' % (
ffi.alignof(BStruct),)]
- for fname, ftype, _ in tp.enumfields():
+ for fname, ftype, fbitsize in tp.enumfields():
+ 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
@@ -387,6 +387,20 @@
s = ffi.new("struct foo_s *")
assert ffi.sizeof(s.a) == 17 * ffi.sizeof('int')
+def test_struct_with_bitfield_exact():
+ ffi = FFI()
+ ffi.cdef("struct foo_s { int a:2, b:3; };")
+ ffi.verify("struct foo_s { int a:2, b:3; };")
+ s = ffi.new("struct foo_s *")
+ s.b = 3
+ 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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit