summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-06-06 19:25:13 (GMT)
committerThomas Heller <theller@ctypes.org>2006-06-06 19:25:13 (GMT)
commitb1998bc860169c02a23fce874f538cf009d351de (patch)
treecccfc1ba947890813ce93e753a5892a87ab25438 /Modules
parentd8714dedfa9bf45ce11330c006c9479b418136f9 (diff)
downloadcpython-b1998bc860169c02a23fce874f538cf009d351de.zip
cpython-b1998bc860169c02a23fce874f538cf009d351de.tar.gz
cpython-b1998bc860169c02a23fce874f538cf009d351de.tar.bz2
Use the same big-endian hack as in _ctypes/callproc.c for callback functions.
This fixes the callback function tests that return float.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callbacks.c43
1 files changed, 7 insertions, 36 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 8c29c55..4baf3aa 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -199,45 +199,16 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
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.