ยปCore Development>Code coverage>Modules/_ctypes/libffi/testsuite/libffi.call/closure_simple.c

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/closure_simple.c

#countcontent
1n/a/* Area: closure_call
2n/a Purpose: Check simple closure handling with all ABIs
3n/a Limitations: none.
4n/a PR: none.
5n/a Originator: <twalljava@dev.java.net> */
6n/a
7n/a/* { dg-do run } */
8n/a#include "ffitest.h"
9n/a
10n/astatic void
11n/aclosure_test(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata)
12n/a{
13n/a *(ffi_arg*)resp =
14n/a (int)*(int *)args[0] + (int)(*(int *)args[1])
15n/a + (int)(*(int *)args[2]) + (int)(*(int *)args[3])
16n/a + (int)(intptr_t)userdata;
17n/a
18n/a printf("%d %d %d %d: %d\n",
19n/a (int)*(int *)args[0], (int)(*(int *)args[1]),
20n/a (int)(*(int *)args[2]), (int)(*(int *)args[3]),
21n/a (int)*(ffi_arg *)resp);
22n/a
23n/a}
24n/a
25n/atypedef int (ABI_ATTR *closure_test_type0)(int, int, int, int);
26n/a
27n/aint main (void)
28n/a{
29n/a ffi_cif cif;
30n/a void *code;
31n/a ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
32n/a ffi_type * cl_arg_types[17];
33n/a int res;
34n/a
35n/a cl_arg_types[0] = &ffi_type_uint;
36n/a cl_arg_types[1] = &ffi_type_uint;
37n/a cl_arg_types[2] = &ffi_type_uint;
38n/a cl_arg_types[3] = &ffi_type_uint;
39n/a cl_arg_types[4] = NULL;
40n/a
41n/a /* Initialize the cif */
42n/a CHECK(ffi_prep_cif(&cif, ABI_NUM, 4,
43n/a &ffi_type_sint, cl_arg_types) == FFI_OK);
44n/a
45n/a CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test,
46n/a (void *) 3 /* userdata */, code) == FFI_OK);
47n/a
48n/a res = (*(closure_test_type0)code)(0, 1, 2, 3);
49n/a /* { dg-output "0 1 2 3: 9" } */
50n/a
51n/a printf("res: %d\n",res);
52n/a /* { dg-output "\nres: 9" } */
53n/a
54n/a exit(0);
55n/a}