summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2019-06-12 17:58:26 +0200
committerArmin Rigo <arigo@tunes.org>2019-06-12 17:58:26 +0200
commitf50cf76eb836582beda30a0828151997896040dc (patch)
treee245b32770e743fdc44e96e7a2ccd3693e24984f /testing
parent7c94e003e06bdd32f9a7eaf013551ea0dcd45cdd (diff)
downloadcffi-f50cf76eb836582beda30a0828151997896040dc.tar.gz
Issue #412
Test and fix for unnamed bitfields which are not ":0" bitfields.
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi1/test_recompiler.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index d560d6a..741170b 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -2359,3 +2359,56 @@ def test_from_buffer_struct():
assert q[0].a == p.a
assert q[0].b == p.b
assert q == p
+
+def test_unnamed_bitfield_1():
+ ffi = FFI()
+ ffi.cdef("""struct A { char : 1; };""")
+ lib = verify(ffi, "test_unnamed_bitfield_1", """
+ struct A { char : 1; };
+ """)
+ p = ffi.new("struct A *")
+ assert ffi.sizeof(p[0]) == 1
+ # Note: on gcc, the type name is ignored for anonymous bitfields
+ # and that's why the result is 1. On MSVC, the result is
+ # sizeof("char") which is also 1.
+
+def test_unnamed_bitfield_2():
+ ffi = FFI()
+ ffi.cdef("""struct A {
+ short c : 1; short : 1; short d : 1; short : 1; };""")
+ lib = verify(ffi, "test_unnamed_bitfield_2", """
+ struct A {
+ short c : 1; short : 1; short d : 1; short : 1;
+ };
+ """)
+ p = ffi.new("struct A *")
+ assert ffi.sizeof(p[0]) == ffi.sizeof("short")
+
+def test_unnamed_bitfield_3():
+ ffi = FFI()
+ ffi.cdef("""struct A { struct { char : 1; char : 1; } b; };""")
+ lib = verify(ffi, "test_unnamed_bitfield_3", """
+ struct A { struct { char : 1; char : 1; } b; };
+ """)
+ p = ffi.new("struct A *")
+ assert ffi.sizeof(p[0]) == 1
+ # Note: on gcc, the type name is ignored for anonymous bitfields
+ # and that's why the result is 1. On MSVC, the result is
+ # sizeof("char") which is also 1.
+
+def test_unnamed_bitfield_4():
+ ffi = FFI()
+ ffi.cdef("""struct A { struct {
+ unsigned c : 1; unsigned : 1; unsigned d : 1; unsigned : 1; } a;
+ };
+ struct B { struct A a; };""")
+ lib = verify(ffi, "test_unnamed_bitfield_4", """
+ struct A { struct {
+ unsigned c : 1; unsigned : 1; unsigned d : 1; unsigned : 1; } a;
+ };
+ struct B { struct A a; };
+ """)
+ b = ffi.new("struct B *")
+ a = ffi.new("struct A *")
+ assert ffi.sizeof(a[0]) == ffi.sizeof("unsigned")
+ assert ffi.sizeof(b[0]) == ffi.sizeof(a[0])