Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

float1.c
Go to the documentation of this file.
1 /* Area: ffi_call
2 Purpose: Check return value double.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9 #include "float.h"
10
11 typedef union
12 {
13 double d;
14 unsigned char c[sizeof (double)];
15 } value_type;
16
17 #define CANARY 0xba
18
19 static double dblit(float f)
20 {
21 return f/3.0;
22 }
23
24 int main (void)
25 {
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 float f;
30 value_type result[2];
31 unsigned int i;
32
33 args[0] = &ffi_type_float;
34 values[0] = &f;
35
36 /* Initialize the cif */
37 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
38 &ffi_type_double, args) == FFI_OK);
39
40 f = 3.14159;
41
42 /* Put a canary in the return array. This is a regression test for
43 a buffer overrun. */
44 memset(result[1].c, CANARY, sizeof (double));
45
46 ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
47
48 /* These are not always the same!! Check for a reasonable delta */
49
50 CHECK(result[0].d - dblit(f) < DBL_EPSILON);
51
52 /* Check the canary. */
53 for (i = 0; i < sizeof (double); ++i)
54 CHECK(result[1].c[i] == CANARY);
55
56 exit(0);
57
58 }
DBL_EPSILON
#define DBL_EPSILON
Definition: numeric.c:61
CANARY
#define CANARY
Definition: float1.c:17
value_type
enum ruby_value_type value_type
Definition: debug.c:34
memset
void * memset(void *, int, size_t)
large_tag::c
unsigned c
Definition: cls_struct_va1.c:21
value_type::d
double d
Definition: float1.c:13
exit
void exit(int __status) __attribute__((__noreturn__))
main
int main(void)
Definition: float1.c:24
ffitest.h
double
double
Definition: rb_mjit_min_header-2.7.0.h:5923
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
f
#define f
large_tag::d
unsigned d
Definition: cls_struct_va1.c:22
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
value_type
Definition: float1.c:11