Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
ext
fiddle
libffi-3.2.1
testsuite
libffi.call
cls_dbls_struct.c
Go to the documentation of this file.
1
/* Area: ffi_call, closure_call
2
Purpose: Check double arguments in structs.
3
Limitations: none.
4
PR: none.
5
Originator: Blake Chaffin 6/23/2007 */
6
7
/* { dg-do run } */
8
9
#include "
ffitest.h
"
10
11
typedef
struct
Dbls
{
12
double
x
;
13
double
y
;
14
}
Dbls
;
15
16
void
17
closure_test_fn
(
Dbls
p)
18
{
19
printf
(
"%.1f %.1f\n"
, p.
x
, p.
y
);
20
}
21
22
void
23
closure_test_gn
(ffi_cif* cif
__UNUSED__
,
void
* resp
__UNUSED__
,
24
void
** args,
void
* userdata
__UNUSED__
)
25
{
26
closure_test_fn
(*(
Dbls
*)args[0]);
27
}
28
29
int
main
(
int
argc
__UNUSED__
,
char
**
argv
__UNUSED__
)
30
{
31
ffi_cif cif;
32
33
void
*code;
34
ffi_closure* pcl = ffi_closure_alloc(
sizeof
(ffi_closure), &code);
35
ffi_type* cl_arg_types[1];
36
37
ffi_type ts1_type;
38
ffi_type* ts1_type_elements[4];
39
40
Dbls
arg
= { 1.0, 2.0 };
41
42
ts1_type.size = 0;
43
ts1_type.alignment = 0;
44
ts1_type.type = FFI_TYPE_STRUCT;
45
ts1_type.elements = ts1_type_elements;
46
47
ts1_type_elements[0] = &ffi_type_double;
48
ts1_type_elements[1] = &ffi_type_double;
49
ts1_type_elements[2] =
NULL
;
50
51
cl_arg_types[0] = &ts1_type;
52
53
/* Initialize the cif */
54
CHECK
(
ffi_prep_cif
(&cif,
FFI_DEFAULT_ABI
, 1,
55
&
ffi_type_void
, cl_arg_types) == FFI_OK);
56
57
CHECK
(
ffi_prep_closure_loc
(pcl, &cif,
closure_test_gn
,
NULL
, code) == FFI_OK);
58
59
((
void
*(*)(
Dbls
))(code))(
arg
);
60
/* { dg-output "1.0 2.0\n" } */
61
62
closure_test_fn
(
arg
);
63
/* { dg-output "1.0 2.0\n" } */
64
65
return
0;
66
}
Dbls::y
double y
Definition:
cls_dbls_struct.c:13
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition:
_sdbm.c:101
ffitest.h
main
int main(int argc __UNUSED__, char **argv __UNUSED__)
Definition:
cls_dbls_struct.c:29
Dbls
Definition:
cls_dbls_struct.c:11
ffi_type_void
const ffi_type ffi_type_void
Definition:
types.c:63
__UNUSED__
#define __UNUSED__
Definition:
ffitest.h:28
CHECK
#define CHECK(sub)
Definition:
compile.c:448
closure_test_fn
void closure_test_fn(Dbls p)
Definition:
cls_dbls_struct.c:17
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition:
ffitarget.h:38
closure_test_gn
void closure_test_gn(ffi_cif *cif __UNUSED__, void *resp __UNUSED__, void **args, void *userdata __UNUSED__)
Definition:
cls_dbls_struct.c:23
arg
VALUE arg
Definition:
rb_mjit_min_header-2.7.0.h:5601
argv
char ** argv
Definition:
ruby.c:223
Dbls::x
double x
Definition:
cls_dbls_struct.c:12
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
argc
int argc
Definition:
ruby.c:222
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
Dbls
struct Dbls Dbls
Generated by
1.8.17