Commit b4a0cf17 authored by Thomas Heller's avatar Thomas Heller

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)
parent f9b5b8e9
...@@ -61,6 +61,7 @@ class BasicWrapTestCase(unittest.TestCase): ...@@ -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)
......
...@@ -222,6 +222,7 @@ class FunctionTestCase(unittest.TestCase): ...@@ -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)
......
...@@ -64,6 +64,11 @@ Core and builtins ...@@ -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.
......
...@@ -205,7 +205,7 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print() ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment