Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
closure_fn6.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  Limitations: none.
5  PR: PR23404
6  Originator: <andreast@gcc.gnu.org> 20050830 */
7 
8 /* { dg-do run } */
9 #include "ffitest.h"
10 
11 static void
12 closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args,
13  void* userdata)
14 {
15  *(ffi_arg*)resp =
16  (int)*(unsigned long long *)args[0] +
17  (int)(*(unsigned long long *)args[1]) +
18  (int)(*(unsigned long long *)args[2]) +
19  (int)*(unsigned long long *)args[3] +
20  (int)(*(int *)args[4]) + (int)(*(double *)args[5]) +
21  (int)*(double *)args[6] + (int)(*(float *)args[7]) +
22  (int)(*(double *)args[8]) + (int)*(double *)args[9] +
23  (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
24  (int)*(int *)args[12] + (int)(*(int *)args[13]) +
25  (int)(*(double *)args[14]) + (int)*(double *)args[15] +
26  (intptr_t)userdata;
27 
28  printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
29  (int)*(unsigned long long *)args[0],
30  (int)(*(unsigned long long *)args[1]),
31  (int)(*(unsigned long long *)args[2]),
32  (int)*(unsigned long long *)args[3],
33  (int)(*(int *)args[4]), (int)(*(double *)args[5]),
34  (int)*(double *)args[6], (int)(*(float *)args[7]),
35  (int)(*(double *)args[8]), (int)*(double *)args[9],
36  (int)(*(int *)args[10]), (int)(*(float *)args[11]),
37  (int)*(int *)args[12], (int)(*(int *)args[13]),
38  (int)(*(double *)args[14]), (int)(*(double *)args[15]),
39  (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
40 
41 }
42 
43 typedef int (*closure_test_type0)(unsigned long long,
44  unsigned long long,
45  unsigned long long,
46  unsigned long long,
47  int, double, double, float, double, double,
48  int, float, int, int, double, double);
49 
50 int main (void)
51 {
52  ffi_cif cif;
53  void *code;
54  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
55  ffi_type * cl_arg_types[17];
56  int res;
57 
58  cl_arg_types[0] = &ffi_type_uint64;
59  cl_arg_types[1] = &ffi_type_uint64;
60  cl_arg_types[2] = &ffi_type_uint64;
61  cl_arg_types[3] = &ffi_type_uint64;
62  cl_arg_types[4] = &ffi_type_sint;
63  cl_arg_types[5] = &ffi_type_double;
64  cl_arg_types[6] = &ffi_type_double;
65  cl_arg_types[7] = &ffi_type_float;
66  cl_arg_types[8] = &ffi_type_double;
67  cl_arg_types[9] = &ffi_type_double;
68  cl_arg_types[10] = &ffi_type_sint;
69  cl_arg_types[11] = &ffi_type_float;
70  cl_arg_types[12] = &ffi_type_sint;
71  cl_arg_types[13] = &ffi_type_sint;
72  cl_arg_types[14] = &ffi_type_double;
73  cl_arg_types[15] = &ffi_type_double;
74  cl_arg_types[16] = NULL;
75 
76  /* Initialize the cif */
78  &ffi_type_sint, cl_arg_types) == FFI_OK);
79 
80  CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn0,
81  (void *) 3 /* userdata */, code) == FFI_OK);
82 
83  res = (*((closure_test_type0)code))
84  (1, 2, 3, 4, 127, 429., 7., 8., 9.5, 10., 11, 12., 13,
85  19, 21., 1.);
86  /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
87  printf("res: %d\n",res);
88  /* { dg-output "\nres: 680" } */
89  exit(0);
90 }
long
#define long
Definition: rb_mjit_min_header-2.7.1.h:2880
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
double
double
Definition: rb_mjit_min_header-2.7.1.h:5923
NULL
#define NULL
Definition: _sdbm.c:101
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
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, int, double, double, float, double, double, int, float, int, int, double, double)
Definition: closure_fn6.c:43
int
__inline__ int
Definition: rb_mjit_min_header-2.7.1.h:2839
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
main
int main(void)
Definition: closure_fn6.c:50
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