1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned char values.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
10 unsigned char test_func_fn(unsigned char a1
, unsigned char a2
,
11 unsigned char a3
, unsigned char a4
)
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__
)
26 unsigned char a1
, a2
, a3
, a4
;
28 a1
= *(unsigned char *)avals
[0];
29 a2
= *(unsigned char *)avals
[1];
30 a3
= *(unsigned char *)avals
[2];
31 a4
= *(unsigned char *)avals
[3];
33 *(ffi_arg
*)rval
= test_func_fn(a1
, a2
, a3
, a4
);
37 typedef unsigned char (*test_type
)(unsigned char, unsigned char,
38 unsigned char, unsigned char);
40 void test_func(ffi_cif
*cif __UNUSED__
, void *rval __UNUSED__
, void **avals
,
41 void *data __UNUSED__
)
43 printf("%d %d %d %d\n", *(unsigned char *)avals
[0],
44 *(unsigned char *)avals
[1], *(unsigned char *)avals
[2],
45 *(unsigned char *)avals
[3]);
51 static ffi_closure cl
;
55 ffi_type
* cl_arg_types
[5];
57 unsigned char a
, b
, c
, d
, res_closure
;
60 pcl
= allocate_mmap (sizeof(ffi_closure
));
76 cl_arg_types
[0] = &ffi_type_uchar
;
77 cl_arg_types
[1] = &ffi_type_uchar
;
78 cl_arg_types
[2] = &ffi_type_uchar
;
79 cl_arg_types
[3] = &ffi_type_uchar
;
80 cl_arg_types
[4] = NULL
;
82 /* Initialize the cif */
83 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 4,
84 &ffi_type_uchar
, cl_arg_types
) == FFI_OK
);
86 ffi_call(&cif
, FFI_FN(test_func_fn
), &res_call
, args_dbl
);
87 /* { dg-output "1 2 127 125: 255" } */
88 printf("res: %d\n", (unsigned char)res_call
);
89 /* { dg-output "\nres: 255" } */
91 CHECK(ffi_prep_closure(pcl
, &cif
, test_func_gn
, NULL
) == FFI_OK
);
93 res_closure
= (*((test_type
)pcl
))(1, 2, 127, 125);
94 /* { dg-output "\n1 2 127 125: 255" } */
95 printf("res: %d\n", res_closure
);
96 /* { dg-output "\nres: 255" } */