[Python-checkins] r54249 - in python/branches/release25-maint: Lib/ctypes Lib/ctypes/test/test_functions.py Misc/NEWS Modules/_ctypes Modules/_ctypes/_ctypes.c

thomas.heller python-checkins at python.org
Fri Mar 9 21:49:04 CET 2007


Author: thomas.heller
Date: Fri Mar  9 21:48:57 2007
New Revision: 54249

Modified:
   python/branches/release25-maint/Lib/ctypes/   (props changed)
   python/branches/release25-maint/Lib/ctypes/test/test_functions.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Modules/_ctypes/   (props changed)
   python/branches/release25-maint/Modules/_ctypes/_ctypes.c
Log:
Merged revisions 54248 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes

........
  r54248 | thomas.heller | 2007-03-09 21:39:22 +0100 (Fr, 09 Mär 2007) | 7 lines
  
  Bug #1651235: When a tuple was passed to a ctypes function call,
  Python would crash instead of raising an error.
  
  The crash was caused by a section of code that should have been
  removed long ago, at that time ctypes had other ways to pass
  parameters to function calls.
........


Modified: python/branches/release25-maint/Lib/ctypes/test/test_functions.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/test/test_functions.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/test/test_functions.py	Fri Mar  9 21:48:57 2007
@@ -21,7 +21,9 @@
 
 class POINT(Structure):
     _fields_ = [("x", c_int), ("y", c_int)]
-
+class RECT(Structure):
+    _fields_ = [("left", c_int), ("top", c_int),
+                ("right", c_int), ("bottom", c_int)]
 class FunctionTestCase(unittest.TestCase):
 
     def test_mro(self):
@@ -379,5 +381,15 @@
             self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
                                  (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
 
+    def test_sf1651235(self):
+        # see http://www.python.org/sf/1651235
+
+        proto = CFUNCTYPE(c_int, RECT, POINT)
+        def callback(*args):
+            return 0
+
+        callback = proto(callback)
+        self.failUnlessRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT()))
+
 if __name__ == '__main__':
     unittest.main()

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Mar  9 21:48:57 2007
@@ -196,6 +196,8 @@
 
 Library
 -------
+- Bug #1651235: When a tuple was passed to a ctypes function call,
+  Python would crash instead of raising an error.
 
 - Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0)
   returned string up to the first NUL character.

Modified: python/branches/release25-maint/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/_ctypes.c	Fri Mar  9 21:48:57 2007
@@ -339,24 +339,6 @@
 			     ((PyTypeObject *)type)->tp_name, ob_name);
 		return NULL;
 	}
-#if 1
-/* XXX Remove this section ??? */
-	/* tuple returned by byref: */
-	/* ('i', addr, obj) */
-	if (PyTuple_Check(value)) {
-		PyObject *ob;
-		StgDictObject *dict;
-
-		dict = PyType_stgdict(type);
-		ob = PyTuple_GetItem(value, 2);
-		if (dict && ob &&
-		    0 == PyObject_IsInstance(value, dict->proto)) {
-			Py_INCREF(value);
-			return value;
-		}
-	}
-/* ... and leave the rest */
-#endif
 
 	as_parameter = PyObject_GetAttrString(value, "_as_parameter_");
 	if (as_parameter) {


More information about the Python-checkins mailing list