Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r57116:282cd24306f0
Date: 2012-09-04 12:11 +0200
http://bitbucket.org/pypy/pypy/changeset/282cd24306f0/

Log:    Port the fix cffi/cffi a7550e27bbc4.

diff --git a/pypy/module/_cffi_backend/newtype.py 
b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -211,12 +211,12 @@
     if is_union:
         assert offset == 0
         offset = maxsize
-    offset = (offset + alignment - 1) & ~(alignment-1)
 
     # Like C, if the size of this structure would be zero, we compute it
     # as 1 instead.  But for ctypes support, we allow the manually-
     # specified totalsize to be zero in this case.
     if totalsize < 0:
+        offset = (offset + alignment - 1) & ~(alignment-1)
         totalsize = offset or 1
     elif totalsize < offset:
         raise operationerrfmt(space.w_TypeError,
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2057,3 +2057,9 @@
                                       ('i', BShort)])
     assert sizeof(BUnion) == 4
     assert alignof(BUnion) == 2
+
+def test_unaligned_struct():
+    BInt = new_primitive_type("int")
+    BStruct = new_struct_type("foo")
+    complete_struct_or_union(BStruct, [('b', BInt, -1, 1)],
+                             None, 5, 1)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to