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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct4.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/a
10n/atypedef struct
11n/a{
12n/a unsigned ui1;
13n/a unsigned ui2;
14n/a unsigned ui3;
15n/a} test_structure_4;
16n/a
17n/astatic test_structure_4 ABI_ATTR struct4(test_structure_4 ts)
18n/a{
19n/a ts.ui3 = ts.ui1 * ts.ui2 * ts.ui3;
20n/a
21n/a return ts;
22n/a}
23n/a
24n/aint main (void)
25n/a{
26n/a ffi_cif cif;
27n/a ffi_type *args[MAX_ARGS];
28n/a void *values[MAX_ARGS];
29n/a ffi_type ts4_type;
30n/a ffi_type *ts4_type_elements[4];
31n/a
32n/a test_structure_4 ts4_arg;
33n/a
34n/a /* This is a hack to get a properly aligned result buffer */
35n/a test_structure_4 *ts4_result =
36n/a (test_structure_4 *) malloc (sizeof(test_structure_4));
37n/a
38n/a ts4_type.size = 0;
39n/a ts4_type.alignment = 0;
40n/a ts4_type.type = FFI_TYPE_STRUCT;
41n/a ts4_type.elements = ts4_type_elements;
42n/a ts4_type_elements[0] = &ffi_type_uint;
43n/a ts4_type_elements[1] = &ffi_type_uint;
44n/a ts4_type_elements[2] = &ffi_type_uint;
45n/a ts4_type_elements[3] = NULL;
46n/a
47n/a args[0] = &ts4_type;
48n/a values[0] = &ts4_arg;
49n/a
50n/a /* Initialize the cif */
51n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts4_type, args) == FFI_OK);
52n/a
53n/a ts4_arg.ui1 = 2;
54n/a ts4_arg.ui2 = 3;
55n/a ts4_arg.ui3 = 4;
56n/a
57n/a ffi_call (&cif, FFI_FN(struct4), ts4_result, values);
58n/a
59n/a CHECK(ts4_result->ui3 == 2U * 3U * 4U);
60n/a
61n/a
62n/a free (ts4_result);
63n/a exit(0);
64n/a}