1 | n/a | /* { dg-do run } */ |
---|
2 | n/a | #include "ffitest.h" |
---|
3 | n/a | |
---|
4 | n/a | typedef struct |
---|
5 | n/a | { |
---|
6 | n/a | unsigned char uc; |
---|
7 | n/a | double d; |
---|
8 | n/a | unsigned int ui; |
---|
9 | n/a | } test_structure_1; |
---|
10 | n/a | |
---|
11 | n/a | static test_structure_1 struct1(test_structure_1 ts) |
---|
12 | n/a | { |
---|
13 | n/a | ts.uc++; |
---|
14 | n/a | ts.d--; |
---|
15 | n/a | ts.ui++; |
---|
16 | n/a | |
---|
17 | n/a | return ts; |
---|
18 | n/a | } |
---|
19 | n/a | |
---|
20 | n/a | int main (void) |
---|
21 | n/a | { |
---|
22 | n/a | ffi_cif cif; |
---|
23 | n/a | ffi_type *args[MAX_ARGS]; |
---|
24 | n/a | void *values[MAX_ARGS]; |
---|
25 | n/a | ffi_type ts1_type; |
---|
26 | n/a | ffi_type *ts1_type_elements[4]; |
---|
27 | n/a | |
---|
28 | n/a | memset(&cif, 1, sizeof(cif)); |
---|
29 | n/a | ts1_type.size = 0; |
---|
30 | n/a | ts1_type.alignment = 0; |
---|
31 | n/a | ts1_type.type = FFI_TYPE_STRUCT; |
---|
32 | n/a | ts1_type.elements = ts1_type_elements; |
---|
33 | n/a | ts1_type_elements[0] = &ffi_type_uchar; |
---|
34 | n/a | ts1_type_elements[1] = &ffi_type_double; |
---|
35 | n/a | ts1_type_elements[2] = &ffi_type_uint; |
---|
36 | n/a | ts1_type_elements[3] = NULL; |
---|
37 | n/a | |
---|
38 | n/a | test_structure_1 ts1_arg; |
---|
39 | n/a | /* This is a hack to get a properly aligned result buffer */ |
---|
40 | n/a | test_structure_1 *ts1_result = |
---|
41 | n/a | (test_structure_1 *) malloc (sizeof(test_structure_1)); |
---|
42 | n/a | |
---|
43 | n/a | args[0] = &ts1_type; |
---|
44 | n/a | values[0] = &ts1_arg; |
---|
45 | n/a | |
---|
46 | n/a | /* Initialize the cif */ |
---|
47 | n/a | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, |
---|
48 | n/a | &ts1_type, args) == FFI_OK); |
---|
49 | n/a | |
---|
50 | n/a | ts1_arg.uc = '\x01'; |
---|
51 | n/a | ts1_arg.d = 3.14159; |
---|
52 | n/a | ts1_arg.ui = 555; |
---|
53 | n/a | |
---|
54 | n/a | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); |
---|
55 | n/a | |
---|
56 | n/a | CHECK(ts1_result->ui == 556); |
---|
57 | n/a | CHECK(ts1_result->d == 3.14159 - 1); |
---|
58 | n/a | |
---|
59 | n/a | free (ts1_result); |
---|
60 | n/a | exit(0); |
---|
61 | n/a | } |
---|