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

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/va_struct2.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 small_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 s1.a += s2.a;
44n/a s1.b += s2.b;
45n/a return s1;
46n/a}
47n/a
48n/aint
49n/amain (void)
50n/a{
51n/a ffi_cif cif;
52n/a void* args[5];
53n/a ffi_type* arg_types[5];
54n/a
55n/a ffi_type s_type;
56n/a ffi_type *s_type_elements[3];
57n/a
58n/a ffi_type l_type;
59n/a ffi_type *l_type_elements[6];
60n/a
61n/a struct small_tag s1;
62n/a struct small_tag s2;
63n/a struct large_tag l1;
64n/a
65n/a int n;
66n/a struct small_tag res;
67n/a
68n/a s_type.size = 0;
69n/a s_type.alignment = 0;
70n/a s_type.type = FFI_TYPE_STRUCT;
71n/a s_type.elements = s_type_elements;
72n/a
73n/a s_type_elements[0] = &ffi_type_uchar;
74n/a s_type_elements[1] = &ffi_type_uchar;
75n/a s_type_elements[2] = NULL;
76n/a
77n/a l_type.size = 0;
78n/a l_type.alignment = 0;
79n/a l_type.type = FFI_TYPE_STRUCT;
80n/a l_type.elements = l_type_elements;
81n/a
82n/a l_type_elements[0] = &ffi_type_uint;
83n/a l_type_elements[1] = &ffi_type_uint;
84n/a l_type_elements[2] = &ffi_type_uint;
85n/a l_type_elements[3] = &ffi_type_uint;
86n/a l_type_elements[4] = &ffi_type_uint;
87n/a l_type_elements[5] = NULL;
88n/a
89n/a arg_types[0] = &ffi_type_sint;
90n/a arg_types[1] = &s_type;
91n/a arg_types[2] = &l_type;
92n/a arg_types[3] = &s_type;
93n/a arg_types[4] = NULL;
94n/a
95n/a CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &s_type, arg_types) == FFI_OK);
96n/a
97n/a s1.a = 5;
98n/a s1.b = 6;
99n/a
100n/a l1.a = 10;
101n/a l1.b = 11;
102n/a l1.c = 12;
103n/a l1.d = 13;
104n/a l1.e = 14;
105n/a
106n/a s2.a = 7;
107n/a s2.b = 8;
108n/a
109n/a n = 41;
110n/a
111n/a args[0] = &n;
112n/a args[1] = &s1;
113n/a args[2] = &l1;
114n/a args[3] = &s2;
115n/a args[4] = NULL;
116n/a
117n/a ffi_call(&cif, FFI_FN(test_fn), &res, args);
118n/a /* { dg-output "5 6 10 11 12 13 14 7 8" } */
119n/a printf("res: %d %d\n", res.a, res.b);
120n/a /* { dg-output "\nres: 12 14" } */
121n/a
122n/a return 0;
123n/a}