Author: Armin Rigo <[email protected]>
Branch:
Changeset: r900:6bb8f88697fe
Date: 2012-08-27 21:57 +0200
http://bitbucket.org/cffi/cffi/changeset/6bb8f88697fe/
Log: Bug with sizeof(union) (thanks paniq on issue #25)
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2039,3 +2039,21 @@
assert d[2][1].offset == sizeof(BInt) * 2
assert d[2][1].bitshift == -1
assert d[2][1].bitsize == -1
+
+def test_sizeof_union():
+ # a union has the largest alignment of its members, and a total size
+ # that is the largest of its items *possibly further aligned* if
+ # another smaller item has a larger alignment...
+ BChar = new_primitive_type("char")
+ BShort = new_primitive_type("short")
+ assert sizeof(BShort) == alignof(BShort) == 2
+ BStruct = new_struct_type("foo")
+ complete_struct_or_union(BStruct, [('a1', BChar),
+ ('a2', BChar),
+ ('a3', BChar)])
+ assert sizeof(BStruct) == 3 and alignof(BStruct) == 1
+ BUnion = new_union_type("u")
+ complete_struct_or_union(BUnion, [('s', BStruct),
+ ('i', BShort)])
+ assert sizeof(BUnion) == 4
+ assert alignof(BUnion) == 2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit