ยปCore Development>Code coverage>Modules/_ctypes/libffi/testsuite/libffi.call/struct5.c

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct5.c

#countcontent
1n/a/* Area: ffi_call
2n/a Purpose: Check structures.
3n/a Limitations: none.
4n/a PR: none.
5n/a Originator: From the original ffitest.c */
6n/a
7n/a/* { dg-do run } */
8n/a#include "ffitest.h"
9n/atypedef struct
10n/a{
11n/a char c1;
12n/a char c2;
13n/a} test_structure_5;
14n/a
15n/astatic test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2)
16n/a{
17n/a ts1.c1 += ts2.c1;
18n/a ts1.c2 -= ts2.c2;
19n/a
20n/a return ts1;
21n/a}
22n/a
23n/aint main (void)
24n/a{
25n/a ffi_cif cif;
26n/a ffi_type *args[MAX_ARGS];
27n/a void *values[MAX_ARGS];
28n/a ffi_type ts5_type;
29n/a ffi_type *ts5_type_elements[3];
30n/a
31n/a test_structure_5 ts5_arg1, ts5_arg2;
32n/a
33n/a /* This is a hack to get a properly aligned result buffer */
34n/a test_structure_5 *ts5_result =
35n/a (test_structure_5 *) malloc (sizeof(test_structure_5));
36n/a
37n/a ts5_type.size = 0;
38n/a ts5_type.alignment = 0;
39n/a ts5_type.type = FFI_TYPE_STRUCT;
40n/a ts5_type.elements = ts5_type_elements;
41n/a ts5_type_elements[0] = &ffi_type_schar;
42n/a ts5_type_elements[1] = &ffi_type_schar;
43n/a ts5_type_elements[2] = NULL;
44n/a
45n/a args[0] = &ts5_type;
46n/a args[1] = &ts5_type;
47n/a values[0] = &ts5_arg1;
48n/a values[1] = &ts5_arg2;
49n/a
50n/a /* Initialize the cif */
51n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK);
52n/a
53n/a ts5_arg1.c1 = 2;
54n/a ts5_arg1.c2 = 6;
55n/a ts5_arg2.c1 = 5;
56n/a ts5_arg2.c2 = 3;
57n/a
58n/a ffi_call (&cif, FFI_FN(struct5), ts5_result, values);
59n/a
60n/a CHECK(ts5_result->c1 == 7);
61n/a CHECK(ts5_result->c2 == 3);
62n/a
63n/a
64n/a free (ts5_result);
65n/a exit(0);
66n/a}