Mercurial > cpython-lru_cache-weakref
diff Modules/_ctypes/callbacks.c @ 38634:7bfafdeffee2 legacy-trunk
Use the same big-endian hack as in _ctypes/callproc.c for callback functions.
This fixes the callback function tests that return float.
| author | Thomas Heller <theller@ctypes.org> |
|---|---|
| date | Tue, 06 Jun 2006 19:25:13 +0000 |
| parents | dd4156c36703 |
| children | 381a72ab5fb8 |
line wrap: on
line diff
--- a/Modules/_ctypes/callbacks.c Tue Jun 06 18:50:46 2006 +0000 +++ b/Modules/_ctypes/callbacks.c Tue Jun 06 19:25:13 2006 +0000 @@ -199,45 +199,16 @@ result = PyObject_CallObject(callable, arglist); CHECK("'calling callback function'", result); - if ((restype != &ffi_type_void) - && 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; + if ((restype != &ffi_type_void) && result && result != Py_None) { PyObject *keep; assert(setfunc); - switch (restype->size) { - case 1: - keep = setfunc(&r, result, 0); - CHECK("'converting callback result'", keep); - *(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; +#ifdef WORDS_BIGENDIAN + /* See the corresponding code in callproc.c, around line 961 */ + if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) + mem = (char *)mem + sizeof(ffi_arg) - restype->size; #endif - default: - keep = setfunc(mem, result, 0); - CHECK("'converting callback result'", keep); - break; - } + keep = setfunc(mem, result, 0); + CHECK("'converting callback result'", keep); /* keep is an object we have to keep alive so that the result stays valid. If there is no such object, the setfunc will have returned Py_None.
