[Pyobjc-dev] FFI problems
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@xs...> - 2003-03-07 08:20:32
|
It looks like I've run into a bug in libffi, or (more likely) I should dig for more documentation. The following program works fine when RETTYPE is int and crashes when RETTYPE is double. Problem is that this is how we use libffi in the bridge, the effect of this is that you cannot define methods that return anything other than id, char, short or int (and unsigned variants) at the moment. Luckily returning other types (double, long long, structs) is not that common in Cocoa. Ronald #include <ffi.h> #include <assert.h> #define RETTYPE double static void closure_test_fn4(ffi_cif* cif,void* resp,void** args, void* userdata) { *(RETTYPE*)resp = 42; } typedef RETTYPE (*closure_test_type4)(void); void doit(void) { ffi_cif cif; ffi_type* cl_arg_types[17]; static ffi_closure cl; double res; cl_arg_types[0] = NULL; /* Initialize the cif */ assert(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_sint, cl_arg_types) == FFI_OK); assert(ffi_prep_closure(&cl, &cif, closure_test_fn4, (void *) 3 /* userdata */) == FFI_OK); res = ((closure_test_type4)(&cl))(); printf("%f\n", res); } int main(void) { doit(); } |