Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

struct3.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 int si;
13 } test_structure_3;
14
15 static test_structure_3 ABI_ATTR struct3(test_structure_3 ts)
16 {
17 ts.si = -(ts.si*2);
18
19 return ts;
20 }
21
22 int main (void)
23 {
24 ffi_cif cif;
25 ffi_type *args[MAX_ARGS];
26 void *values[MAX_ARGS];
27 int compare_value;
28 ffi_type ts3_type;
29 ffi_type *ts3_type_elements[2];
30
31 test_structure_3 ts3_arg;
32 test_structure_3 *ts3_result =
33 (test_structure_3 *) malloc (sizeof(test_structure_3));
34
35 ts3_type.size = 0;
36 ts3_type.alignment = 0;
37 ts3_type.type = FFI_TYPE_STRUCT;
38 ts3_type.elements = ts3_type_elements;
39 ts3_type_elements[0] = &ffi_type_sint;
40 ts3_type_elements[1] = NULL;
41
42 args[0] = &ts3_type;
43 values[0] = &ts3_arg;
44
45 /* Initialize the cif */
46 CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
47 &ts3_type, args) == FFI_OK);
48
49 ts3_arg.si = -123;
50 compare_value = ts3_arg.si;
51
52 ffi_call(&cif, FFI_FN(struct3), ts3_result, values);
53
54 printf ("%d %d\n", ts3_result->si, -(compare_value*2));
55
56 CHECK(ts3_result->si == -(compare_value*2));
57
58 free (ts3_result);
59 exit(0);
60 }
malloc
void * malloc(size_t) __attribute__((__malloc__)) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(1)))
main
int main(void)
Definition: struct3.c:22
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__))
ffitest.h
test_structure_3
Definition: struct3.c:10
test_structure_3::si
int si
Definition: struct3.c:12
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
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813