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 | char c1; |
---|
12 | n/a | char c2; |
---|
13 | n/a | } test_structure_5; |
---|
14 | n/a | |
---|
15 | n/a | static test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2) |
---|
16 | n/a | { |
---|
17 | n/a | ts1.c1 += ts2.c1; |
---|
18 | n/a | ts1.c2 -= ts2.c2; |
---|
19 | n/a | |
---|
20 | n/a | return ts1; |
---|
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 ts5_type; |
---|
29 | n/a | ffi_type *ts5_type_elements[3]; |
---|
30 | n/a | |
---|
31 | n/a | test_structure_5 ts5_arg1, ts5_arg2; |
---|
32 | n/a | |
---|
33 | n/a | /* This is a hack to get a properly aligned result buffer */ |
---|
34 | n/a | test_structure_5 *ts5_result = |
---|
35 | n/a | (test_structure_5 *) malloc (sizeof(test_structure_5)); |
---|
36 | n/a | |
---|
37 | n/a | ts5_type.size = 0; |
---|
38 | n/a | ts5_type.alignment = 0; |
---|
39 | n/a | ts5_type.type = FFI_TYPE_STRUCT; |
---|
40 | n/a | ts5_type.elements = ts5_type_elements; |
---|
41 | n/a | ts5_type_elements[0] = &ffi_type_schar; |
---|
42 | n/a | ts5_type_elements[1] = &ffi_type_schar; |
---|
43 | n/a | ts5_type_elements[2] = NULL; |
---|
44 | n/a | |
---|
45 | n/a | args[0] = &ts5_type; |
---|
46 | n/a | args[1] = &ts5_type; |
---|
47 | n/a | values[0] = &ts5_arg1; |
---|
48 | n/a | values[1] = &ts5_arg2; |
---|
49 | n/a | |
---|
50 | n/a | /* Initialize the cif */ |
---|
51 | n/a | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK); |
---|
52 | n/a | |
---|
53 | n/a | ts5_arg1.c1 = 2; |
---|
54 | n/a | ts5_arg1.c2 = 6; |
---|
55 | n/a | ts5_arg2.c1 = 5; |
---|
56 | n/a | ts5_arg2.c2 = 3; |
---|
57 | n/a | |
---|
58 | n/a | ffi_call (&cif, FFI_FN(struct5), ts5_result, values); |
---|
59 | n/a | |
---|
60 | n/a | CHECK(ts5_result->c1 == 7); |
---|
61 | n/a | CHECK(ts5_result->c2 == 3); |
---|
62 | n/a | |
---|
63 | n/a | |
---|
64 | n/a | free (ts5_result); |
---|
65 | n/a | exit(0); |
---|
66 | n/a | } |
---|