[Python-checkins] r66611 - in python/trunk: Lib/ctypes/test/test_bitfields.py Misc/NEWS Modules/_ctypes/cfield.c

thomas.heller python-checkins at python.org
Wed Sep 24 20:26:05 CEST 2008


Author: thomas.heller
Date: Wed Sep 24 20:26:05 2008
New Revision: 66611

Log:
Fix issue #3547: ctypes is confused by bitfields of varying integer types

Reviewed by Fredrik Lundh and Skip Montanaro.

Modified:
   python/trunk/Lib/ctypes/test/test_bitfields.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/_ctypes/cfield.c

Modified: python/trunk/Lib/ctypes/test/test_bitfields.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_bitfields.py	(original)
+++ python/trunk/Lib/ctypes/test/test_bitfields.py	Wed Sep 24 20:26:05 2008
@@ -215,6 +215,21 @@
                         ("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):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Sep 24 20:26:05 2008
@@ -15,6 +15,9 @@
 Library
 -------
 
+- Issue #3547: Fixed ctypes structures bitfields of varying integer
+  sizes.
+
 - Issue #3879: A regression in urllib.getproxies_enviroment was fixed.
 
 Build

Modified: python/trunk/Modules/_ctypes/cfield.c
==============================================================================
--- python/trunk/Modules/_ctypes/cfield.c	(original)
+++ python/trunk/Modules/_ctypes/cfield.c	Wed Sep 24 20:26:05 2008
@@ -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;


More information about the Python-checkins mailing list