| 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 |
|
| 10 |
typedef struct |
| 11 |
{ |
| 12 |
float f; |
| 13 |
} s55; |
| 14 |
|
| 15 |
static s55 ABI_ATTR f55(s55 ts, float f) |
| 16 |
{ |
| 17 |
s55 r; |
| 18 |
r.f = ts.f + f; |
| 19 |
printf ("f55>> %g + %g = %g\n", ts.f, f, r.f); |
| 20 |
return r; |
| 21 |
} |
| 22 |
|
| 23 |
int main (void) |
| 24 |
{ |
| 25 |
ffi_cif cif; |
| 26 |
s55 F, Fr; |
| 27 |
float f; |
| 28 |
void *values[] = { &F, &f }; |
| 29 |
ffi_type s55_type; |
| 30 |
ffi_type *args[] = { &s55_type, &ffi_type_float }; |
| 31 |
ffi_type *s55_type_elements[] = { &ffi_type_float, NULL }; |
| 32 |
|
| 33 |
/* This is a hack to get a properly aligned result buffer */ |
| 34 |
s55 *s55_result = |
| 35 |
(s55 *) malloc (sizeof(s55)); |
| 36 |
|
| 37 |
s55_type.size = 0; |
| 38 |
s55_type.alignment = 0; |
| 39 |
s55_type.type = FFI_TYPE_STRUCT; |
| 40 |
s55_type.elements = s55_type_elements; |
| 41 |
|
| 42 |
/* Initialize the cif */ |
| 43 |
CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &s55_type, args) == FFI_OK); |
| 44 |
|
| 45 |
F.f = 1; |
| 46 |
Fr = f55(F, 2.14); |
| 47 |
printf ("%g\n", Fr.f); |
| 48 |
|
| 49 |
F.f = 1; |
| 50 |
f = 2.14; |
| 51 |
ffi_call(&cif, FFI_FN(f55), s55_result, values); |
| 52 |
printf ("%g\n", s55_result->f); |
| 53 |
|
| 54 |
fflush(0); |
| 55 |
|
| 56 |
CHECK(fabs(Fr.f - s55_result->f) < FLT_EPSILON); |
| 57 |
|
| 58 |
free (s55_result); |
| 59 |
exit(0); |
| 60 |
} |