Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

struct4.c
Go to the documentation of this file.
1 /* Area: ffi_call
2 Purpose: Check structures.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 typedef struct
11 {
12 unsigned ui1;
13 unsigned ui2;
14 unsigned ui3;
15 } test_structure_4;
16
17 static test_structure_4 ABI_ATTR struct4(test_structure_4 ts)
18 {
19 ts.ui3 = ts.ui1 * ts.ui2 * ts.ui3;
20
21 return ts;
22 }
23
24 int main (void)
25 {
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 ffi_type ts4_type;
30 ffi_type *ts4_type_elements[4];
31
32 test_structure_4 ts4_arg;
33
34 /* This is a hack to get a properly aligned result buffer */
35 test_structure_4 *ts4_result =
36 (test_structure_4 *) malloc (sizeof(test_structure_4));
37
38 ts4_type.size = 0;
39 ts4_type.alignment = 0;
40 ts4_type.type = FFI_TYPE_STRUCT;
41 ts4_type.elements = ts4_type_elements;
42 ts4_type_elements[0] = &ffi_type_uint;
43 ts4_type_elements[1] = &ffi_type_uint;
44 ts4_type_elements[2] = &ffi_type_uint;
45 ts4_type_elements[3] = NULL;
46
47 args[0] = &ts4_type;
48 values[0] = &ts4_arg;
49
50 /* Initialize the cif */
51 CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts4_type, args) == FFI_OK);
52
53 ts4_arg.ui1 = 2;
54 ts4_arg.ui2 = 3;
55 ts4_arg.ui3 = 4;
56
57 ffi_call (&cif, FFI_FN(struct4), ts4_result, values);
58
59 CHECK(ts4_result->ui3 == 2U * 3U * 4U);
60
61
62 free (ts4_result);
63 exit(0);
64 }
test_structure_4::ui3
unsigned ui3
Definition: struct4.c:14
malloc
void * malloc(size_t) __attribute__((__malloc__)) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(1)))
ABI_NUM
#define ABI_NUM
Definition: ffitest.h:35
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
test_structure_4
Definition: struct4.c:10
ffitest.h
main
int main(void)
Definition: struct4.c:24
CHECK
#define CHECK(sub)
Definition: compile.c:448
test_structure_4::ui1
unsigned ui1
Definition: struct4.c:12
U
Definition: dtoa.c:290
ABI_ATTR
#define ABI_ATTR
Definition: ffitest.h:36
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
free
#define free(x)
Definition: dln.c:52
test_structure_4::ui2
unsigned ui2
Definition: struct4.c:13
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813