2009-06-08 Andrew Haley <aph@redhat.com>
[libffi.git] / libffi / testsuite / libffi.call / cls_dbls_struct.c
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 }
21
22 void
23 closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
24 void** args, void* userdata __UNUSED__)
25 {
26 closure_test_fn(*(Dbls*)args[0]);
27 }
28
29 int main(int argc __UNUSED__, char** argv __UNUSED__)
30 {
31 ffi_cif cif;
32
33 #ifndef USING_MMAP
34 static ffi_closure cl;
35 #endif
36
37 ffi_closure* pcl;
38 ffi_type* cl_arg_types[1];
39
40 #ifdef USING_MMAP
41 pcl = allocate_mmap(sizeof(ffi_closure));
42 #else
43 pcl = &cl;
44 #endif
45
46 ffi_type ts1_type;
47 ffi_type* ts1_type_elements[4];
48
49 ts1_type.size = 0;
50 ts1_type.alignment = 0;
51 ts1_type.type = FFI_TYPE_STRUCT;
52 ts1_type.elements = ts1_type_elements;
53
54 ts1_type_elements[0] = &ffi_type_double;
55 ts1_type_elements[1] = &ffi_type_double;
56 ts1_type_elements[2] = NULL;
57
58 cl_arg_types[0] = &ts1_type;
59
60 Dbls arg = { 1.0, 2.0 };
61
62 /* Initialize the cif */
63 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
64 &ffi_type_void, cl_arg_types) == FFI_OK);
65
66 CHECK(ffi_prep_closure(pcl, &cif, closure_test_gn, NULL) == FFI_OK);
67
68 ((void*(*)(Dbls))(pcl))(arg);
69 /* { dg-output "1.0 2.0\n" { xfail x86_64-*-linux-* } } */
70
71 closure_test_fn(arg);
72 /* { dg-output "1.0 2.0\n" } */
73
74 return 0;
75 }