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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct7.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 f1;
12n/a float f2;
13n/a double d;
14n/a} test_structure_7;
15n/a
16n/astatic test_structure_7 ABI_ATTR struct7 (test_structure_7 ts)
17n/a{
18n/a ts.f1 += 1;
19n/a ts.f2 += 1;
20n/a ts.d += 1;
21n/a
22n/a return ts;
23n/a}
24n/a
25n/aint main (void)
26n/a{
27n/a ffi_cif cif;
28n/a ffi_type *args[MAX_ARGS];
29n/a void *values[MAX_ARGS];
30n/a ffi_type ts7_type;
31n/a ffi_type *ts7_type_elements[4];
32n/a
33n/a test_structure_7 ts7_arg;
34n/a
35n/a /* This is a hack to get a properly aligned result buffer */
36n/a test_structure_7 *ts7_result =
37n/a (test_structure_7 *) malloc (sizeof(test_structure_7));
38n/a
39n/a ts7_type.size = 0;
40n/a ts7_type.alignment = 0;
41n/a ts7_type.type = FFI_TYPE_STRUCT;
42n/a ts7_type.elements = ts7_type_elements;
43n/a ts7_type_elements[0] = &ffi_type_float;
44n/a ts7_type_elements[1] = &ffi_type_float;
45n/a ts7_type_elements[2] = &ffi_type_double;
46n/a ts7_type_elements[3] = NULL;
47n/a
48n/a args[0] = &ts7_type;
49n/a values[0] = &ts7_arg;
50n/a
51n/a /* Initialize the cif */
52n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts7_type, args) == FFI_OK);
53n/a
54n/a ts7_arg.f1 = 5.55f;
55n/a ts7_arg.f2 = 55.5f;
56n/a ts7_arg.d = 6.66;
57n/a
58n/a printf ("%g\n", ts7_arg.f1);
59n/a printf ("%g\n", ts7_arg.f2);
60n/a printf ("%g\n", ts7_arg.d);
61n/a
62n/a ffi_call(&cif, FFI_FN(struct7), ts7_result, values);
63n/a
64n/a printf ("%g\n", ts7_result->f1);
65n/a printf ("%g\n", ts7_result->f2);
66n/a printf ("%g\n", ts7_result->d);
67n/a
68n/a CHECK(ts7_result->f1 == 5.55f + 1);
69n/a CHECK(ts7_result->f2 == 55.5f + 1);
70n/a CHECK(ts7_result->d == 6.66 + 1);
71n/a
72n/a free (ts7_result);
73n/a exit(0);
74n/a}