1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned short/char values.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
10 unsigned short test_func_fn(unsigned char a1
, unsigned short a2
,
11 unsigned char a3
, unsigned short a4
)
13 unsigned short result
;
15 result
= a1
+ a2
+ a3
+ a4
;
17 printf("%d %d %d %d: %d\n", a1
, a2
, a3
, a4
, result
);
23 static void test_func_gn(ffi_cif
*cif __UNUSED__
, void *rval
, void **avals
,
24 void *data __UNUSED__
)
27 unsigned short a2
, a4
;
29 a1
= *(unsigned char *)avals
[0];
30 a2
= *(unsigned short *)avals
[1];
31 a3
= *(unsigned char *)avals
[2];
32 a4
= *(unsigned short *)avals
[3];
34 *(ffi_arg
*)rval
= test_func_fn(a1
, a2
, a3
, a4
);
38 typedef unsigned short (*test_type
)(unsigned char, unsigned short,
39 unsigned char, unsigned short);
45 static ffi_closure cl
;
49 ffi_type
* cl_arg_types
[5];
52 unsigned short b
, d
, res_closure
;
55 pcl
= allocate_mmap (sizeof(ffi_closure
));
71 cl_arg_types
[0] = &ffi_type_uchar
;
72 cl_arg_types
[1] = &ffi_type_ushort
;
73 cl_arg_types
[2] = &ffi_type_uchar
;
74 cl_arg_types
[3] = &ffi_type_ushort
;
75 cl_arg_types
[4] = NULL
;
77 /* Initialize the cif */
78 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 4,
79 &ffi_type_ushort
, cl_arg_types
) == FFI_OK
);
81 ffi_call(&cif
, FFI_FN(test_func_fn
), &res_call
, args_dbl
);
82 /* { dg-output "1 2 127 128: 258" } */
83 printf("res: %d\n", (unsigned short)res_call
);
84 /* { dg-output "\nres: 258" } */
86 CHECK(ffi_prep_closure(pcl
, &cif
, test_func_gn
, NULL
) == FFI_OK
);
88 res_closure
= (*((test_type
)pcl
))(1, 2, 127, 128);
89 /* { dg-output "\n1 2 127 128: 258" } */
90 printf("res: %d\n", res_closure
);
91 /* { dg-output "\nres: 258" } */