Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
struct2.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  double d1;
13  double d2;
15 
17 {
18  ts.d1--;
19  ts.d2--;
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  test_structure_2 ts2_arg;
30  ffi_type ts2_type;
31  ffi_type *ts2_type_elements[3];
32 
33  /* This is a hack to get a properly aligned result buffer */
34  test_structure_2 *ts2_result =
36 
37  ts2_type.size = 0;
38  ts2_type.alignment = 0;
39  ts2_type.type = FFI_TYPE_STRUCT;
40  ts2_type.elements = ts2_type_elements;
41  ts2_type_elements[0] = &ffi_type_double;
42  ts2_type_elements[1] = &ffi_type_double;
43  ts2_type_elements[2] = NULL;
44 
45  args[0] = &ts2_type;
46  values[0] = &ts2_arg;
47 
48  /* Initialize the cif */
49  CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts2_type, args) == FFI_OK);
50 
51  ts2_arg.d1 = 5.55;
52  ts2_arg.d2 = 6.66;
53 
54  printf ("%g\n", ts2_arg.d1);
55  printf ("%g\n", ts2_arg.d2);
56 
57  ffi_call(&cif, FFI_FN(struct2), ts2_result, values);
58 
59  printf ("%g\n", ts2_result->d1);
60  printf ("%g\n", ts2_result->d2);
61 
62  CHECK(ts2_result->d1 == 5.55 - 1);
63  CHECK(ts2_result->d2 == 6.66 - 1);
64 
65  free (ts2_result);
66  exit(0);
67 }
main
int main(void)
Definition: struct2.c:24
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
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__))
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
test_structure_2
Definition: struct2.c:10
test_structure_2::d2
double d2
Definition: struct2.c:13
test_structure_2::d1
double d1
Definition: struct2.c:12