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

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

cls_float.c
Go to the documentation of this file.
1/* Area: closure_call
2 Purpose: Check return value float.
3 Limitations: none.
4 PR: none.
5 Originator: <andreast@gcc.gnu.org> 20030828 */
6
7/* { dg-do run } */
8#include "ffitest.h"
9
10static void cls_ret_float_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
11 void* userdata __UNUSED__)
12 {
13 *(float *)resp = *(float *)args[0];
14
15 printf("%g: %g\n",*(float *)args[0],
16 *(float *)resp);
17 }
18
19 typedef float (*cls_ret_float)(float);
20
21 int main (void)
22{
23 ffi_cif cif;
24 void *code;
25 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
26 ffi_type * cl_arg_types[2];
27 float res;
28
29 cl_arg_types[0] = &ffi_type_float;
30 cl_arg_types[1] = NULL;
31
32 /* Initialize the cif */
33 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
34 &ffi_type_float, cl_arg_types) == FFI_OK);
35
36 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_float_fn, NULL, code) == FFI_OK);
37 res = ((((cls_ret_float)code)(-2122.12)));
38 /* { dg-output "\\-2122.12: \\-2122.12" } */
39 printf("res: %.6f\n", res);
40 /* { dg-output "\nres: \-2122.120117" } */
41 exit(0);
42}
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
cls_ret_float
float(* cls_ret_float)(float)
Definition: cls_float.c:19
main
int main(void)
Definition: cls_float.c:21
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:23
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
NULL
#define NULL
Definition: regenc.h:69
code
Definition: inftree9.h:24