runtime: adapt memory management to AIX mmap
[official-gcc.git] / libffi / testsuite / libffi.call / cls_dbls_struct.c
blobd6637911e584f9c11dce73d69e7d3da0811d800e
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 */
7 /* { dg-do run } */
9 #include "ffitest.h"
11 typedef struct Dbls {
12 double x;
13 double y;
14 } Dbls;
16 void
17 closure_test_fn(Dbls p)
19 printf("%.1f %.1f\n", p.x, p.y);
22 void
23 closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
24 void** args, void* userdata __UNUSED__)
26 closure_test_fn(*(Dbls*)args[0]);
29 int main(int argc __UNUSED__, char** argv __UNUSED__)
31 ffi_cif cif;
33 void *code;
34 ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
35 ffi_type* cl_arg_types[1];
37 ffi_type ts1_type;
38 ffi_type* ts1_type_elements[4];
40 Dbls arg = { 1.0, 2.0 };
42 ts1_type.size = 0;
43 ts1_type.alignment = 0;
44 ts1_type.type = FFI_TYPE_STRUCT;
45 ts1_type.elements = ts1_type_elements;
47 ts1_type_elements[0] = &ffi_type_double;
48 ts1_type_elements[1] = &ffi_type_double;
49 ts1_type_elements[2] = NULL;
51 cl_arg_types[0] = &ts1_type;
53 /* Initialize the cif */
54 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
55 &ffi_type_void, cl_arg_types) == FFI_OK);
57 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK);
59 ((void*(*)(Dbls))(code))(arg);
60 /* { dg-output "1.0 2.0\n" } */
62 closure_test_fn(arg);
63 /* { dg-output "1.0 2.0\n" } */
65 return 0;