Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
struct5.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 typedef struct
10 {
11  char c1;
12  char c2;
14 
16 {
17  ts1.c1 += ts2.c1;
18  ts1.c2 -= ts2.c2;
19 
20  return ts1;
21 }
22 
23 int main (void)
24 {
25  ffi_cif cif;
26  ffi_type *args[MAX_ARGS];
27  void *values[MAX_ARGS];
28  ffi_type ts5_type;
29  ffi_type *ts5_type_elements[3];
30 
31  test_structure_5 ts5_arg1, ts5_arg2;
32 
33  /* This is a hack to get a properly aligned result buffer */
34  test_structure_5 *ts5_result =
36 
37  ts5_type.size = 0;
38  ts5_type.alignment = 0;
39  ts5_type.type = FFI_TYPE_STRUCT;
40  ts5_type.elements = ts5_type_elements;
41  ts5_type_elements[0] = &ffi_type_schar;
42  ts5_type_elements[1] = &ffi_type_schar;
43  ts5_type_elements[2] = NULL;
44 
45  args[0] = &ts5_type;
46  args[1] = &ts5_type;
47  values[0] = &ts5_arg1;
48  values[1] = &ts5_arg2;
49 
50  /* Initialize the cif */
51  CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK);
52 
53  ts5_arg1.c1 = 2;
54  ts5_arg1.c2 = 6;
55  ts5_arg2.c1 = 5;
56  ts5_arg2.c2 = 3;
57 
58  ffi_call (&cif, FFI_FN(struct5), ts5_result, values);
59 
60  CHECK(ts5_result->c1 == 7);
61  CHECK(ts5_result->c2 == 3);
62 
63 
64  free (ts5_result);
65  exit(0);
66 }
ffi_type_schar
#define ffi_type_schar
Definition: fiddle.h:56
ABI_NUM
#define ABI_NUM
Definition: ffitest.h:35
NULL
#define NULL
Definition: _sdbm.c:101
ffitest.h
malloc
void * malloc(size_t) __attribute__((__malloc__)) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(1)))
CHECK
#define CHECK(sub)
Definition: compile.c:448
test_structure_5::c2
char c2
Definition: struct5.c:12
test_structure_5::c1
char c1
Definition: struct5.c:11
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
exit
void exit(int __status) __attribute__((__noreturn__))
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
test_structure_5
Definition: struct5.c:9
main
int main(void)
Definition: struct5.c:23