1. Python CFFI
  2. Untitled project
  3. cffi

Commits

Armin Rigo  committed ca6d6a3

Raise a NotImplementedError in one messy corner case

  • Participants
  • Parent commits 7eb548f
  • Branches default

Comments (0)

Files changed (2)

File c/_cffi_backend.c

View file
  • Ignore whitespace
                     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;

File c/test_c.py

View file
  • Ignore whitespace
     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"