Debian Codegraph @

testsuite/libffi.closures/cls_multi_ushort.c

raw
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned short values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <[email protected]> 20031129 */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 static unsigned short test_func_fn(unsigned short a1, unsigned short a2)
11 {
12 unsigned short result;
13
14 result = a1 + a2;
15
16 printf("%d %d: %d\n", a1, a2, result);
17
18 CHECK(a1 == 2);
19 CHECK(a2 == 32765);
20 CHECK(result == 32767);
21
22 return result;
23 }
24
25 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
26 void *data __UNUSED__)
27 {
28 unsigned short a1, a2;
29
30 a1 = *(unsigned short *)avals[0];
31 a2 = *(unsigned short *)avals[1];
32
33 *(ffi_arg *)rval = test_func_fn(a1, a2);
34
35 }
36
37 typedef unsigned short (*test_type)(unsigned short, unsigned short);
38
39 int main (void)
40 {
41 ffi_cif cif;
42 void *code;
43 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
44 void * args_dbl[3];
45 ffi_type * cl_arg_types[3];
46 ffi_arg res_call;
47 unsigned short a, b, res_closure;
48
49 a = 2;
50 b = 32765;
51
52 args_dbl[0] = &a;
53 args_dbl[1] = &b;
54 args_dbl[2] = NULL;
55
56 cl_arg_types[0] = &ffi_type_ushort;
57 cl_arg_types[1] = &ffi_type_ushort;
58 cl_arg_types[2] = NULL;
59
60 /* Initialize the cif */
61 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
62 &ffi_type_ushort, cl_arg_types) == FFI_OK);
63
64 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
65 /* { dg-output "2 32765: 32767" } */
66 printf("res: %d\n", (unsigned short)res_call);
67 /* { dg-output "\nres: 32767" } */
68
69 CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
70
71 res_closure = (*((test_type)code))(2, 32765);
72 /* { dg-output "\n2 32765: 32767" } */
73 printf("res: %d\n", res_closure);
74 /* { dg-output "\nres: 32767" } */
75 CHECK(res_closure == 32767);
76
77 exit(0);
78 }