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

neal.norwitz python-checkins at python.org
Mon Sep 11 06:02:44 CEST 2006


Author: neal.norwitz
Date: Mon Sep 11 06:02:43 2006
New Revision: 51848

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

The cast function did not accept c_char_p or c_wchar_p instances
as first argument, and failed with a 'bad argument to internal function'
error message.


Modified: python/branches/release25-maint/Lib/ctypes/test/test_cast.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/test/test_cast.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/test/test_cast.py	Mon Sep 11 06:02:43 2006
@@ -57,5 +57,21 @@
         c_int()
         self.failUnlessEqual(p[:4], [1, 2, 96, 4])
 
+    def test_char_p(self):
+        # This didn't work: bad argument to internal function
+        s = c_char_p("hiho")
+        self.failUnlessEqual(cast(cast(s, c_void_p), c_char_p).value,
+                             "hiho")
+
+    try:
+        c_wchar_p
+    except NameError:
+        pass
+    else:
+        def test_wchar_p(self):
+            s = c_wchar_p("hiho")
+            self.failUnlessEqual(cast(cast(s, c_void_p), c_wchar_p).value,
+                                 "hiho")
+
 if __name__ == "__main__":
     unittest.main()

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	Mon Sep 11 06:02:43 2006
@@ -4590,11 +4590,11 @@
 			if (obj->b_objects == NULL)
 				goto failed;
 		}
+		Py_XINCREF(obj->b_objects);
 		result->b_objects = obj->b_objects;
-		if (result->b_objects) {
+		if (result->b_objects && PyDict_Check(result->b_objects)) {
 			PyObject *index;
 			int rc;
-			Py_INCREF(obj->b_objects);
 			index = PyLong_FromVoidPtr((void *)src);
 			if (index == NULL)
 				goto failed;


More information about the Python-checkins mailing list