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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/struct2_win32.c

#countcontent
1n/a/* Area: ffi_call
2n/a Purpose: Check structures in fastcall/stdcall function
3n/a Limitations: none.
4n/a PR: none.
5n/a Originator: From the original ffitest.c */
6n/a
7n/a/* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
8n/a#include "ffitest.h"
9n/a
10n/atypedef struct
11n/a{
12n/a double d1;
13n/a double d2;
14n/a} test_structure_2;
15n/a
16n/astatic test_structure_2 __FASTCALL__ struct2(test_structure_2 ts)
17n/a{
18n/a ts.d1--;
19n/a ts.d2--;
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 test_structure_2 ts2_arg;
30n/a ffi_type ts2_type;
31n/a ffi_type *ts2_type_elements[3];
32n/a
33n/a /* This is a hack to get a properly aligned result buffer */
34n/a test_structure_2 *ts2_result =
35n/a (test_structure_2 *) malloc (sizeof(test_structure_2));
36n/a
37n/a ts2_type.size = 0;
38n/a ts2_type.alignment = 0;
39n/a ts2_type.type = FFI_TYPE_STRUCT;
40n/a ts2_type.elements = ts2_type_elements;
41n/a ts2_type_elements[0] = &ffi_type_double;
42n/a ts2_type_elements[1] = &ffi_type_double;
43n/a ts2_type_elements[2] = NULL;
44n/a
45n/a args[0] = &ts2_type;
46n/a values[0] = &ts2_arg;
47n/a
48n/a /* Initialize the cif */
49n/a CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 1, &ts2_type, args) == FFI_OK);
50n/a
51n/a ts2_arg.d1 = 5.55;
52n/a ts2_arg.d2 = 6.66;
53n/a
54n/a printf ("%g\n", ts2_arg.d1);
55n/a printf ("%g\n", ts2_arg.d2);
56n/a
57n/a ffi_call(&cif, FFI_FN(struct2), ts2_result, values);
58n/a
59n/a printf ("%g\n", ts2_result->d1);
60n/a printf ("%g\n", ts2_result->d2);
61n/a
62n/a CHECK(ts2_result->d1 == 5.55 - 1);
63n/a CHECK(ts2_result->d2 == 6.66 - 1);
64n/a
65n/a free (ts2_result);
66n/a exit(0);
67n/a}