Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
uninitialized.c
Go to the documentation of this file.
1 /* { dg-do run } */
2 #include "ffitest.h"
3 
4 typedef struct
5 {
6  unsigned char uc;
7  double d;
8  unsigned int ui;
10 
11 static test_structure_1 struct1(test_structure_1 ts)
12 {
13  ts.uc++;
14  ts.d--;
15  ts.ui++;
16 
17  return ts;
18 }
19 
20 int main (void)
21 {
22  ffi_cif cif;
23  ffi_type *args[MAX_ARGS];
24  void *values[MAX_ARGS];
25  ffi_type ts1_type;
26  ffi_type *ts1_type_elements[4];
27 
28  memset(&cif, 1, sizeof(cif));
29  ts1_type.size = 0;
30  ts1_type.alignment = 0;
31  ts1_type.type = FFI_TYPE_STRUCT;
32  ts1_type.elements = ts1_type_elements;
33  ts1_type_elements[0] = &ffi_type_uchar;
34  ts1_type_elements[1] = &ffi_type_double;
35  ts1_type_elements[2] = &ffi_type_uint;
36  ts1_type_elements[3] = NULL;
37 
38  test_structure_1 ts1_arg;
39  /* This is a hack to get a properly aligned result buffer */
40  test_structure_1 *ts1_result =
42 
43  args[0] = &ts1_type;
44  values[0] = &ts1_arg;
45 
46  /* Initialize the cif */
48  &ts1_type, args) == FFI_OK);
49 
50  ts1_arg.uc = '\x01';
51  ts1_arg.d = 3.14159;
52  ts1_arg.ui = 555;
53 
54  ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
55 
56  CHECK(ts1_result->ui == 556);
57  CHECK(ts1_result->d == 3.14159 - 1);
58 
59  free (ts1_result);
60  exit(0);
61 }
test_structure_1
Definition: struct1.c:10
cls_struct_combined::d
cls_struct_16byte1 d
Definition: nested_struct.c:24
test_structure_1::d
double d
Definition: struct1.c:13
test_structure_1::ui
unsigned int ui
Definition: struct1.c:14
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
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
test_structure_1::uc
unsigned char uc
Definition: struct1.c:12
ffi_type_uchar
#define ffi_type_uchar
Definition: fiddle.h:55
memset
void * memset(void *, int, size_t)
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
main
int main(void)
Definition: uninitialized.c:20