Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

strlen4.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, int i)
12 {
13 return (size_t) ((int) strlen(s) + (int) a + i);
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 int v1;
24 float v2;
25 args[2] = &ffi_type_sint;
26 args[1] = &ffi_type_pointer;
27 args[0] = &ffi_type_float;
28 values[2] = (void*) &v1;
29 values[1] = (void*) &s;
30 values[0] = (void*) &v2;
31
32 /* Initialize the cif */
33 CHECK(ffi_prep_cif(&cif, ABI_NUM, 3,
34 &ffi_type_sint, args) == FFI_OK);
35
36 s = "a";
37 v1 = 1;
38 v2 = 0.0;
39 ffi_call(&cif, FFI_FN(my_f), &rint, values);
40 CHECK(rint == 2);
41
42 s = "1234567";
43 v2 = -1.0;
44 v1 = -2;
45 ffi_call(&cif, FFI_FN(my_f), &rint, values);
46 CHECK(rint == 4);
47
48 s = "1234567890123456789012345";
49 v2 = 1.0;
50 v1 = 2;
51 ffi_call(&cif, FFI_FN(my_f), &rint, values);
52 CHECK(rint == 28);
53
54 exit(0);
55 }
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
ABI_NUM
#define ABI_NUM
Definition: ffitest.h:35
exit
void exit(int __status) __attribute__((__noreturn__))
strlen
size_t strlen(const char *)
ffitest.h
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
CHECK
#define CHECK(sub)
Definition: compile.c:448
rint
double rint(double)
main
int main(void)
Definition: strlen4.c:16
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
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813