Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

negint.c
Go to the documentation of this file.
1 /* Area: ffi_call
2 Purpose: Check that negative integers are passed correctly.
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 int checking(int a, short b, signed char c)
12 {
13
14 return (a < 0 && b < 0 && c < 0);
15 }
16
17 int main (void)
18 {
19 ffi_cif cif;
20 ffi_type *args[MAX_ARGS];
21 void *values[MAX_ARGS];
22 ffi_arg rint;
23
24 signed int si;
25 signed short ss;
26 signed char sc;
27
28 args[0] = &ffi_type_sint;
29 values[0] = &si;
30 args[1] = &ffi_type_sshort;
31 values[1] = &ss;
32 args[2] = &ffi_type_schar;
33 values[2] = &sc;
34
35 /* Initialize the cif */
36 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
37 &ffi_type_sint, args) == FFI_OK);
38
39 si = -6;
40 ss = -12;
41 sc = -1;
42
43 checking (si, ss, sc);
44
45 ffi_call(&cif, FFI_FN(checking), &rint, values);
46
47 printf ("%d vs %d\n", (int)rint, checking (si, ss, sc));
48
49 CHECK(rint != 0);
50
51 exit (0);
52 }
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__
exit
void exit(int __status) __attribute__((__noreturn__))
main
int main(void)
Definition: negint.c:17
ffitest.h
CHECK
#define CHECK(sub)
Definition: compile.c:448
rint
double rint(double)
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
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