5 static void cls_ret_complex_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
6 void* userdata __UNUSED__)
10 pa = (_Complex T_C_TYPE *)args[0];
11 pr = (_Complex T_C_TYPE *)resp;
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));
18 typedef _Complex T_C_TYPE (*cls_ret_complex)(_Complex T_C_TYPE);
24 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
25 ffi_type * cl_arg_types[2];
26 _Complex T_C_TYPE res;
28 cl_arg_types[0] = &T_FFI_TYPE;
29 cl_arg_types[1] = NULL;
31 /* Initialize the cif */
32 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
33 &T_FFI_TYPE, cl_arg_types) == FFI_OK);
35 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_complex_fn, NULL, code) == FFI_OK);
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));