1 | n/a | /* Area: ffi_call |
---|
2 | n/a | Purpose: Check structures. |
---|
3 | n/a | Limitations: none. |
---|
4 | n/a | PR: none. |
---|
5 | n/a | Originator: From the original ffitest.c */ |
---|
6 | n/a | |
---|
7 | n/a | /* { dg-do run } */ |
---|
8 | n/a | #include "ffitest.h" |
---|
9 | n/a | typedef struct |
---|
10 | n/a | { |
---|
11 | n/a | float f1; |
---|
12 | n/a | float f2; |
---|
13 | n/a | double d; |
---|
14 | n/a | } test_structure_7; |
---|
15 | n/a | |
---|
16 | n/a | static test_structure_7 ABI_ATTR struct7 (test_structure_7 ts) |
---|
17 | n/a | { |
---|
18 | n/a | ts.f1 += 1; |
---|
19 | n/a | ts.f2 += 1; |
---|
20 | n/a | ts.d += 1; |
---|
21 | n/a | |
---|
22 | n/a | return ts; |
---|
23 | n/a | } |
---|
24 | n/a | |
---|
25 | n/a | int main (void) |
---|
26 | n/a | { |
---|
27 | n/a | ffi_cif cif; |
---|
28 | n/a | ffi_type *args[MAX_ARGS]; |
---|
29 | n/a | void *values[MAX_ARGS]; |
---|
30 | n/a | ffi_type ts7_type; |
---|
31 | n/a | ffi_type *ts7_type_elements[4]; |
---|
32 | n/a | |
---|
33 | n/a | test_structure_7 ts7_arg; |
---|
34 | n/a | |
---|
35 | n/a | /* This is a hack to get a properly aligned result buffer */ |
---|
36 | n/a | test_structure_7 *ts7_result = |
---|
37 | n/a | (test_structure_7 *) malloc (sizeof(test_structure_7)); |
---|
38 | n/a | |
---|
39 | n/a | ts7_type.size = 0; |
---|
40 | n/a | ts7_type.alignment = 0; |
---|
41 | n/a | ts7_type.type = FFI_TYPE_STRUCT; |
---|
42 | n/a | ts7_type.elements = ts7_type_elements; |
---|
43 | n/a | ts7_type_elements[0] = &ffi_type_float; |
---|
44 | n/a | ts7_type_elements[1] = &ffi_type_float; |
---|
45 | n/a | ts7_type_elements[2] = &ffi_type_double; |
---|
46 | n/a | ts7_type_elements[3] = NULL; |
---|
47 | n/a | |
---|
48 | n/a | args[0] = &ts7_type; |
---|
49 | n/a | values[0] = &ts7_arg; |
---|
50 | n/a | |
---|
51 | n/a | /* Initialize the cif */ |
---|
52 | n/a | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts7_type, args) == FFI_OK); |
---|
53 | n/a | |
---|
54 | n/a | ts7_arg.f1 = 5.55f; |
---|
55 | n/a | ts7_arg.f2 = 55.5f; |
---|
56 | n/a | ts7_arg.d = 6.66; |
---|
57 | n/a | |
---|
58 | n/a | printf ("%g\n", ts7_arg.f1); |
---|
59 | n/a | printf ("%g\n", ts7_arg.f2); |
---|
60 | n/a | printf ("%g\n", ts7_arg.d); |
---|
61 | n/a | |
---|
62 | n/a | ffi_call(&cif, FFI_FN(struct7), ts7_result, values); |
---|
63 | n/a | |
---|
64 | n/a | printf ("%g\n", ts7_result->f1); |
---|
65 | n/a | printf ("%g\n", ts7_result->f2); |
---|
66 | n/a | printf ("%g\n", ts7_result->d); |
---|
67 | n/a | |
---|
68 | n/a | CHECK(ts7_result->f1 == 5.55f + 1); |
---|
69 | n/a | CHECK(ts7_result->f2 == 55.5f + 1); |
---|
70 | n/a | CHECK(ts7_result->d == 6.66 + 1); |
---|
71 | n/a | |
---|
72 | n/a | free (ts7_result); |
---|
73 | n/a | exit(0); |
---|
74 | n/a | } |
---|