Ruby: ext/fiddle/libffi-3.2.1/testsuite/libffi.call/closure_fn4.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

closure_fn4.c
Go to the documentation of this file.
1/* Area: closure_call
2 Purpose: Check multiple long long values passing.
3 Also, exceed the limit of gpr and fpr registers on PowerPC
4 Darwin.
5 Limitations: none.
6 PR: none.
7 Originator: <andreast@gcc.gnu.org> 20031026 */
8
9/* { dg-do run } */
10
11#include "ffitest.h"
12
13static void
14closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args,
15 void* userdata)
16{
17 *(ffi_arg*)resp =
18 (int)*(unsigned long long *)args[0] + (int)*(unsigned long long *)args[1] +
19 (int)*(unsigned long long *)args[2] + (int)*(unsigned long long *)args[3] +
20 (int)*(unsigned long long *)args[4] + (int)*(unsigned long long *)args[5] +
21 (int)*(unsigned long long *)args[6] + (int)*(unsigned long long *)args[7] +
22 (int)*(unsigned long long *)args[8] + (int)*(unsigned long long *)args[9] +
23 (int)*(unsigned long long *)args[10] +
24 (int)*(unsigned long long *)args[11] +
25 (int)*(unsigned long long *)args[12] +
26 (int)*(unsigned long long *)args[13] +
27 (int)*(unsigned long long *)args[14] +
28 *(int *)args[15] + (intptr_t)userdata;
29
30 printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
31 (int)*(unsigned long long *)args[0],
32 (int)*(unsigned long long *)args[1],
33 (int)*(unsigned long long *)args[2],
34 (int)*(unsigned long long *)args[3],
35 (int)*(unsigned long long *)args[4],
36 (int)*(unsigned long long *)args[5],
37 (int)*(unsigned long long *)args[6],
38 (int)*(unsigned long long *)args[7],
39 (int)*(unsigned long long *)args[8],
40 (int)*(unsigned long long *)args[9],
41 (int)*(unsigned long long *)args[10],
42 (int)*(unsigned long long *)args[11],
43 (int)*(unsigned long long *)args[12],
44 (int)*(unsigned long long *)args[13],
45 (int)*(unsigned long long *)args[14],
46 *(int *)args[15],
47 (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
48
49}
50
51 typedef int (*closure_test_type0)(unsigned long long, unsigned long long,
52 unsigned long long, unsigned long long,
53 unsigned long long, unsigned long long,
54 unsigned long long, unsigned long long,
55 unsigned long long, unsigned long long,
56 unsigned long long, unsigned long long,
57 unsigned long long, unsigned long long,
58 unsigned long long, int);
59
60 int main (void)
61{
62 ffi_cif cif;
63 void *code;
64 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
65 ffi_type * cl_arg_types[17];
66 int i, res;
67
68 for (i = 0; i < 15; i++) {
69 cl_arg_types[i] = &ffi_type_uint64;
70 }
71 cl_arg_types[15] = &ffi_type_sint;
72 cl_arg_types[16] = NULL;
73
74 /* Initialize the cif */
75 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
76 &ffi_type_sint, cl_arg_types) == FFI_OK);
77
78 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn0,
79 (void *) 3 /* userdata */, code) == FFI_OK);
80
81 res = (*((closure_test_type0)code))
82 (1LL, 2LL, 3LL, 4LL, 127LL, 429LL, 7LL, 8LL, 9LL, 10LL, 11LL, 12LL,
83 13LL, 19LL, 21LL, 1);
84 /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
85 printf("res: %d\n",res);
86 /* { dg-output "\nres: 680" } */
87
88 exit(0);
89}
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
closure_test_type0
int(* closure_test_type0)(unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, int)
Definition: closure_fn4.c:51
main
int main(void)
Definition: closure_fn4.c:60
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:23
long
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
ffi_prep_cif
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226
NULL
#define NULL
Definition: regenc.h:69
code
Definition: inftree9.h:24
intptr_t
int intptr_t
Definition: win32.h:90