Ruby  2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
closure_loc_fn0.c
Go to the documentation of this file.
1 /* Area: closure_call
2  Purpose: Check multiple values passing from different type.
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> 20030828 */
8 
9 
10 
11 
12 /* { dg-do run } */
13 #include "ffitest.h"
14 
15 static void
16 closure_loc_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args,
17  void* userdata)
18 {
19  *(ffi_arg*)resp =
20  (int)*(unsigned long long *)args[0] + (int)(*(int *)args[1]) +
21  (int)(*(unsigned long long *)args[2]) + (int)*(int *)args[3] +
22  (int)(*(signed short *)args[4]) +
23  (int)(*(unsigned long long *)args[5]) +
24  (int)*(int *)args[6] + (int)(*(int *)args[7]) +
25  (int)(*(double *)args[8]) + (int)*(int *)args[9] +
26  (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
27  (int)*(int *)args[12] + (int)(*(int *)args[13]) +
28  (int)(*(int *)args[14]) + *(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], (int)(*(int *)args[1]),
32  (int)(*(unsigned long long *)args[2]),
33  (int)*(int *)args[3], (int)(*(signed short *)args[4]),
34  (int)(*(unsigned long long *)args[5]),
35  (int)*(int *)args[6], (int)(*(int *)args[7]),
36  (int)(*(double *)args[8]), (int)*(int *)args[9],
37  (int)(*(int *)args[10]), (int)(*(float *)args[11]),
38  (int)*(int *)args[12], (int)(*(int *)args[13]),
39  (int)(*(int *)args[14]),*(int *)args[15],
40  (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
41 
42 }
43 
44 typedef int (*closure_loc_test_type0)(unsigned long long, int, unsigned long long,
45  int, signed short, unsigned long long, int,
46  int, double, int, int, float, int, int,
47  int, int);
48 
49 int main (void)
50 {
51  ffi_cif cif;
52  ffi_closure *pcl;
53  ffi_type * cl_arg_types[17];
54  int res;
55  void *codeloc;
56 
57  cl_arg_types[0] = &ffi_type_uint64;
58  cl_arg_types[1] = &ffi_type_sint;
59  cl_arg_types[2] = &ffi_type_uint64;
60  cl_arg_types[3] = &ffi_type_sint;
61  cl_arg_types[4] = &ffi_type_sshort;
62  cl_arg_types[5] = &ffi_type_uint64;
63  cl_arg_types[6] = &ffi_type_sint;
64  cl_arg_types[7] = &ffi_type_sint;
65  cl_arg_types[8] = &ffi_type_double;
66  cl_arg_types[9] = &ffi_type_sint;
67  cl_arg_types[10] = &ffi_type_sint;
68  cl_arg_types[11] = &ffi_type_float;
69  cl_arg_types[12] = &ffi_type_sint;
70  cl_arg_types[13] = &ffi_type_sint;
71  cl_arg_types[14] = &ffi_type_sint;
72  cl_arg_types[15] = &ffi_type_sint;
73  cl_arg_types[16] = NULL;
74 
75  /* Initialize the cif */
77  &ffi_type_sint, cl_arg_types) == FFI_OK);
78 
79  pcl = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
80  CHECK(pcl != NULL);
81  CHECK(codeloc != NULL);
82 
83  CHECK(ffi_prep_closure_loc(pcl, &cif, closure_loc_test_fn0,
84  (void *) 3 /* userdata */, codeloc) == FFI_OK);
85 
86  CHECK(memcmp(pcl, codeloc, sizeof(*pcl)) == 0);
87 
88  res = (*((closure_loc_test_type0)codeloc))
89  (1LL, 2, 3LL, 4, 127, 429LL, 7, 8, 9.5, 10, 11, 12, 13,
90  19, 21, 1);
91  /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
92  printf("res: %d\n",res);
93  /* { dg-output "\nres: 680" } */
94  exit(0);
95 }
main
int main(void)
Definition: closure_loc_fn0.c:49
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
int
__inline__ int
Definition: rb_mjit_min_header-2.7.2.h:2845
long
#define long
Definition: rb_mjit_min_header-2.7.2.h:2889
short
#define short
Definition: rb_mjit_min_header-2.7.2.h:2885
NULL
#define NULL
Definition: _sdbm.c:101
ffitest.h
closure_loc_test_type0
int(* closure_loc_test_type0)(unsigned long long, int, unsigned long long, int, signed short, unsigned long long, int, int, double, int, int, float, int, int, int, int)
Definition: closure_loc_fn0.c:44
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
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
exit
void exit(int __status) __attribute__((__noreturn__))
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
intptr_t
int intptr_t
Definition: win32.h:90
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
double
double
Definition: rb_mjit_min_header-2.7.2.h:5919