summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-09-06 23:04:42 +0000
committerDamien George <damien.p.george@gmail.com>2014-09-06 23:04:42 +0000
commit91fe0d4880b2abde25050d2b626320003f130e83 (patch)
tree29fa1ff368430cb05ae1216c827de0f18d01fba7
parent03281b3850698310acd2c3445786b70babafe43a (diff)
downloadmicropython-91fe0d4880b2abde25050d2b626320003f130e83.tar.gz
micropython-91fe0d4880b2abde25050d2b626320003f130e83.zip
unix: Fix modffi to be able to return double on x86 machines.
-rw-r--r--unix/modffi.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/unix/modffi.c b/unix/modffi.c
index e019e9fc95..03b76e643b 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -334,9 +334,19 @@ mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
valueptrs[i] = &values[i];
}
- ffi_arg retval;
- ffi_call(&self->cif, self->func, &retval, valueptrs);
- return return_ffi_value(retval, self->rettype);
+ // If ffi_arg is not big enough to hold a double, then we must pass along a
+ // pointer to a memory location of the correct size.
+ // TODO check if this needs to be done for other types which don't fit into
+ // ffi_arg.
+ if (sizeof(ffi_arg) == 4 && self->rettype == 'd') {
+ double retval;
+ ffi_call(&self->cif, self->func, &retval, valueptrs);
+ return mp_obj_new_float(retval);
+ } else {
+ ffi_arg retval;
+ ffi_call(&self->cif, self->func, &retval, valueptrs);
+ return return_ffi_value(retval, self->rettype);
+ }
error:
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Don't know how to pass object to native function"));