1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned short values.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
10 unsigned short test_func_fn(unsigned short a1
, unsigned short a2
)
12 unsigned short result
;
16 printf("%d %d: %d\n", a1
, a2
, result
);
22 static void test_func_gn(ffi_cif
*cif __UNUSED__
, void *rval
, void **avals
,
23 void *data __UNUSED__
)
25 unsigned short a1
, a2
;
27 a1
= *(unsigned short *)avals
[0];
28 a2
= *(unsigned short *)avals
[1];
30 *(ffi_arg
*)rval
= test_func_fn(a1
, a2
);
34 typedef unsigned short (*test_type
)(unsigned short, unsigned short);
40 static ffi_closure cl
;
44 ffi_type
* cl_arg_types
[3];
46 unsigned short a
, b
, res_closure
;
49 pcl
= allocate_mmap (sizeof(ffi_closure
));
61 cl_arg_types
[0] = &ffi_type_ushort
;
62 cl_arg_types
[1] = &ffi_type_ushort
;
63 cl_arg_types
[2] = NULL
;
65 /* Initialize the cif */
66 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2,
67 &ffi_type_ushort
, cl_arg_types
) == FFI_OK
);
69 ffi_call(&cif
, FFI_FN(test_func_fn
), &res_call
, args_dbl
);
70 /* { dg-output "2 32765: 32767" } */
71 printf("res: %d\n", (unsigned short)res_call
);
72 /* { dg-output "\nres: 32767" } */
74 CHECK(ffi_prep_closure(pcl
, &cif
, test_func_gn
, NULL
) == FFI_OK
);
76 res_closure
= (*((test_type
)pcl
))(2, 32765);
77 /* { dg-output "\n2 32765: 32767" } */
78 printf("res: %d\n", res_closure
);
79 /* { dg-output "\nres: 32767" } */