Change soft-fail to use the config, rather than env
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / nested_struct.c
blobadce7ba434f3cd5e89e5bf32d021035aeb9b5c5d
1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing with different structure size.
3 Contains structs as parameter of the struct itself.
4 Limitations: none.
5 PR: none.
6 Originator: <andreast@gcc.gnu.org> 20030828 */
8 /* { dg-do run } */
9 #include "ffitest.h"
11 typedef struct cls_struct_16byte1 {
12 double a;
13 float b;
14 int c;
15 } cls_struct_16byte1;
17 typedef struct cls_struct_16byte2 {
18 int ii;
19 double dd;
20 float ff;
21 } cls_struct_16byte2;
23 typedef struct cls_struct_combined {
24 cls_struct_16byte1 d;
25 cls_struct_16byte2 e;
26 } cls_struct_combined;
28 cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0,
29 struct cls_struct_16byte2 b1,
30 struct cls_struct_combined b2)
32 struct cls_struct_combined result;
34 result.d.a = b0.a + b1.dd + b2.d.a;
35 result.d.b = b0.b + b1.ff + b2.d.b;
36 result.d.c = b0.c + b1.ii + b2.d.c;
37 result.e.ii = b0.c + b1.ii + b2.e.ii;
38 result.e.dd = b0.a + b1.dd + b2.e.dd;
39 result.e.ff = b0.b + b1.ff + b2.e.ff;
41 printf("%g %g %d %d %g %g %g %g %d %d %g %g: %g %g %d %d %g %g\n",
42 b0.a, b0.b, b0.c,
43 b1.ii, b1.dd, b1.ff,
44 b2.d.a, b2.d.b, b2.d.c,
45 b2.e.ii, b2.e.dd, b2.e.ff,
46 result.d.a, result.d.b, result.d.c,
47 result.e.ii, result.e.dd, result.e.ff);
49 return result;
52 static void
53 cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp, void** args,
54 void* userdata __UNUSED__)
56 struct cls_struct_16byte1 b0;
57 struct cls_struct_16byte2 b1;
58 struct cls_struct_combined b2;
60 b0 = *(struct cls_struct_16byte1*)(args[0]);
61 b1 = *(struct cls_struct_16byte2*)(args[1]);
62 b2 = *(struct cls_struct_combined*)(args[2]);
65 *(cls_struct_combined*)resp = cls_struct_combined_fn(b0, b1, b2);
68 int main (void)
70 ffi_cif cif;
71 #ifndef USING_MMAP
72 static ffi_closure cl;
73 #endif
74 ffi_closure *pcl;
75 void* args_dbl[5];
76 ffi_type* cls_struct_fields[5];
77 ffi_type* cls_struct_fields1[5];
78 ffi_type* cls_struct_fields2[5];
79 ffi_type cls_struct_type, cls_struct_type1, cls_struct_type2;
80 ffi_type* dbl_arg_types[5];
82 #ifdef USING_MMAP
83 pcl = allocate_mmap (sizeof(ffi_closure));
84 #else
85 pcl = &cl;
86 #endif
88 cls_struct_type.size = 0;
89 cls_struct_type.alignment = 0;
90 cls_struct_type.type = FFI_TYPE_STRUCT;
91 cls_struct_type.elements = cls_struct_fields;
93 cls_struct_type1.size = 0;
94 cls_struct_type1.alignment = 0;
95 cls_struct_type1.type = FFI_TYPE_STRUCT;
96 cls_struct_type1.elements = cls_struct_fields1;
98 cls_struct_type2.size = 0;
99 cls_struct_type2.alignment = 0;
100 cls_struct_type2.type = FFI_TYPE_STRUCT;
101 cls_struct_type2.elements = cls_struct_fields2;
103 struct cls_struct_16byte1 e_dbl = { 9.0, 2.0, 6};
104 struct cls_struct_16byte2 f_dbl = { 1, 2.0, 3.0};
105 struct cls_struct_combined g_dbl = {{4.0, 5.0, 6},
106 {3, 1.0, 8.0}};
107 struct cls_struct_combined res_dbl;
109 cls_struct_fields[0] = &ffi_type_double;
110 cls_struct_fields[1] = &ffi_type_float;
111 cls_struct_fields[2] = &ffi_type_sint;
112 cls_struct_fields[3] = NULL;
114 cls_struct_fields1[0] = &ffi_type_sint;
115 cls_struct_fields1[1] = &ffi_type_double;
116 cls_struct_fields1[2] = &ffi_type_float;
117 cls_struct_fields1[3] = NULL;
119 cls_struct_fields2[0] = &cls_struct_type;
120 cls_struct_fields2[1] = &cls_struct_type1;
121 cls_struct_fields2[2] = NULL;
124 dbl_arg_types[0] = &cls_struct_type;
125 dbl_arg_types[1] = &cls_struct_type1;
126 dbl_arg_types[2] = &cls_struct_type2;
127 dbl_arg_types[3] = NULL;
129 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, &cls_struct_type2,
130 dbl_arg_types) == FFI_OK);
132 args_dbl[0] = &e_dbl;
133 args_dbl[1] = &f_dbl;
134 args_dbl[2] = &g_dbl;
135 args_dbl[3] = NULL;
137 ffi_call(&cif, FFI_FN(cls_struct_combined_fn), &res_dbl, args_dbl);
138 /* { dg-output "9 2 6 1 2 3 4 5 6 3 1 8: 15 10 13 10 12 13" } */
139 CHECK( res_dbl.d.a == (e_dbl.a + f_dbl.dd + g_dbl.d.a));
140 CHECK( res_dbl.d.b == (e_dbl.b + f_dbl.ff + g_dbl.d.b));
141 CHECK( res_dbl.d.c == (e_dbl.c + f_dbl.ii + g_dbl.d.c));
142 CHECK( res_dbl.e.ii == (e_dbl.c + f_dbl.ii + g_dbl.e.ii));
143 CHECK( res_dbl.e.dd == (e_dbl.a + f_dbl.dd + g_dbl.e.dd));
144 CHECK( res_dbl.e.ff == (e_dbl.b + f_dbl.ff + g_dbl.e.ff));
146 CHECK(ffi_prep_closure(pcl, &cif, cls_struct_combined_gn, NULL) == FFI_OK);
148 res_dbl = ((cls_struct_combined(*)(cls_struct_16byte1,
149 cls_struct_16byte2,
150 cls_struct_combined))
151 (pcl))(e_dbl, f_dbl, g_dbl);
152 /* { dg-output "\n9 2 6 1 2 3 4 5 6 3 1 8: 15 10 13 10 12 13" } */
153 CHECK( res_dbl.d.a == (e_dbl.a + f_dbl.dd + g_dbl.d.a));
154 CHECK( res_dbl.d.b == (e_dbl.b + f_dbl.ff + g_dbl.d.b));
155 CHECK( res_dbl.d.c == (e_dbl.c + f_dbl.ii + g_dbl.d.c));
156 CHECK( res_dbl.e.ii == (e_dbl.c + f_dbl.ii + g_dbl.e.ii));
157 CHECK( res_dbl.e.dd == (e_dbl.a + f_dbl.dd + g_dbl.e.dd));
158 CHECK( res_dbl.e.ff == (e_dbl.b + f_dbl.ff + g_dbl.e.ff));
159 exit(0);