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 f; |
---|
12 | n/a | double d; |
---|
13 | n/a | } test_structure_6; |
---|
14 | n/a | |
---|
15 | n/a | static test_structure_6 ABI_ATTR struct6 (test_structure_6 ts) |
---|
16 | n/a | { |
---|
17 | n/a | ts.f += 1; |
---|
18 | n/a | ts.d += 1; |
---|
19 | n/a | |
---|
20 | n/a | return ts; |
---|
21 | n/a | } |
---|
22 | n/a | |
---|
23 | n/a | int main (void) |
---|
24 | n/a | { |
---|
25 | n/a | ffi_cif cif; |
---|
26 | n/a | ffi_type *args[MAX_ARGS]; |
---|
27 | n/a | void *values[MAX_ARGS]; |
---|
28 | n/a | ffi_type ts6_type; |
---|
29 | n/a | ffi_type *ts6_type_elements[3]; |
---|
30 | n/a | |
---|
31 | n/a | test_structure_6 ts6_arg; |
---|
32 | n/a | |
---|
33 | n/a | /* This is a hack to get a properly aligned result buffer */ |
---|
34 | n/a | test_structure_6 *ts6_result = |
---|
35 | n/a | (test_structure_6 *) malloc (sizeof(test_structure_6)); |
---|
36 | n/a | |
---|
37 | n/a | ts6_type.size = 0; |
---|
38 | n/a | ts6_type.alignment = 0; |
---|
39 | n/a | ts6_type.type = FFI_TYPE_STRUCT; |
---|
40 | n/a | ts6_type.elements = ts6_type_elements; |
---|
41 | n/a | ts6_type_elements[0] = &ffi_type_float; |
---|
42 | n/a | ts6_type_elements[1] = &ffi_type_double; |
---|
43 | n/a | ts6_type_elements[2] = NULL; |
---|
44 | n/a | |
---|
45 | n/a | args[0] = &ts6_type; |
---|
46 | n/a | values[0] = &ts6_arg; |
---|
47 | n/a | |
---|
48 | n/a | /* Initialize the cif */ |
---|
49 | n/a | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts6_type, args) == FFI_OK); |
---|
50 | n/a | |
---|
51 | n/a | ts6_arg.f = 5.55f; |
---|
52 | n/a | ts6_arg.d = 6.66; |
---|
53 | n/a | |
---|
54 | n/a | printf ("%g\n", ts6_arg.f); |
---|
55 | n/a | printf ("%g\n", ts6_arg.d); |
---|
56 | n/a | |
---|
57 | n/a | ffi_call(&cif, FFI_FN(struct6), ts6_result, values); |
---|
58 | n/a | |
---|
59 | n/a | CHECK(ts6_result->f == 5.55f + 1); |
---|
60 | n/a | CHECK(ts6_result->d == 6.66 + 1); |
---|
61 | n/a | |
---|
62 | n/a | free (ts6_result); |
---|
63 | n/a | exit(0); |
---|
64 | n/a | } |
---|