Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
cls_multi_sshortchar.c
Go to the documentation of this file.
1 /* Area: ffi_call, closure_call
2  Purpose: Check passing of multiple signed short/char values.
3  Limitations: none.
4  PR: PR13221.
5  Originator: <andreast@gcc.gnu.org> 20031129 */
6 
7 /* { dg-do run } */
8 #include "ffitest.h"
9 
10 signed short test_func_fn(signed char a1, signed short a2,
11  signed char a3, signed short a4)
12 {
13  signed short result;
14 
15  result = a1 + a2 + a3 + a4;
16 
17  printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
18 
19  return result;
20 
21 }
22 
23 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
24  void *data __UNUSED__)
25 {
26  signed char a1, a3;
27  signed short a2, a4;
28 
29  a1 = *(signed char *)avals[0];
30  a2 = *(signed short *)avals[1];
31  a3 = *(signed char *)avals[2];
32  a4 = *(signed short *)avals[3];
33 
34  *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
35 
36 }
37 
38 typedef signed short (*test_type)(signed char, signed short,
39  signed char, signed short);
40 
41 int main (void)
42 {
43  ffi_cif cif;
44  void *code;
45  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
46  void * args_dbl[5];
47  ffi_type * cl_arg_types[5];
48  ffi_arg res_call;
49  signed char a, c;
50  signed short b, d, res_closure;
51 
52  a = 1;
53  b = 32765;
54  c = 127;
55  d = -128;
56 
57  args_dbl[0] = &a;
58  args_dbl[1] = &b;
59  args_dbl[2] = &c;
60  args_dbl[3] = &d;
61  args_dbl[4] = NULL;
62 
63  cl_arg_types[0] = &ffi_type_schar;
64  cl_arg_types[1] = &ffi_type_sshort;
65  cl_arg_types[2] = &ffi_type_schar;
66  cl_arg_types[3] = &ffi_type_sshort;
67  cl_arg_types[4] = NULL;
68 
69  /* Initialize the cif */
71  &ffi_type_sshort, cl_arg_types) == FFI_OK);
72 
73  ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
74  /* { dg-output "1 32765 127 -128: 32765" } */
75  printf("res: %d\n", (signed short)res_call);
76  /* { dg-output "\nres: 32765" } */
77 
78  CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
79 
80  res_closure = (*((test_type)code))(1, 32765, 127, -128);
81  /* { dg-output "\n1 32765 127 -128: 32765" } */
82  printf("res: %d\n", res_closure);
83  /* { dg-output "\nres: 32765" } */
84 
85  exit(0);
86 }
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
ffi_type_schar
#define ffi_type_schar
Definition: fiddle.h:56
main
int main(void)
Definition: cls_multi_sshortchar.c:41
NULL
#define NULL
Definition: _sdbm.c:101
test_type
signed short(* test_type)(signed char, signed short, signed char, signed short)
Definition: cls_multi_sshortchar.c:38
char
#define char
Definition: rb_mjit_min_header-2.7.1.h:2844
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
short
#define short
Definition: rb_mjit_min_header-2.7.1.h:2845
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
test_func_fn
signed short test_func_fn(signed char a1, signed short a2, signed char a3, signed short a4)
Definition: cls_multi_sshortchar.c:10
exit
void exit(int __status) __attribute__((__noreturn__))
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
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