1/* -*-c-*- */ 2#include "ffitest.h" 3#include <complex.h> 4 5static void cls_ret_complex_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 6 void* userdata __UNUSED__) 7 { 8 _Complex T_C_TYPE *pa; 9 _Complex T_C_TYPE *pr; 10 pa = (_Complex T_C_TYPE *)args[0]; 11 pr = (_Complex T_C_TYPE *)resp; 12 *pr = *pa; 13 14 printf("%.6f,%.6fi: %.6f,%.6fi\n", 15 T_CONV creal (*pa), T_CONV cimag (*pa), 16 T_CONV creal (*pr), T_CONV cimag (*pr)); 17 } 18typedef _Complex T_C_TYPE (*cls_ret_complex)(_Complex T_C_TYPE); 19 20int main (void) 21{ 22 ffi_cif cif; 23 void *code; 24 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 25 ffi_type * cl_arg_types[2]; 26 _Complex T_C_TYPE res; 27 28 cl_arg_types[0] = &T_FFI_TYPE; 29 cl_arg_types[1] = NULL; 30 31 /* Initialize the cif */ 32 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 &T_FFI_TYPE, cl_arg_types) == FFI_OK); 34 35 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_complex_fn, NULL, code) == FFI_OK); 36 37 res = (*((cls_ret_complex)code))(0.125 + 128.0 * I); 38 printf("res: %.6f,%.6fi\n", T_CONV creal (res), T_CONV cimag (res)); 39 CHECK (res == (0.125 + 128.0 * I)); 40 41 exit(0); 42} 43