Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / struct9.c
blobf30091f54f129040ffbd8cb22534bd5e8639943a
1 /* Area: ffi_call
2 Purpose: Check structures.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
7 /* { dg-do run } */
8 #include "ffitest.h"
10 typedef struct
12 float f;
13 int i;
14 } test_structure_9;
16 static test_structure_9 struct9 (test_structure_9 ts)
18 ts.f += 1;
19 ts.i += 1;
21 return ts;
24 int main (void)
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 ffi_type ts9_type;
30 ffi_type *ts9_type_elements[3];
31 ts9_type.size = 0;
32 ts9_type.alignment = 0;
33 ts9_type.type = FFI_TYPE_STRUCT;
34 ts9_type.elements = ts9_type_elements;
35 ts9_type_elements[0] = &ffi_type_float;
36 ts9_type_elements[1] = &ffi_type_sint;
37 ts9_type_elements[2] = NULL;
39 test_structure_9 ts9_arg;
41 /* This is a hack to get a properly aligned result buffer */
42 test_structure_9 *ts9_result =
43 (test_structure_9 *) malloc (sizeof(test_structure_9));
45 args[0] = &ts9_type;
46 values[0] = &ts9_arg;
48 /* Initialize the cif */
49 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts9_type, args) == FFI_OK);
51 ts9_arg.f = 5.55f;
52 ts9_arg.i = 5;
54 printf ("%g\n", ts9_arg.f);
55 printf ("%d\n", ts9_arg.i);
57 ffi_call(&cif, FFI_FN(struct9), ts9_result, values);
59 printf ("%g\n", ts9_result->f);
60 printf ("%d\n", ts9_result->i);
62 CHECK(ts9_result->f == 5.55f + 1);
63 CHECK(ts9_result->i == 5 + 1);
65 free (ts9_result);
66 exit(0);