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

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

#countcontent
1n/a/* Area: ffi_call
2n/a Purpose: Test passing struct in variable argument lists.
3n/a Limitations: none.
4n/a PR: none.
5n/a Originator: ARM Ltd. */
6n/a
7n/a/* { dg-do run } */
8n/a/* { dg-output "" { xfail avr32*-*-* } } */
9n/a
10n/a#include "ffitest.h"
11n/a#include <stdarg.h>
12n/a
13n/astruct small_tag
14n/a{
15n/a unsigned char a;
16n/a unsigned char b;
17n/a};
18n/a
19n/astruct large_tag
20n/a{
21n/a unsigned a;
22n/a unsigned b;
23n/a unsigned c;
24n/a unsigned d;
25n/a unsigned e;
26n/a};
27n/a
28n/astatic struct large_tag
29n/atest_fn (int n, ...)
30n/a{
31n/a va_list ap;
32n/a struct small_tag s1;
33n/a struct small_tag s2;
34n/a struct large_tag l;
35n/a
36n/a va_start (ap, n);
37n/a s1 = va_arg (ap, struct small_tag);
38n/a l = va_arg (ap, struct large_tag);
39n/a s2 = va_arg (ap, struct small_tag);
40n/a printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e,
41n/a s2.a, s2.b);
42n/a va_end (ap);
43n/a l.a += s1.a;
44n/a l.b += s1.b;
45n/a l.c += s2.a;
46n/a l.d += s2.b;
47n/a return l;
48n/a}
49n/a
50n/aint
51n/amain (void)
52n/a{
53n/a ffi_cif cif;
54n/a void* args[5];
55n/a ffi_type* arg_types[5];
56n/a
57n/a ffi_type s_type;
58n/a ffi_type *s_type_elements[3];
59n/a
60n/a ffi_type l_type;
61n/a ffi_type *l_type_elements[6];
62n/a
63n/a struct small_tag s1;
64n/a struct small_tag s2;
65n/a struct large_tag l1;
66n/a
67n/a int n;
68n/a struct large_tag res;
69n/a
70n/a s_type.size = 0;
71n/a s_type.alignment = 0;
72n/a s_type.type = FFI_TYPE_STRUCT;
73n/a s_type.elements = s_type_elements;
74n/a
75n/a s_type_elements[0] = &ffi_type_uchar;
76n/a s_type_elements[1] = &ffi_type_uchar;
77n/a s_type_elements[2] = NULL;
78n/a
79n/a l_type.size = 0;
80n/a l_type.alignment = 0;
81n/a l_type.type = FFI_TYPE_STRUCT;
82n/a l_type.elements = l_type_elements;
83n/a
84n/a l_type_elements[0] = &ffi_type_uint;
85n/a l_type_elements[1] = &ffi_type_uint;
86n/a l_type_elements[2] = &ffi_type_uint;
87n/a l_type_elements[3] = &ffi_type_uint;
88n/a l_type_elements[4] = &ffi_type_uint;
89n/a l_type_elements[5] = NULL;
90n/a
91n/a arg_types[0] = &ffi_type_sint;
92n/a arg_types[1] = &s_type;
93n/a arg_types[2] = &l_type;
94n/a arg_types[3] = &s_type;
95n/a arg_types[4] = NULL;
96n/a
97n/a CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &l_type, arg_types) == FFI_OK);
98n/a
99n/a s1.a = 5;
100n/a s1.b = 6;
101n/a
102n/a l1.a = 10;
103n/a l1.b = 11;
104n/a l1.c = 12;
105n/a l1.d = 13;
106n/a l1.e = 14;
107n/a
108n/a s2.a = 7;
109n/a s2.b = 8;
110n/a
111n/a n = 41;
112n/a
113n/a args[0] = &n;
114n/a args[1] = &s1;
115n/a args[2] = &l1;
116n/a args[3] = &s2;
117n/a args[4] = NULL;
118n/a
119n/a ffi_call(&cif, FFI_FN(test_fn), &res, args);
120n/a /* { dg-output "5 6 10 11 12 13 14 7 8" } */
121n/a printf("res: %d %d %d %d %d\n", res.a, res.b, res.c, res.d, res.e);
122n/a /* { dg-output "\nres: 15 17 19 21 14" } */
123n/a
124n/a return 0;
125n/a}