summaryrefslogtreecommitdiffstatshomepage
path: root/unix/modffi.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-08 15:41:11 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-08 15:41:11 +0000
commit115187f7ceb11b0cb0b77fd98ee3c5be5d03b6f5 (patch)
treec25ab894965dec1a79743d5d3f3104d98f32a3ff /unix/modffi.c
parentafd6c8e1d2a2c24595194879481987cec3b57f8a (diff)
downloadmicropython-115187f7ceb11b0cb0b77fd98ee3c5be5d03b6f5.tar.gz
micropython-115187f7ceb11b0cb0b77fd98ee3c5be5d03b6f5.zip
unix: Allow to compile with float support disabled.
Diffstat (limited to 'unix/modffi.c')
-rw-r--r--unix/modffi.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/unix/modffi.c b/unix/modffi.c
index e0f2f3f27f..fb0c820d2a 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -106,8 +106,10 @@ STATIC ffi_type *char2ffi_type(char c)
case 'I': return &ffi_type_uint;
case 'l': return &ffi_type_slong;
case 'L': return &ffi_type_ulong;
+ #if MICROPY_PY_BUILTINS_FLOAT
case 'f': return &ffi_type_float;
case 'd': return &ffi_type_double;
+ #endif
case 'C': // (*)()
case 'P': // const void*
case 'p': // void*
@@ -141,6 +143,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
}
case 'v':
return mp_const_none;
+ #if MICROPY_PY_BUILTINS_FLOAT
case 'f': {
union { ffi_arg ffi; float flt; } val_union = { .ffi = val };
return mp_obj_new_float(val_union.flt);
@@ -149,6 +152,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
double *p = (double*)&val;
return mp_obj_new_float(*p);
}
+ #endif
default:
return mp_obj_new_int(val);
}
@@ -336,11 +340,14 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
// 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 MICROPY_PY_BUILTINS_FLOAT
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 {
+ } else
+ #endif
+ {
ffi_arg retval;
ffi_call(&self->cif, self->func, &retval, valueptrs);
return return_ffi_value(retval, self->rettype);