[Python-checkins] r51847 - in python/branches/release25-maint: Lib/ctypes/test/test_bitfields.py Modules/_ctypes/stgdict.c

neal.norwitz python-checkins at python.org
Mon Sep 11 06:01:58 CEST 2006


Author: neal.norwitz
Date: Mon Sep 11 06:01:57 2006
New Revision: 51847

Modified:
   python/branches/release25-maint/Lib/ctypes/test/test_bitfields.py
   python/branches/release25-maint/Modules/_ctypes/stgdict.c
Log:
Backport rev 51819 from Thomas Heller

Anonymous structure fields that have a bit-width specified did not work,
and they gave a strange error message from PyArg_ParseTuple:
   function takes exactly 2 arguments (3 given).


Modified: python/branches/release25-maint/Lib/ctypes/test/test_bitfields.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/test/test_bitfields.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/test/test_bitfields.py	Mon Sep 11 06:01:57 2006
@@ -215,5 +215,14 @@
                         ("b", c_ubyte, 4)]
         self.failUnlessEqual(sizeof(X), sizeof(c_byte))
 
+    def test_anon_bitfields(self):
+        # anonymous bit-fields gave a strange error message
+        class X(Structure):
+            _fields_ = [("a", c_byte, 4),
+                        ("b", c_ubyte, 4)]
+        class Y(Structure):
+            _anonymous_ = ["_"]
+            _fields_ = [("_", X)]
+
 if __name__ == "__main__":
     unittest.main()

Modified: python/branches/release25-maint/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/stgdict.c	Mon Sep 11 06:01:57 2006
@@ -177,11 +177,11 @@
 
 	for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) {
 		PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */
-		PyObject *fname, *ftype;
+		PyObject *fname, *ftype, *bits;
 		CFieldObject *fdescr;
 		CFieldObject *new_descr;
 		/* Convert to PyArg_UnpackTuple... */
-		if (!PyArg_ParseTuple(pair, "OO", &fname, &ftype)) {
+		if (!PyArg_ParseTuple(pair, "OO|O", &fname, &ftype, &bits)) {
 			Py_DECREF(fieldlist);
 			return -1;
 		}


More information about the Python-checkins mailing list