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

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

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