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)
This commit is contained in:
Thomas Heller 2006-08-16 15:10:12 +00:00
parent f9b5b8e9f8
commit b4a0cf17c4
4 changed files with 8 additions and 1 deletions

View File

@ -61,6 +61,7 @@ class BasicWrapTestCase(unittest.TestCase):
def callback(v): def callback(v):
args.append(v) args.append(v)
return v
CallBack = CFUNCTYPE(c_int, c_int) CallBack = CFUNCTYPE(c_int, c_int)

View File

@ -222,6 +222,7 @@ class FunctionTestCase(unittest.TestCase):
def callback(v): def callback(v):
args.append(v) args.append(v)
return v
CallBack = CFUNCTYPE(c_int, c_int) CallBack = CFUNCTYPE(c_int, c_int)

View File

@ -64,6 +64,11 @@ Core and builtins
Library 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 - The __repr__ method of a NULL ctypes.py_object() no longer raises
an exception. an exception.

View File

@ -205,7 +205,7 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
result = PyObject_CallObject(callable, arglist); result = PyObject_CallObject(callable, arglist);
CHECK("'calling callback function'", result); CHECK("'calling callback function'", result);
if ((restype != &ffi_type_void) && result && result != Py_None) { if ((restype != &ffi_type_void) && result) {
PyObject *keep; PyObject *keep;
assert(setfunc); assert(setfunc);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN