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 10typedef struct 11{ 12 double f; 13 double i; 14} test_structure_11; 15 16static test_structure_11 struct9 (test_structure_11 ts) 17{ 18 ts.f += 1; 19 ts.i += 1; 20 21 return ts; 22} 23 24int main (void) 25{ 26 ffi_cif cif; 27 ffi_type *args[MAX_ARGS]; 28 void *values[MAX_ARGS]; 29 ffi_type ts11_type; 30 ffi_type *ts11_type_elements[3]; 31 ts11_type.size = 0; 32 ts11_type.alignment = 0; 33 ts11_type.type = FFI_TYPE_STRUCT; 34 ts11_type.elements = ts11_type_elements; 35 ts11_type_elements[0] = &ffi_type_double; 36 ts11_type_elements[1] = &ffi_type_double; 37 ts11_type_elements[2] = NULL; 38 39 test_structure_11 ts11_arg; 40 41 /* This is a hack to get a properly aligned result buffer */ 42 test_structure_11 *ts11_result = 43 (test_structure_11 *) malloc (sizeof(test_structure_11)); 44 45 args[0] = &ts11_type; 46 values[0] = &ts11_arg; 47 48 /* Initialize the cif */ 49 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts11_type, args) == FFI_OK); 50 51 ts11_arg.f = 5.55; 52 ts11_arg.i = 5.99; 53 54 printf ("%g\n", ts11_arg.f); 55 printf ("%g\n", ts11_arg.i); 56 57 ffi_call(&cif, FFI_FN(struct9), ts11_result, values); 58 59 printf ("%g\n", ts11_result->f); 60 printf ("%g\n", ts11_result->i); 61 62 CHECK(ts11_result->f == 5.55 + 1); 63 CHECK(ts11_result->i == 5.99 + 1); 64 65 free (ts11_result); 66 exit(0); 67} 68