2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / libffi.call / struct1.c
blob99c5d3b91ac8b2d14f70fc3fbd25cdd81855af01
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 unsigned char uc;
13 double d;
14 unsigned int ui;
15 } test_structure_1;
17 static test_structure_1 struct1(test_structure_1 ts)
19 /*@-type@*/
20 ts.uc++;
21 /*@=type@*/
22 ts.d--;
23 ts.ui++;
25 return ts;
28 int main (void)
30 ffi_cif cif;
31 ffi_type *args[MAX_ARGS];
32 void *values[MAX_ARGS];
33 ffi_type ts1_type;
34 ffi_type *ts1_type_elements[4];
35 ts1_type.size = 0;
36 ts1_type.alignment = 0;
37 ts1_type.type = FFI_TYPE_STRUCT;
38 ts1_type.elements = ts1_type_elements;
39 ts1_type_elements[0] = &ffi_type_uchar;
40 ts1_type_elements[1] = &ffi_type_double;
41 ts1_type_elements[2] = &ffi_type_uint;
42 ts1_type_elements[3] = NULL;
44 test_structure_1 ts1_arg;
45 /* This is a hack to get a properly aligned result buffer */
46 test_structure_1 *ts1_result =
47 (test_structure_1 *) malloc (sizeof(test_structure_1));
49 args[0] = &ts1_type;
50 values[0] = &ts1_arg;
52 /* Initialize the cif */
53 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
54 &ts1_type, args) == FFI_OK);
56 ts1_arg.uc = '\x01';
57 ts1_arg.d = 3.14159;
58 ts1_arg.ui = 555;
60 ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
62 CHECK(ts1_result->ui == 556);
63 CHECK(ts1_result->d == 3.14159 - 1);
65 free (ts1_result);
66 exit(0);