1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing with different structure size.
5 Originator: <andreast@gcc.gnu.org> 20030828 */
10 typedef struct my_ffi_struct
{
16 my_ffi_struct
callee(struct my_ffi_struct a1
, struct my_ffi_struct a2
)
18 struct my_ffi_struct result
;
19 result
.a
= a1
.a
+ a2
.a
;
20 result
.b
= a1
.b
+ a2
.b
;
21 result
.c
= a1
.c
+ a2
.c
;
24 printf("%g %g %g %g %g %g: %g %g %g\n", a1
.a
, a1
.b
, a1
.c
,
25 a2
.a
, a2
.b
, a2
.c
, result
.a
, result
.b
, result
.c
);
30 void stub(ffi_cif
* cif
, void* resp
, void** args
, void* userdata
)
32 struct my_ffi_struct a1
;
33 struct my_ffi_struct a2
;
35 a1
= *(struct my_ffi_struct
*)(args
[0]);
36 a2
= *(struct my_ffi_struct
*)(args
[1]);
38 *(my_ffi_struct
*)resp
= callee(a1
, a2
);
44 ffi_type
* my_ffi_struct_fields
[4];
45 ffi_type my_ffi_struct_type
;
47 static ffi_closure cl
;
48 ffi_closure
*pcl
= &cl
;
50 ffi_type
* arg_types
[3];
52 struct my_ffi_struct g
= { 1.0, 2.0, 3.0 };
53 struct my_ffi_struct f
= { 1.0, 2.0, 3.0 };
54 struct my_ffi_struct res
;
56 my_ffi_struct_type
.size
= 0;
57 my_ffi_struct_type
.alignment
= 0;
58 my_ffi_struct_type
.type
= FFI_TYPE_STRUCT
;
59 my_ffi_struct_type
.elements
= my_ffi_struct_fields
;
61 my_ffi_struct_fields
[0] = &ffi_type_double
;
62 my_ffi_struct_fields
[1] = &ffi_type_double
;
63 my_ffi_struct_fields
[2] = &ffi_type_double
;
64 my_ffi_struct_fields
[3] = NULL
;
66 arg_types
[0] = &my_ffi_struct_type
;
67 arg_types
[1] = &my_ffi_struct_type
;
70 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &my_ffi_struct_type
,
71 arg_types
) == FFI_OK
);
76 ffi_call(&cif
, FFI_FN(callee
), &res
, args
);
77 /* { dg-output "1 2 3 1 2 3: 2 4 6" } */
83 CHECK(ffi_prep_closure(pcl
, &cif
, stub
, NULL
) == FFI_OK
);
85 res
= ((my_ffi_struct(*)(struct my_ffi_struct
, struct my_ffi_struct
))(pcl
))(g
, f
);
86 /* { dg-output "\n1 2 3 1 2 3: 2 4 6" } */