Index: Lib/ctypes/test/test_bitfields.py =================================================================== --- Lib/ctypes/test/test_bitfields.py (revision 66506) +++ Lib/ctypes/test/test_bitfields.py (working copy) @@ -215,6 +215,16 @@ ("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)] + self.failUnlessEqual(sizeof(X), sizeof(c_int) * 2) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 66506) +++ Misc/NEWS (working copy) @@ -15,6 +15,8 @@ Library ------- +- Issue #3547: Fixed ctypes structures bitfields of varying integer + sizes. What's New in Python 2.6 release candidate 2? ============================================= Index: Modules/_ctypes/cfield.c =================================================================== --- Modules/_ctypes/cfield.c (revision 66506) +++ Modules/_ctypes/cfield.c (working copy) @@ -163,7 +163,7 @@ break; case EXPAND_BITFIELD: - /* XXX needs more */ + *poffset += dict->size - *pfield_size/8; *psize += dict->size - *pfield_size/8; *pfield_size = dict->size * 8;