Debian Codegraph @

testsuite/libffi.closures/cls_dbls_struct.c

raw
1 /* Area: ffi_call, closure_call
2 Purpose: Check double arguments in structs.
3 Limitations: none.
4 PR: none.
5 Originator: Blake Chaffin 6/23/2007 */
6
7 /* { dg-do run } */
8
9 #include "ffitest.h"
10
11 typedef struct Dbls {
12 double x;
13 double y;
14 } Dbls;
15
16 void
17 closure_test_fn(Dbls p)
18 {
19 printf("%.1f %.1f\n", p.x, p.y);
20 CHECK(p.x == 1);
21 CHECK(p.y == 2);
22 }
23
24 void
25 closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
26 void** args, void* userdata __UNUSED__)
27 {
28 closure_test_fn(*(Dbls*)args[0]);
29 }
30
31 int main(void)
32 {
33 ffi_cif cif;
34
35 void *code;
36 ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
37 ffi_type* cl_arg_types[1];
38
39 ffi_type ts1_type;
40 ffi_type* ts1_type_elements[4];
41
42 Dbls arg = { 1.0, 2.0 };
43
44 ts1_type.size = 0;
45 ts1_type.alignment = 0;
46 ts1_type.type = FFI_TYPE_STRUCT;
47 ts1_type.elements = ts1_type_elements;
48
49 ts1_type_elements[0] = &ffi_type_double;
50 ts1_type_elements[1] = &ffi_type_double;
51 ts1_type_elements[2] = NULL;
52
53 cl_arg_types[0] = &ts1_type;
54
55 /* Initialize the cif */
56 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
57 &ffi_type_void, cl_arg_types) == FFI_OK);
58
59 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK);
60
61 ((void (*)(Dbls))(code))(arg);
62 /* { dg-output "1.0 2.0" } */
63
64 closure_test_fn(arg);
65 /* { dg-output "\n1.0 2.0" } */
66
67 return 0;
68 }