Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / struct5.c
blobc03cc97ac990bff32e84adc0d3832284cd8dff2c
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"
9 typedef struct
11 char c1;
12 char c2;
13 } test_structure_5;
15 static test_structure_5 struct5(test_structure_5 ts1, test_structure_5 ts2)
17 ts1.c1 += ts2.c1;
18 ts1.c2 -= ts2.c2;
20 return ts1;
23 int main (void)
25 ffi_cif cif;
26 ffi_type *args[MAX_ARGS];
27 void *values[MAX_ARGS];
28 ffi_type ts5_type;
29 ffi_type *ts5_type_elements[3];
30 ts5_type.size = 0;
31 ts5_type.alignment = 0;
32 ts5_type.type = FFI_TYPE_STRUCT;
33 ts5_type.elements = ts5_type_elements;
34 ts5_type_elements[0] = &ffi_type_schar;
35 ts5_type_elements[1] = &ffi_type_schar;
36 ts5_type_elements[2] = NULL;
38 test_structure_5 ts5_arg1, ts5_arg2;
40 /* This is a hack to get a properly aligned result buffer */
41 test_structure_5 *ts5_result =
42 (test_structure_5 *) malloc (sizeof(test_structure_5));
44 args[0] = &ts5_type;
45 args[1] = &ts5_type;
46 values[0] = &ts5_arg1;
47 values[1] = &ts5_arg2;
49 /* Initialize the cif */
50 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ts5_type, args) == FFI_OK);
52 ts5_arg1.c1 = 2;
53 ts5_arg1.c2 = 6;
54 ts5_arg2.c1 = 5;
55 ts5_arg2.c2 = 3;
57 ffi_call (&cif, FFI_FN(struct5), ts5_result, values);
59 CHECK(ts5_result->c1 == 7);
60 CHECK(ts5_result->c2 == 3);
63 free (ts5_result);
64 exit(0);