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

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

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"
9static 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_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
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
MAX_ARGS
#define MAX_ARGS
Definition: function.c:17
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
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