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