Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
ext
fiddle
libffi-3.2.1
testsuite
libffi.call
cls_multi_schar.c
Go to the documentation of this file.
1
/* Area: ffi_call, closure_call
2
Purpose: Check passing of multiple signed char values.
3
Limitations: none.
4
PR: PR13221.
5
Originator: <hos@tamanegi.org> 20031129 */
6
7
/* { dg-do run } */
8
#include "
ffitest.h
"
9
10
signed
char
test_func_fn
(
signed
char
a1,
signed
char
a2)
11
{
12
signed
char
result;
13
14
result = a1 + a2;
15
16
printf
(
"%d %d: %d\n"
, a1, a2, result);
17
18
return
result;
19
20
}
21
22
static
void
test_func_gn(ffi_cif *cif
__UNUSED__
,
void
*rval,
void
**avals,
23
void
*data
__UNUSED__
)
24
{
25
signed
char
a1, a2;
26
27
a1 = *(
signed
char
*)avals[0];
28
a2 = *(
signed
char
*)avals[1];
29
30
*(
ffi_arg
*)rval =
test_func_fn
(a1, a2);
31
32
}
33
34
typedef
signed
char
(*
test_type
)(
signed
char
,
signed
char
);
35
36
int
main
(
void
)
37
{
38
ffi_cif cif;
39
void
*code;
40
ffi_closure *pcl = ffi_closure_alloc(
sizeof
(ffi_closure), &code);
41
void
* args_dbl[3];
42
ffi_type * cl_arg_types[3];
43
ffi_arg
res_call;
44
signed
char
a, b, res_closure;
45
46
a = 2;
47
b = 125;
48
49
args_dbl[0] = &a;
50
args_dbl[1] = &b;
51
args_dbl[2] =
NULL
;
52
53
cl_arg_types[0] = &
ffi_type_schar
;
54
cl_arg_types[1] = &
ffi_type_schar
;
55
cl_arg_types[2] =
NULL
;
56
57
/* Initialize the cif */
58
CHECK
(
ffi_prep_cif
(&cif,
FFI_DEFAULT_ABI
, 2,
59
&
ffi_type_schar
, cl_arg_types) == FFI_OK);
60
61
ffi_call
(&cif, FFI_FN(
test_func_fn
), &res_call, args_dbl);
62
/* { dg-output "2 125: 127" } */
63
printf
(
"res: %d\n"
, (
signed
char
)res_call);
64
/* { dg-output "\nres: 127" } */
65
66
CHECK
(
ffi_prep_closure_loc
(pcl, &cif, test_func_gn,
NULL
, code) == FFI_OK);
67
68
res_closure = (*((
test_type
)code))(2, 125);
69
/* { dg-output "\n2 125: 127" } */
70
printf
(
"res: %d\n"
, res_closure);
71
/* { dg-output "\nres: 127" } */
72
73
exit
(0);
74
}
ffi_arg
unsigned long ffi_arg
Definition:
ffitarget.h:30
ffi_type_schar
#define ffi_type_schar
Definition:
fiddle.h:56
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition:
_sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
test_type
signed char(* test_type)(signed char, signed char)
Definition:
cls_multi_schar.c:34
ffitest.h
main
int main(void)
Definition:
cls_multi_schar.c:36
__UNUSED__
#define __UNUSED__
Definition:
ffitest.h:28
CHECK
#define CHECK(sub)
Definition:
compile.c:448
test_func_fn
signed char test_func_fn(signed char a1, signed char a2)
Definition:
cls_multi_schar.c:10
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition:
ffitarget.h:38
char
#define char
Definition:
rb_mjit_min_header-2.7.0.h:2876
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
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
Generated by
1.8.17