| 1 |
/* Area: ffi_call |
| 2 |
Purpose: Check structures. |
| 3 |
Limitations: none. |
| 4 |
PR: none. |
| 5 |
Originator: From the original ffitest.c */ |
| 6 |
|
| 7 |
/* { dg-do run } */ |
| 8 |
#include "ffitest.h" |
| 9 |
typedef struct |
| 10 |
{ |
| 11 |
int a; |
| 12 |
int b; |
| 13 |
int c; |
| 14 |
int d; |
| 15 |
int e; |
| 16 |
int f; |
| 17 |
int g; |
| 18 |
int h; |
| 19 |
} test_structure_5; |
| 20 |
|
| 21 |
static test_structure_5 ABI_ATTR struct5(test_structure_5 inp) |
| 22 |
{ |
| 23 |
inp.a *= 2; |
| 24 |
inp.b *= 3; |
| 25 |
inp.c *= 4; |
| 26 |
inp.d *= 5; |
| 27 |
inp.e *= 6; |
| 28 |
inp.f *= 7; |
| 29 |
inp.g *= 8; |
| 30 |
inp.h *= 9; |
| 31 |
return inp; |
| 32 |
} |
| 33 |
|
| 34 |
int main (void) |
| 35 |
{ |
| 36 |
ffi_cif cif; |
| 37 |
ffi_type *args[MAX_ARGS]; |
| 38 |
void *values[MAX_ARGS]; |
| 39 |
ffi_type ts5_type; |
| 40 |
ffi_type *ts5_type_elements[9]; |
| 41 |
|
| 42 |
test_structure_5 ts5_arg1; |
| 43 |
|
| 44 |
/* This is a hack to get a properly aligned result buffer */ |
| 45 |
test_structure_5 *ts5_result = |
| 46 |
(test_structure_5 *) malloc (sizeof(test_structure_5)); |
| 47 |
|
| 48 |
ts5_type.size = 0; |
| 49 |
ts5_type.alignment = 0; |
| 50 |
ts5_type.type = FFI_TYPE_STRUCT; |
| 51 |
ts5_type.elements = ts5_type_elements; |
| 52 |
ts5_type_elements[0] = &ffi_type_sint; |
| 53 |
ts5_type_elements[1] = &ffi_type_sint; |
| 54 |
ts5_type_elements[2] = &ffi_type_sint; |
| 55 |
ts5_type_elements[3] = &ffi_type_sint; |
| 56 |
ts5_type_elements[4] = &ffi_type_sint; |
| 57 |
ts5_type_elements[5] = &ffi_type_sint; |
| 58 |
ts5_type_elements[6] = &ffi_type_sint; |
| 59 |
ts5_type_elements[7] = &ffi_type_sint; |
| 60 |
ts5_type_elements[8] = NULL; |
| 61 |
|
| 62 |
args[0] = &ts5_type; |
| 63 |
values[0] = &ts5_arg1; |
| 64 |
|
| 65 |
/* Initialize the cif */ |
| 66 |
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts5_type, args) == FFI_OK); |
| 67 |
|
| 68 |
ts5_arg1.a = 9; |
| 69 |
ts5_arg1.b = 8; |
| 70 |
ts5_arg1.c = 7; |
| 71 |
ts5_arg1.d = 6; |
| 72 |
ts5_arg1.e = 5; |
| 73 |
ts5_arg1.f = 4; |
| 74 |
ts5_arg1.g = 3; |
| 75 |
ts5_arg1.h = 2; |
| 76 |
|
| 77 |
ffi_call (&cif, FFI_FN(struct5), ts5_result, values); |
| 78 |
|
| 79 |
CHECK(ts5_result->a == 9*2); |
| 80 |
CHECK(ts5_result->b == 8*3); |
| 81 |
CHECK(ts5_result->c == 7*4); |
| 82 |
CHECK(ts5_result->d == 6*5); |
| 83 |
CHECK(ts5_result->e == 5*6); |
| 84 |
CHECK(ts5_result->f == 4*7); |
| 85 |
CHECK(ts5_result->g == 3*8); |
| 86 |
CHECK(ts5_result->h == 2*9); |
| 87 |
|
| 88 |
free (ts5_result); |
| 89 |
exit(0); |
| 90 |
} |