annotate libffi/testsuite/libffi.call/struct5.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Area: ffi_call
kono
parents:
diff changeset
2 Purpose: Check structures.
kono
parents:
diff changeset
3 Limitations: none.
kono
parents:
diff changeset
4 PR: none.
kono
parents:
diff changeset
5 Originator: From the original ffitest.c */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 /* { dg-do run } */
kono
parents:
diff changeset
8 #include "ffitest.h"
kono
parents:
diff changeset
9 typedef struct
kono
parents:
diff changeset
10 {
kono
parents:
diff changeset
11 char c1;
kono
parents:
diff changeset
12 char c2;
kono
parents:
diff changeset
13 } test_structure_5;
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 static test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2)
kono
parents:
diff changeset
16 {
kono
parents:
diff changeset
17 ts1.c1 += ts2.c1;
kono
parents:
diff changeset
18 ts1.c2 -= ts2.c2;
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 return ts1;
kono
parents:
diff changeset
21 }
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 int main (void)
kono
parents:
diff changeset
24 {
kono
parents:
diff changeset
25 ffi_cif cif;
kono
parents:
diff changeset
26 ffi_type *args[MAX_ARGS];
kono
parents:
diff changeset
27 void *values[MAX_ARGS];
kono
parents:
diff changeset
28 ffi_type ts5_type;
kono
parents:
diff changeset
29 ffi_type *ts5_type_elements[3];
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 test_structure_5 ts5_arg1, ts5_arg2;
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 /* This is a hack to get a properly aligned result buffer */
kono
parents:
diff changeset
34 test_structure_5 *ts5_result =
kono
parents:
diff changeset
35 (test_structure_5 *) malloc (sizeof(test_structure_5));
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 ts5_type.size = 0;
kono
parents:
diff changeset
38 ts5_type.alignment = 0;
kono
parents:
diff changeset
39 ts5_type.type = FFI_TYPE_STRUCT;
kono
parents:
diff changeset
40 ts5_type.elements = ts5_type_elements;
kono
parents:
diff changeset
41 ts5_type_elements[0] = &ffi_type_schar;
kono
parents:
diff changeset
42 ts5_type_elements[1] = &ffi_type_schar;
kono
parents:
diff changeset
43 ts5_type_elements[2] = NULL;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 args[0] = &ts5_type;
kono
parents:
diff changeset
46 args[1] = &ts5_type;
kono
parents:
diff changeset
47 values[0] = &ts5_arg1;
kono
parents:
diff changeset
48 values[1] = &ts5_arg2;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Initialize the cif */
kono
parents:
diff changeset
51 CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK);
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 ts5_arg1.c1 = 2;
kono
parents:
diff changeset
54 ts5_arg1.c2 = 6;
kono
parents:
diff changeset
55 ts5_arg2.c1 = 5;
kono
parents:
diff changeset
56 ts5_arg2.c2 = 3;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 ffi_call (&cif, FFI_FN(struct5), ts5_result, values);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 CHECK(ts5_result->c1 == 7);
kono
parents:
diff changeset
61 CHECK(ts5_result->c2 == 3);
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 free (ts5_result);
kono
parents:
diff changeset
65 exit(0);
kono
parents:
diff changeset
66 }