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

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

return_fl2.c
Go to the documentation of this file.
1/* Area: ffi_call
2 Purpose: Check return value float.
3 Limitations: none.
4 PR: none.
5 Originator: <andreast@gcc.gnu.org> 20050212 */
6
7/* { dg-do run } */
8#include "ffitest.h"
9
10/* Use volatile float to avoid false negative on ix86. See PR target/323. */
11static float return_fl(float fl1, float fl2, float fl3, float fl4)
12{
13 volatile float sum;
14
15 sum = fl1 + fl2 + fl3 + fl4;
16 return sum;
17}
18 int main (void)
19{
20 ffi_cif cif;
21 ffi_type *args[MAX_ARGS];
22 void *values[MAX_ARGS];
23 float fl1, fl2, fl3, fl4, rfl;
24 volatile float sum;
25
26 args[0] = &ffi_type_float;
27 args[1] = &ffi_type_float;
28 args[2] = &ffi_type_float;
29 args[3] = &ffi_type_float;
30 values[0] = &fl1;
31 values[1] = &fl2;
32 values[2] = &fl3;
33 values[3] = &fl4;
34
35 /* Initialize the cif */
36 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
37 &ffi_type_float, args) == FFI_OK);
38 fl1 = 127.0;
39 fl2 = 128.0;
40 fl3 = 255.1;
41 fl4 = 512.7;
42
43 ffi_call(&cif, FFI_FN(return_fl), &rfl, values);
44 printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, fl3, fl4));
45
46 sum = fl1 + fl2 + fl3 + fl4;
47 CHECK(rfl == sum);
48 exit(0);
49}
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
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
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: return_fl2.c:18