diff options
author | Thomas Heller <theller@ctypes.org> | 2008-09-24 19:00:21 +0000 |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-09-24 19:00:21 +0000 |
commit | 8e97ea9c6b079716c3400b51c6fd262329b68b96 (patch) | |
tree | 8c7f472fba85108eea03a0c01500eff26439d181 | |
parent | a7a94a0a21030998eda42140ccec3df00af14cd3 (diff) | |
download | cpython-git-8e97ea9c6b079716c3400b51c6fd262329b68b96.tar.gz |
Fix issue #3547: ctypes is confused by bitfields of varying integer types
Reviewed by Fredrik Lundh and Skip Montanaro.
Backport from trunk.
-rw-r--r-- | Lib/ctypes/test/test_bitfields.py | 15 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 2 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py index 2867cbf93e..ddd753ea09 100644 --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -215,6 +215,21 @@ class BitFieldTest(unittest.TestCase): ("b", c_ubyte, 4)] self.failUnlessEqual(sizeof(X), sizeof(c_byte)) + def test_mixed_4(self): + class X(Structure): + _fields_ = [("a", c_short, 4), + ("b", c_short, 4), + ("c", c_int, 24), + ("d", c_short, 4), + ("e", c_short, 4), + ("f", c_int, 24)] + # MS compilers do NOT combine c_short and c_int into + # one field, gcc does. + if os.name in ("nt", "ce"): + self.failUnlessEqual(sizeof(X), sizeof(c_int) * 4) + else: + self.failUnlessEqual(sizeof(X), sizeof(c_int) * 2) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): @@ -86,6 +86,9 @@ Core and builtins Library ------- +- Issue #3547: Fixed ctypes structures bitfields of varying integer + sizes. + - Issue #3762: platform.architecture() fails if python is lanched via its symbolic link. diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index d310ac5482..adf85971e4 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -163,7 +163,7 @@ CField_FromDesc(PyObject *desc, int index, break; case EXPAND_BITFIELD: - /* XXX needs more */ + *poffset += dict->size - *pfield_size/8; *psize += dict->size - *pfield_size/8; *pfield_size = dict->size * 8; |