Debian Codegraph @

testsuite/libffi.closures/cls_multi_schar.c

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