Debian Codegraph @

testsuite/libffi.closures/cls_schar.c

raw
1 /* Area: closure_call
2 Purpose: Check return value schar.
3 Limitations: none.
4 PR: none.
5 Originator: <[email protected]> 20031108 */
6
7
8
9 /* { dg-do run } */
10 #include "ffitest.h"
11
12 static void cls_ret_schar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
13 void* userdata __UNUSED__)
14 {
15 *(ffi_arg*)resp = *(signed char *)args[0];
16 printf("%d: %d\n",*(signed char *)args[0],
17 (int)*(ffi_arg *)(resp));
18 CHECK(*(signed char *)args[0] == 127);
19 CHECK((int)*(ffi_arg *)(resp) == 127);
20 }
21 typedef signed char (*cls_ret_schar)(signed char);
22
23 int main (void)
24 {
25 ffi_cif cif;
26 void *code;
27 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
28 ffi_type * cl_arg_types[2];
29 signed char res;
30
31 cl_arg_types[0] = &ffi_type_schar;
32 cl_arg_types[1] = NULL;
33
34 /* Initialize the cif */
35 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
36 &ffi_type_schar, cl_arg_types) == FFI_OK);
37
38 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_schar_fn, NULL, code) == FFI_OK);
39
40 res = (*((cls_ret_schar)code))(127);
41 /* { dg-output "127: 127" } */
42 printf("res: %d\n", res);
43 /* { dg-output "\nres: 127" } */
44 CHECK(res == 127);
45
46 exit(0);
47 }