summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2008-09-24 19:01:29 (GMT)
committerThomas Heller <theller@ctypes.org>2008-09-24 19:01:29 (GMT)
commit1308c26cf4cd930f3774cf6f35ae1e3c483d9718 (patch)
tree354b02c57db1e52cb33d07564e4063242ec930b7
parent05f5ab7ee39b16bdd7fda23b3276d52b8c2b4acb (diff)
downloadcpython-1308c26cf4cd930f3774cf6f35ae1e3c483d9718.zip
cpython-1308c26cf4cd930f3774cf6f35ae1e3c483d9718.tar.gz
cpython-1308c26cf4cd930f3774cf6f35ae1e3c483d9718.tar.bz2
Merged revisions 66611 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r66611 | thomas.heller | 2008-09-24 20:26:05 +0200 (Mi, 24 Sep 2008) | 3 lines Fix issue #3547: ctypes is confused by bitfields of varying integer types Reviewed by Fredrik Lundh and Skip Montanaro. ........
-rw-r--r--Lib/ctypes/test/test_bitfields.py15
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_ctypes/cfield.c2
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py
index c17ba3c..06c4023 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):
diff --git a/Misc/NEWS b/Misc/NEWS
index ac2dda8..1079960 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,9 @@ Library
- Bug #3884: Make the turtle module toplevel again.
+- Issue #3547: Fixed ctypes structures bitfields of varying integer
+ sizes.
+
Extension Modules
-----------------
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index beca018..9040dbb 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -159,7 +159,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t 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;