[Python-checkins] r51320 - in python/trunk: Lib/ctypes/test/test_as_parameter.py Lib/ctypes/test/test_functions.py Misc/NEWS Modules/_ctypes/callbacks.c

thomas.heller python-checkins at python.org
Wed Aug 16 17:10:14 CEST 2006


Author: thomas.heller
Date: Wed Aug 16 17:10:12 2006
New Revision: 51320

Modified:
   python/trunk/Lib/ctypes/test/test_as_parameter.py
   python/trunk/Lib/ctypes/test/test_functions.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/_ctypes/callbacks.c
Log:
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C.  If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.

(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)


Modified: python/trunk/Lib/ctypes/test/test_as_parameter.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_as_parameter.py	(original)
+++ python/trunk/Lib/ctypes/test/test_as_parameter.py	Wed Aug 16 17:10:12 2006
@@ -61,6 +61,7 @@
 
         def callback(v):
             args.append(v)
+            return v
 
         CallBack = CFUNCTYPE(c_int, c_int)
 

Modified: python/trunk/Lib/ctypes/test/test_functions.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_functions.py	(original)
+++ python/trunk/Lib/ctypes/test/test_functions.py	Wed Aug 16 17:10:12 2006
@@ -222,6 +222,7 @@
 
         def callback(v):
             args.append(v)
+            return v
 
         CallBack = CFUNCTYPE(c_int, c_int)
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Aug 16 17:10:12 2006
@@ -64,6 +64,11 @@
 Library
 -------
 
+- If a the Python part of a ctypes callback function returns None,
+  and this cannot be converted to the required C type, an exception is
+  printed with PyErr_WriteUnraisable.  Before this change, the C
+  callback did return arbitrary values to the calling code.
+
 - The __repr__ method of a NULL ctypes.py_object() no longer raises
   an exception.
 

Modified: python/trunk/Modules/_ctypes/callbacks.c
==============================================================================
--- python/trunk/Modules/_ctypes/callbacks.c	(original)
+++ python/trunk/Modules/_ctypes/callbacks.c	Wed Aug 16 17:10:12 2006
@@ -205,7 +205,7 @@
 
 	result = PyObject_CallObject(callable, arglist);
 	CHECK("'calling callback function'", result);
-	if ((restype != &ffi_type_void) && result && result != Py_None) {
+	if ((restype != &ffi_type_void) && result) {
 		PyObject *keep;
 		assert(setfunc);
 #ifdef WORDS_BIGENDIAN


More information about the Python-checkins mailing list