diff options
| author | Armin Rigo <arigo@tunes.org> | 2013-05-05 12:25:44 +0200 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2013-05-05 12:25:44 +0200 |
| commit | 820f67af48a8a5e994dd745af2cd5fad9b4e6a55 (patch) | |
| tree | d2a860816853257fe6f959a0f8341be235916283 /testing | |
| parent | ce447dd341ab7551c9f7a9afec51ee4ec20d0450 (diff) | |
| download | cffi-820f67af48a8a5e994dd745af2cd5fad9b4e6a55.tar.gz | |
Fix for enums used as bitfields. (thanks jerith)
Diffstat (limited to 'testing')
| -rw-r--r-- | testing/backend_tests.py | 10 | ||||
| -rw-r--r-- | testing/test_verify.py | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/testing/backend_tests.py b/testing/backend_tests.py index dd10adc..9f07d47 100644 --- a/testing/backend_tests.py +++ b/testing/backend_tests.py @@ -970,6 +970,16 @@ class BackendTests: s.c = -4 assert s.c == -4 + def test_bitfield_enum(self): + ffi = FFI(backend=self.Backend()) + ffi.cdef(""" + typedef enum { AA, BB, CC } foo_e; + typedef struct { foo_e f:2; } foo_s; + """) + s = ffi.new("foo_s *") + s.f = 2 + assert s.f == 2 + def test_anonymous_struct(self): ffi = FFI(backend=self.Backend()) ffi.cdef("typedef struct { int a; } foo_t;") diff --git a/testing/test_verify.py b/testing/test_verify.py index 72cb66e..712744e 100644 --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -521,6 +521,18 @@ def test_struct_with_bitfield_exact(): py.test.raises(OverflowError, "s.b = 4") assert s.b == 3 +def test_struct_with_bitfield_enum(): + ffi = FFI() + code = """ + typedef enum { AA, BB, CC } foo_e; + typedef struct { foo_e f:2; } foo_s; + """ + ffi.cdef(code) + ffi.verify(code) + s = ffi.new("foo_s *") + s.f = 2 + assert s.f == 2 + def test_unsupported_struct_with_bitfield_ellipsis(): ffi = FFI() py.test.raises(NotImplementedError, ffi.cdef, |
