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

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