Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

promotion.c
Go to the documentation of this file.
1 /* Area: ffi_call
2 Purpose: Promotion test.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9 static int promotion(signed char sc, signed short ss,
10 unsigned char uc, unsigned short us)
11 {
12 int r = (int) sc + (int) ss + (int) uc + (int) us;
13
14 return r;
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 signed char sc;
24 unsigned char uc;
25 signed short ss;
26 unsigned short us;
27 unsigned long ul;
28
29 args[0] = &ffi_type_schar;
30 args[1] = &ffi_type_sshort;
31 args[2] = &ffi_type_uchar;
32 args[3] = &ffi_type_ushort;
33 values[0] = &sc;
34 values[1] = &ss;
35 values[2] = &uc;
36 values[3] = &us;
37
38 /* Initialize the cif */
39 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
40 &ffi_type_sint, args) == FFI_OK);
41
42 us = 0;
43 ul = 0;
44
45 for (sc = (signed char) -127;
46 sc <= (signed char) 120; sc += 1)
47 for (ss = -30000; ss <= 30000; ss += 10000)
48 for (uc = (unsigned char) 0;
49 uc <= (unsigned char) 200; uc += 20)
50 for (us = 0; us <= 60000; us += 10000)
51 {
52 ul++;
53 ffi_call(&cif, FFI_FN(promotion), &rint, values);
54 CHECK((int)rint == (signed char) sc + (signed short) ss +
55 (unsigned char) uc + (unsigned short) us);
56 }
57 printf("%lu promotion tests run\n", ul);
58 exit(0);
59 }
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
ffi_type_schar
#define ffi_type_schar
Definition: fiddle.h:56
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
CHECK
#define CHECK(sub)
Definition: compile.c:448
rint
double rint(double)
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
char
#define char
Definition: rb_mjit_min_header-2.7.0.h:2876
ffi_type_uchar
#define ffi_type_uchar
Definition: fiddle.h:55
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
main
int main(void)
Definition: promotion.c:17
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