1/* Area: ffi_call 2 Purpose: Check structures. 3 Limitations: none. 4 PR: none. 5 Originator: RonaldOussoren@mac.com */ 6 7/* { dg-do run } */ 8#include "ffitest.h" 9 10typedef struct { 11 float x; 12 float y; 13} point; 14 15typedef struct 16{ 17 point l; 18 point r; 19} test_structure_10; 20 21static test_structure_10 struct10 (test_structure_10 ts) 22{ 23 ts.r.x += 1.0; 24 ts.r.y += 1.5; 25 ts.l.x += 2.0; 26 ts.l.y += 2.5; 27 28 return ts; 29} 30 31static test_structure_10 struct10b (test_structure_10 ts) 32{ 33 return struct10(ts); 34} 35 36int main (void) 37{ 38 ffi_cif cif; 39 ffi_type *args[MAX_ARGS]; 40 void *values[MAX_ARGS]; 41 ffi_type ts10_type; 42 ffi_type *ts10_type_elements[3]; 43 ffi_type ts10p_type; 44 ffi_type *ts10p_type_elements[3]; 45 46 ts10p_type.size = 0; 47 ts10p_type.alignment = 0; 48 ts10p_type.type = FFI_TYPE_STRUCT; 49 ts10p_type.elements = ts10p_type_elements; 50 ts10p_type_elements[0] = &ffi_type_float; 51 ts10p_type_elements[1] = &ffi_type_float; 52 ts10p_type_elements[2] = NULL; 53 54 ts10_type.size = 0; 55 ts10_type.alignment = 0; 56 ts10_type.type = FFI_TYPE_STRUCT; 57 ts10_type.elements = ts10_type_elements; 58 ts10_type_elements[0] = &ts10p_type; 59 ts10_type_elements[1] = &ts10p_type; 60 ts10_type_elements[2] = NULL; 61 62 test_structure_10 ts10_arg; 63 64 /* This is a hack to get a properly aligned result buffer */ 65 test_structure_10 *ts10_result = 66 (test_structure_10 *) malloc (sizeof(test_structure_10)); 67 68 args[0] = &ts10_type; 69 values[0] = &ts10_arg; 70 71 /* Initialize the cif */ 72 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts10_type, args) == FFI_OK); 73 74 ts10_arg.r.x = 1.44; 75 ts10_arg.r.y = 2.44; 76 ts10_arg.l.x = 3.44; 77 ts10_arg.l.y = 4.44; 78 79 printf ("%g\n", ts10_arg.r.x); 80 printf ("%g\n", ts10_arg.r.y); 81 printf ("%g\n", ts10_arg.l.x); 82 printf ("%g\n", ts10_arg.l.y); 83 84 ffi_call(&cif, FFI_FN(struct10b), ts10_result, values); 85 86 printf ("%g\n", ts10_result->r.x); 87 printf ("%g\n", ts10_result->r.y); 88 printf ("%g\n", ts10_result->l.x); 89 printf ("%g\n", ts10_result->l.y); 90 91 CHECK(ts10_result->r.x == 1.44f + 1.0); 92 CHECK(ts10_result->r.y == 2.44f + 1.5); 93 CHECK(ts10_result->l.x == 3.44f + 2.0); 94 CHECK(ts10_result->l.y == 4.44f + 2.5); 95 96 free (ts10_result); 97 exit(0); 98} 99