Commit b1998bc8 authored by Thomas Heller's avatar Thomas Heller

Use the same big-endian hack as in _ctypes/callproc.c for callback functions.

This fixes the callback function tests that return float.
parent d8714ded
...@@ -199,45 +199,16 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print() ...@@ -199,45 +199,16 @@ 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) if ((restype != &ffi_type_void) && result && result != Py_None) {
&& result && result != Py_None) { /* XXX What is returned for Py_None ? */
/* another big endian hack */
union {
char c;
short s;
int i;
long l;
} r;
PyObject *keep; PyObject *keep;
assert(setfunc); assert(setfunc);
switch (restype->size) { #ifdef WORDS_BIGENDIAN
case 1: /* See the corresponding code in callproc.c, around line 961 */
keep = setfunc(&r, result, 0); if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg))
CHECK("'converting callback result'", keep); mem = (char *)mem + sizeof(ffi_arg) - restype->size;
*(ffi_arg *)mem = r.c;
break;
case SIZEOF_SHORT:
keep = setfunc(&r, result, 0);
CHECK("'converting callback result'", keep);
*(ffi_arg *)mem = r.s;
break;
case SIZEOF_INT:
keep = setfunc(&r, result, 0);
CHECK("'converting callback result'", keep);
*(ffi_arg *)mem = r.i;
break;
#if (SIZEOF_LONG != SIZEOF_INT)
case SIZEOF_LONG:
keep = setfunc(&r, result, 0);
CHECK("'converting callback result'", keep);
*(ffi_arg *)mem = r.l;
break;
#endif #endif
default: keep = setfunc(mem, result, 0);
keep = setfunc(mem, result, 0); CHECK("'converting callback result'", keep);
CHECK("'converting callback result'", keep);
break;
}
/* keep is an object we have to keep alive so that the result /* keep is an object we have to keep alive so that the result
stays valid. If there is no such object, the setfunc will stays valid. If there is no such object, the setfunc will
have returned Py_None. have returned Py_None.
......
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