Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
ext
fiddle
libffi-3.2.1
testsuite
libffi.call
strlen3.c
Go to the documentation of this file.
1
/* Area: ffi_call
2
Purpose: Check strlen function call with additional arguments.
3
Limitations: none.
4
PR: none.
5
Originator: From the original ffitest.c */
6
7
/* { dg-do run } */
8
9
#include "
ffitest.h
"
10
11
static
size_t
ABI_ATTR
my_f(
float
a,
char
*s)
12
{
13
return
(
size_t
) ((
int
)
strlen
(s) + (
int
) a);
14
}
15
16
int
main
(
void
)
17
{
18
ffi_cif cif;
19
ffi_type *args[
MAX_ARGS
];
20
void
*values[
MAX_ARGS
];
21
ffi_arg
rint
;
22
char
*s;
23
float
v2;
24
args[1] = &ffi_type_pointer;
25
args[0] = &ffi_type_float;
26
values[1] = (
void
*) &s;
27
values[0] = (
void
*) &v2;
28
29
/* Initialize the cif */
30
CHECK
(
ffi_prep_cif
(&cif,
ABI_NUM
, 2,
31
&ffi_type_sint, args) == FFI_OK);
32
33
s =
"a"
;
34
v2 = 0.0;
35
ffi_call
(&cif, FFI_FN(my_f), &
rint
, values);
36
CHECK
(
rint
== 1);
37
38
s =
"1234567"
;
39
v2 = -1.0;
40
ffi_call
(&cif, FFI_FN(my_f), &
rint
, values);
41
CHECK
(
rint
== 6);
42
43
s =
"1234567890123456789012345"
;
44
v2 = 1.0;
45
ffi_call
(&cif, FFI_FN(my_f), &
rint
, values);
46
CHECK
(
rint
== 26);
47
48
exit
(0);
49
}
ffi_arg
unsigned long ffi_arg
Definition:
ffitarget.h:30
int
__inline__ int
Definition:
rb_mjit_min_header-2.7.2.h:2877
ABI_NUM
#define ABI_NUM
Definition:
ffitest.h:35
strlen
size_t strlen(const char *)
main
int main(void)
Definition:
strlen3.c:16
ffitest.h
rint
double rint(double)
CHECK
#define CHECK(sub)
Definition:
compile.c:448
ABI_ATTR
#define ABI_ATTR
Definition:
ffitest.h:36
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
MAX_ARGS
#define MAX_ARGS
Definition:
function.c:15
exit
void exit(int __status) __attribute__((__noreturn__))
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition:
ffi.c:813
Generated by
1.8.19