Debian Codegraph @

testsuite/libffi.closures/cls_multi_uchar.c

raw
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned char 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 char test_func_fn(unsigned char a1, unsigned char a2,
11 unsigned char a3, unsigned char a4)
12 {
13 unsigned char result;
14
15 result = a1 + a2 + a3 + a4;
16
17 printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
18
19 CHECK(a1 == 1);
20 CHECK(a2 == 2);
21 CHECK(a3 == 127);
22 CHECK(a4 == 125);
23 CHECK(result == 255);
24
25 return result;
26
27 }
28
29 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
30 void *data __UNUSED__)
31 {
32 unsigned char a1, a2, a3, a4;
33
34 a1 = *(unsigned char *)avals[0];
35 a2 = *(unsigned char *)avals[1];
36 a3 = *(unsigned char *)avals[2];
37 a4 = *(unsigned char *)avals[3];
38
39 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
40
41 }
42
43 typedef unsigned char (*test_type)(unsigned char, unsigned char,
44 unsigned char, unsigned char);
45
46 void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
47 void *data __UNUSED__)
48 {
49 printf("%d %d %d %d\n", *(unsigned char *)avals[0],
50 *(unsigned char *)avals[1], *(unsigned char *)avals[2],
51 *(unsigned char *)avals[3]);
52 }
53 int main (void)
54 {
55 ffi_cif cif;
56 void *code;
57 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
58 void * args_dbl[5];
59 ffi_type * cl_arg_types[5];
60 ffi_arg res_call;
61 unsigned char a, b, c, d, res_closure;
62
63 a = 1;
64 b = 2;
65 c = 127;
66 d = 125;
67
68 args_dbl[0] = &a;
69 args_dbl[1] = &b;
70 args_dbl[2] = &c;
71 args_dbl[3] = &d;
72 args_dbl[4] = NULL;
73
74 cl_arg_types[0] = &ffi_type_uchar;
75 cl_arg_types[1] = &ffi_type_uchar;
76 cl_arg_types[2] = &ffi_type_uchar;
77 cl_arg_types[3] = &ffi_type_uchar;
78 cl_arg_types[4] = NULL;
79
80 /* Initialize the cif */
81 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
82 &ffi_type_uchar, cl_arg_types) == FFI_OK);
83
84 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
85 /* { dg-output "1 2 127 125: 255" } */
86 printf("res: %d\n", (unsigned char)res_call);
87 /* { dg-output "\nres: 255" } */
88 CHECK((unsigned char)res_call == 255);
89
90 CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
91
92 res_closure = (*((test_type)code))(1, 2, 127, 125);
93 /* { dg-output "\n1 2 127 125: 255" } */
94 printf("res: %d\n", res_closure);
95 /* { dg-output "\nres: 255" } */
96 CHECK(res_closure == 255);
97
98 exit(0);
99 }