annotate libffi/testsuite/libffi.complex/cls_complex.inc @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* -*-c-*- */
kono
parents:
diff changeset
2 #include "ffitest.h"
kono
parents:
diff changeset
3 #include <complex.h>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 static void cls_ret_complex_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
kono
parents:
diff changeset
6 void* userdata __UNUSED__)
kono
parents:
diff changeset
7 {
kono
parents:
diff changeset
8 _Complex T_C_TYPE *pa;
kono
parents:
diff changeset
9 _Complex T_C_TYPE *pr;
kono
parents:
diff changeset
10 pa = (_Complex T_C_TYPE *)args[0];
kono
parents:
diff changeset
11 pr = (_Complex T_C_TYPE *)resp;
kono
parents:
diff changeset
12 *pr = *pa;
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 printf("%.6f,%.6fi: %.6f,%.6fi\n",
kono
parents:
diff changeset
15 T_CONV creal (*pa), T_CONV cimag (*pa),
kono
parents:
diff changeset
16 T_CONV creal (*pr), T_CONV cimag (*pr));
kono
parents:
diff changeset
17 }
kono
parents:
diff changeset
18 typedef _Complex T_C_TYPE (*cls_ret_complex)(_Complex T_C_TYPE);
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 int main (void)
kono
parents:
diff changeset
21 {
kono
parents:
diff changeset
22 ffi_cif cif;
kono
parents:
diff changeset
23 void *code;
kono
parents:
diff changeset
24 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
kono
parents:
diff changeset
25 ffi_type * cl_arg_types[2];
kono
parents:
diff changeset
26 _Complex T_C_TYPE res;
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 cl_arg_types[0] = &T_FFI_TYPE;
kono
parents:
diff changeset
29 cl_arg_types[1] = NULL;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 /* Initialize the cif */
kono
parents:
diff changeset
32 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
kono
parents:
diff changeset
33 &T_FFI_TYPE, cl_arg_types) == FFI_OK);
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_complex_fn, NULL, code) == FFI_OK);
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 res = (*((cls_ret_complex)code))(0.125 + 128.0 * I);
kono
parents:
diff changeset
38 printf("res: %.6f,%.6fi\n", T_CONV creal (res), T_CONV cimag (res));
kono
parents:
diff changeset
39 CHECK (res == (0.125 + 128.0 * I));
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 exit(0);
kono
parents:
diff changeset
42 }