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 | int si; |
---|
13 | n/a | } test_structure_3; |
---|
14 | n/a | |
---|
15 | n/a | static test_structure_3 ABI_ATTR struct3(test_structure_3 ts) |
---|
16 | n/a | { |
---|
17 | n/a | ts.si = -(ts.si*2); |
---|
18 | n/a | |
---|
19 | n/a | return ts; |
---|
20 | n/a | } |
---|
21 | n/a | |
---|
22 | n/a | int main (void) |
---|
23 | n/a | { |
---|
24 | n/a | ffi_cif cif; |
---|
25 | n/a | ffi_type *args[MAX_ARGS]; |
---|
26 | n/a | void *values[MAX_ARGS]; |
---|
27 | n/a | int compare_value; |
---|
28 | n/a | ffi_type ts3_type; |
---|
29 | n/a | ffi_type *ts3_type_elements[2]; |
---|
30 | n/a | |
---|
31 | n/a | test_structure_3 ts3_arg; |
---|
32 | n/a | test_structure_3 *ts3_result = |
---|
33 | n/a | (test_structure_3 *) malloc (sizeof(test_structure_3)); |
---|
34 | n/a | |
---|
35 | n/a | ts3_type.size = 0; |
---|
36 | n/a | ts3_type.alignment = 0; |
---|
37 | n/a | ts3_type.type = FFI_TYPE_STRUCT; |
---|
38 | n/a | ts3_type.elements = ts3_type_elements; |
---|
39 | n/a | ts3_type_elements[0] = &ffi_type_sint; |
---|
40 | n/a | ts3_type_elements[1] = NULL; |
---|
41 | n/a | |
---|
42 | n/a | args[0] = &ts3_type; |
---|
43 | n/a | values[0] = &ts3_arg; |
---|
44 | n/a | |
---|
45 | n/a | /* Initialize the cif */ |
---|
46 | n/a | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, |
---|
47 | n/a | &ts3_type, args) == FFI_OK); |
---|
48 | n/a | |
---|
49 | n/a | ts3_arg.si = -123; |
---|
50 | n/a | compare_value = ts3_arg.si; |
---|
51 | n/a | |
---|
52 | n/a | ffi_call(&cif, FFI_FN(struct3), ts3_result, values); |
---|
53 | n/a | |
---|
54 | n/a | printf ("%d %d\n", ts3_result->si, -(compare_value*2)); |
---|
55 | n/a | |
---|
56 | n/a | CHECK(ts3_result->si == -(compare_value*2)); |
---|
57 | n/a | |
---|
58 | n/a | free (ts3_result); |
---|
59 | n/a | exit(0); |
---|
60 | n/a | } |
---|