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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct1.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 char uc;
13n/a double d;
14n/a unsigned int ui;
15n/a} test_structure_1;
16n/a
17n/astatic test_structure_1 ABI_ATTR struct1(test_structure_1 ts)
18n/a{
19n/a ts.uc++;
20n/a ts.d--;
21n/a ts.ui++;
22n/a
23n/a return ts;
24n/a}
25n/a
26n/aint main (void)
27n/a{
28n/a ffi_cif cif;
29n/a ffi_type *args[MAX_ARGS];
30n/a void *values[MAX_ARGS];
31n/a ffi_type ts1_type;
32n/a ffi_type *ts1_type_elements[4];
33n/a
34n/a test_structure_1 ts1_arg;
35n/a
36n/a /* This is a hack to get a properly aligned result buffer */
37n/a test_structure_1 *ts1_result =
38n/a (test_structure_1 *) malloc (sizeof(test_structure_1));
39n/a
40n/a ts1_type.size = 0;
41n/a ts1_type.alignment = 0;
42n/a ts1_type.type = FFI_TYPE_STRUCT;
43n/a ts1_type.elements = ts1_type_elements;
44n/a ts1_type_elements[0] = &ffi_type_uchar;
45n/a ts1_type_elements[1] = &ffi_type_double;
46n/a ts1_type_elements[2] = &ffi_type_uint;
47n/a ts1_type_elements[3] = NULL;
48n/a
49n/a args[0] = &ts1_type;
50n/a values[0] = &ts1_arg;
51n/a
52n/a /* Initialize the cif */
53n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
54n/a &ts1_type, args) == FFI_OK);
55n/a
56n/a ts1_arg.uc = '\x01';
57n/a ts1_arg.d = 3.14159;
58n/a ts1_arg.ui = 555;
59n/a
60n/a ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
61n/a
62n/a CHECK(ts1_result->ui == 556);
63n/a CHECK(ts1_result->d == 3.14159 - 1);
64n/a
65n/a free (ts1_result);
66n/a exit(0);
67n/a}