Debian Codegraph @

testsuite/libffi.closures/cls_uint.c

raw
1 /* Area: closure_call
2 Purpose: Check return value uint.
3 Limitations: none.
4 PR: none.
5 Originator: <[email protected]> 20030828 */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 static void cls_ret_uint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
11 void* userdata __UNUSED__)
12 {
13 *(ffi_arg *)resp = *(unsigned int *)args[0];
14
15 printf("%d: %d\n",*(unsigned int *)args[0],
16 (int)*(ffi_arg *)(resp));
17
18 CHECK(*(unsigned int *)args[0] == 2147483647);
19 CHECK((int)*(ffi_arg *)(resp) == 2147483647);
20 }
21 typedef unsigned int (*cls_ret_uint)(unsigned int);
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 unsigned int res;
30
31 cl_arg_types[0] = &ffi_type_uint;
32 cl_arg_types[1] = NULL;
33
34 /* Initialize the cif */
35 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
36 &ffi_type_uint, cl_arg_types) == FFI_OK);
37
38 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_uint_fn, NULL, code) == FFI_OK);
39
40 res = (*((cls_ret_uint)code))(2147483647);
41 /* { dg-output "2147483647: 2147483647" } */
42 printf("res: %d\n",res);
43 /* { dg-output "\nres: 2147483647" } */
44 CHECK(res == 2147483647);
45
46 exit(0);
47 }