[pypy-commit] cffi default: Raise a NotImplementedError in one messy corner case
arigo
noreply at buildbot.pypy.org
Mon Jan 20 15:19:11 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1457:ca6d6a337335
Date: 2014-01-20 15:18 +0100
http://bitbucket.org/cffi/cffi/changeset/ca6d6a337335/
Log: Raise a NotImplementedError in one messy corner case
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3817,6 +3817,14 @@
if (bits_already_occupied + fbitsize > 8 * ftype->ct_size) {
/* it would not fit, we need to start at the next
allowed position */
+ if ((sflags & SF_PACKED) &&
+ (bits_already_occupied & 7)) {
+ PyErr_Format(PyExc_NotImplementedError,
+ "with 'packed', gcc would compile field "
+ "'%s.%s' to reuse some bits in the previous "
+ "field", ct->ct_name, PyText_AS_UTF8(fname));
+ goto error;
+ }
field_offset_bytes += falign;
assert(boffset < field_offset_bytes * 8);
boffset = field_offset_bytes * 8;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3177,6 +3177,16 @@
assert sizeof(BStruct) == sizeof(BLong) + sizeof(BChar) + sizeof(BShort)
assert alignof(BStruct) == 1
+def test_packed_with_bitfields():
+ BLong = new_primitive_type("long")
+ BChar = new_primitive_type("char")
+ BStruct = new_struct_type("struct foo")
+ py.test.raises(NotImplementedError,
+ complete_struct_or_union,
+ BStruct, [('a1', BLong, 30),
+ ('a2', BChar, 5)],
+ None, -1, -1, 8) # SF_PACKED==8
+
def test_version():
# this test is here mostly for PyPy
assert __version__ == "0.8"
More information about the pypy-commit
mailing list