Ruby  2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
testclosure.c
Go to the documentation of this file.
1 /* Area: closure_call
2  Purpose: Check return value float.
3  Limitations: none.
4  PR: 41908.
5  Originator: <rfm@gnu.org> 20091102 */
6 
7 /* { dg-do run } */
8 #include "ffitest.h"
9 
10 typedef struct cls_struct_combined {
11  float a;
12  float b;
13  float c;
14  float d;
16 
18 {
19  printf("%g %g %g %g\n",
20  arg.a, arg.b,
21  arg.c, arg.d);
22  fflush(stdout);
23 }
24 
25 static void
26 cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
27  void** args, void* userdata __UNUSED__)
28 {
29  struct cls_struct_combined a0;
30 
31  a0 = *(struct cls_struct_combined*)(args[0]);
32 
34 }
35 
36 
37 int main (void)
38 {
39  ffi_cif cif;
40  void *code;
41  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
42  ffi_type* cls_struct_fields0[5];
43  ffi_type cls_struct_type0;
44  ffi_type* dbl_arg_types[5];
45 
46  struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0};
47 
48  cls_struct_type0.size = 0;
49  cls_struct_type0.alignment = 0;
50  cls_struct_type0.type = FFI_TYPE_STRUCT;
51  cls_struct_type0.elements = cls_struct_fields0;
52 
53  cls_struct_fields0[0] = &ffi_type_float;
54  cls_struct_fields0[1] = &ffi_type_float;
55  cls_struct_fields0[2] = &ffi_type_float;
56  cls_struct_fields0[3] = &ffi_type_float;
57  cls_struct_fields0[4] = NULL;
58 
59  dbl_arg_types[0] = &cls_struct_type0;
60  dbl_arg_types[1] = NULL;
61 
63  dbl_arg_types) == FFI_OK);
64 
65  CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK);
66 
67  ((void(*)(cls_struct_combined)) (code))(g_dbl);
68  /* { dg-output "4 5 1 8" } */
69  exit(0);
70 }
void
void
Definition: rb_mjit_min_header-2.7.0.h:13273
cls_struct_combined::a
float a
Definition: testclosure.c:11
cls_struct_combined
struct cls_struct_combined cls_struct_combined
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
cls_struct_combined::d
float d
Definition: testclosure.c:14
cls_struct_combined::b
float b
Definition: testclosure.c:12
main
int main(void)
Definition: testclosure.c:37
cls_struct_combined
Definition: nested_struct.c:23
ffi_type_void
const ffi_type ffi_type_void
Definition: types.c:63
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
fflush
int fflush(FILE *)
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
cls_struct_combined_fn
void cls_struct_combined_fn(struct cls_struct_combined arg)
Definition: testclosure.c:17
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.0.h:5601
stdout
#define stdout
Definition: rb_mjit_min_header-2.7.0.h:1484
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
cls_struct_combined::c
float c
Definition: testclosure.c:13
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