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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct9.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 float f;
13n/a int i;
14n/a} test_structure_9;
15n/a
16n/astatic test_structure_9 ABI_ATTR struct9 (test_structure_9 ts)
17n/a{
18n/a ts.f += 1;
19n/a ts.i += 1;
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 ts9_type;
30n/a ffi_type *ts9_type_elements[3];
31n/a
32n/a test_structure_9 ts9_arg;
33n/a
34n/a /* This is a hack to get a properly aligned result buffer */
35n/a test_structure_9 *ts9_result =
36n/a (test_structure_9 *) malloc (sizeof(test_structure_9));
37n/a
38n/a ts9_type.size = 0;
39n/a ts9_type.alignment = 0;
40n/a ts9_type.type = FFI_TYPE_STRUCT;
41n/a ts9_type.elements = ts9_type_elements;
42n/a ts9_type_elements[0] = &ffi_type_float;
43n/a ts9_type_elements[1] = &ffi_type_sint;
44n/a ts9_type_elements[2] = NULL;
45n/a
46n/a args[0] = &ts9_type;
47n/a values[0] = &ts9_arg;
48n/a
49n/a /* Initialize the cif */
50n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts9_type, args) == FFI_OK);
51n/a
52n/a ts9_arg.f = 5.55f;
53n/a ts9_arg.i = 5;
54n/a
55n/a printf ("%g\n", ts9_arg.f);
56n/a printf ("%d\n", ts9_arg.i);
57n/a
58n/a ffi_call(&cif, FFI_FN(struct9), ts9_result, values);
59n/a
60n/a printf ("%g\n", ts9_result->f);
61n/a printf ("%d\n", ts9_result->i);
62n/a
63n/a CHECK(ts9_result->f == 5.55f + 1);
64n/a CHECK(ts9_result->i == 5 + 1);
65n/a
66n/a free (ts9_result);
67n/a exit(0);
68n/a}