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

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