Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
closure_fn3.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 /* { dg-do run } */
10 #include "ffitest.h"
11 
12 static void closure_test_fn3(ffi_cif* cif __UNUSED__, void* resp, void** args,
13  void* userdata)
14  {
15  *(ffi_arg*)resp =
16  (int)*(float *)args[0] +(int)(*(float *)args[1]) +
17  (int)(*(float *)args[2]) + (int)*(float *)args[3] +
18  (int)(*(float *)args[4]) + (int)(*(float *)args[5]) +
19  (int)*(float *)args[6] + (int)(*(float *)args[7]) +
20  (int)(*(double *)args[8]) + (int)*(int *)args[9] +
21  (int)(*(float *)args[10]) + (int)(*(float *)args[11]) +
22  (int)*(int *)args[12] + (int)(*(float *)args[13]) +
23  (int)(*(float *)args[14]) + *(int *)args[15] + (intptr_t)userdata;
24 
25  printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
26  (int)*(float *)args[0], (int)(*(float *)args[1]),
27  (int)(*(float *)args[2]), (int)*(float *)args[3],
28  (int)(*(float *)args[4]), (int)(*(float *)args[5]),
29  (int)*(float *)args[6], (int)(*(float *)args[7]),
30  (int)(*(double *)args[8]), (int)*(int *)args[9],
31  (int)(*(float *)args[10]), (int)(*(float *)args[11]),
32  (int)*(int *)args[12], (int)(*(float *)args[13]),
33  (int)(*(float *)args[14]), *(int *)args[15], (int)(intptr_t)userdata,
34  (int)*(ffi_arg *)resp);
35 
36  }
37 
38 typedef int (*closure_test_type3)(float, float, float, float, float, float,
39  float, float, double, int, float, float, int,
40  float, float, int);
41 
42 int main (void)
43 {
44  ffi_cif cif;
45  void *code;
46  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
47  ffi_type * cl_arg_types[17];
48  int res;
49 
50  cl_arg_types[0] = &ffi_type_float;
51  cl_arg_types[1] = &ffi_type_float;
52  cl_arg_types[2] = &ffi_type_float;
53  cl_arg_types[3] = &ffi_type_float;
54  cl_arg_types[4] = &ffi_type_float;
55  cl_arg_types[5] = &ffi_type_float;
56  cl_arg_types[6] = &ffi_type_float;
57  cl_arg_types[7] = &ffi_type_float;
58  cl_arg_types[8] = &ffi_type_double;
59  cl_arg_types[9] = &ffi_type_sint;
60  cl_arg_types[10] = &ffi_type_float;
61  cl_arg_types[11] = &ffi_type_float;
62  cl_arg_types[12] = &ffi_type_sint;
63  cl_arg_types[13] = &ffi_type_float;
64  cl_arg_types[14] = &ffi_type_float;
65  cl_arg_types[15] = &ffi_type_sint;
66  cl_arg_types[16] = NULL;
67 
68  /* Initialize the cif */
70  &ffi_type_sint, cl_arg_types) == FFI_OK);
71 
72  CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn3,
73  (void *) 3 /* userdata */, code) == FFI_OK);
74 
75  res = (*((closure_test_type3)code))
76  (1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9, 10, 11.11, 12.0, 13,
77  19.19, 21.21, 1);
78  /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 19 21 1 3: 135" } */
79  printf("res: %d\n",res);
80  /* { dg-output "\nres: 135" } */
81  exit(0);
82 }
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
closure_test_type3
int(* closure_test_type3)(float, float, float, float, float, float, float, float, double, int, float, float, int, float, float, int)
Definition: closure_fn3.c:38
main
int main(void)
Definition: closure_fn3.c:42
__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
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
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