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

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

strlen.c
Go to the documentation of this file.
1/* Area: ffi_call
2 Purpose: Check strlen function call.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7/* { dg-do run } */
8#include "ffitest.h"
9
10static size_t ABI_ATTR my_strlen(char *s)
11{
12 return (strlen(s));
13}
14
15 int main (void)
16{
17 ffi_cif cif;
18 ffi_type *args[MAX_ARGS];
19 void *values[MAX_ARGS];
20 ffi_arg rint;
21 char *s;
22
23 args[0] = &ffi_type_pointer;
24 values[0] = (void*) &s;
25
26 /* Initialize the cif */
27 CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
28 &ffi_type_sint, args) == FFI_OK);
29
30 s = "a";
31 ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
32 CHECK(rint == 1);
33
34 s = "1234567";
35 ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
36 CHECK(rint == 7);
37
38 s = "1234567890123456789012345";
39 ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
40 CHECK(rint == 25);
41
42 exit (0);
43}
44
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
ABI_NUM
#define ABI_NUM
Definition: ffitest.h:35
ABI_ATTR
#define ABI_ATTR
Definition: ffitest.h:36
MAX_ARGS
#define MAX_ARGS
Definition: function.c:17
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
strlen
size_t strlen(const char *)
main
int main(void)
Definition: strlen.c:15