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