Ruby  2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
struct6.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  float f;
12  double d;
14 
15 static test_structure_6 ABI_ATTR struct6 (test_structure_6 ts)
16 {
17  ts.f += 1;
18  ts.d += 1;
19 
20  return ts;
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 ts6_type;
29  ffi_type *ts6_type_elements[3];
30 
31  test_structure_6 ts6_arg;
32 
33  /* This is a hack to get a properly aligned result buffer */
34  test_structure_6 *ts6_result =
36 
37  ts6_type.size = 0;
38  ts6_type.alignment = 0;
39  ts6_type.type = FFI_TYPE_STRUCT;
40  ts6_type.elements = ts6_type_elements;
41  ts6_type_elements[0] = &ffi_type_float;
42  ts6_type_elements[1] = &ffi_type_double;
43  ts6_type_elements[2] = NULL;
44 
45  args[0] = &ts6_type;
46  values[0] = &ts6_arg;
47 
48  /* Initialize the cif */
49  CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts6_type, args) == FFI_OK);
50 
51  ts6_arg.f = 5.55f;
52  ts6_arg.d = 6.66;
53 
54  printf ("%g\n", ts6_arg.f);
55  printf ("%g\n", ts6_arg.d);
56 
57  ffi_call(&cif, FFI_FN(struct6), ts6_result, values);
58 
59  CHECK(ts6_result->f == 5.55f + 1);
60  CHECK(ts6_result->d == 6.66 + 1);
61 
62  free (ts6_result);
63  exit(0);
64 }
test_structure_6::d
double d
Definition: struct6.c:12
malloc
void * malloc(size_t) __attribute__((__malloc__)) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(1)))
ABI_NUM
#define ABI_NUM
Definition: ffitest.h:35
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__))
test_structure_6::f
float f
Definition: struct6.c:11
ffitest.h
CHECK
#define CHECK(sub)
Definition: compile.c:448
main
int main(void)
Definition: struct6.c:23
ABI_ATTR
#define ABI_ATTR
Definition: ffitest.h:36
test_structure_6
Definition: struct6.c:9
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
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813