| 1 |
/* Area: ffi_call |
| 2 |
Purpose: Check structures. |
| 3 |
Limitations: none. |
| 4 |
PR: none. |
| 5 |
Originator: Sergei Trofimovich <[email protected]> |
| 6 |
|
| 7 |
The test originally discovered in ruby's bindings |
| 8 |
for ffi in https://bugs.gentoo.org/634190 */ |
| 9 |
|
| 10 |
/* { dg-do run } */ |
| 11 |
#include "ffitest.h" |
| 12 |
|
| 13 |
struct s { |
| 14 |
int s32; |
| 15 |
float f32; |
| 16 |
signed char s8; |
| 17 |
}; |
| 18 |
|
| 19 |
struct s make_s(void) { |
| 20 |
struct s r; |
| 21 |
r.s32 = 0x1234; |
| 22 |
r.f32 = 7.0; |
| 23 |
r.s8 = 0x78; |
| 24 |
return r; |
| 25 |
} |
| 26 |
|
| 27 |
int main() { |
| 28 |
ffi_cif cif; |
| 29 |
struct s r; |
| 30 |
ffi_type rtype; |
| 31 |
ffi_type* s_fields[] = { |
| 32 |
&ffi_type_sint, |
| 33 |
&ffi_type_float, |
| 34 |
&ffi_type_schar, |
| 35 |
NULL, |
| 36 |
}; |
| 37 |
|
| 38 |
rtype.size = 0; |
| 39 |
rtype.alignment = 0, |
| 40 |
rtype.type = FFI_TYPE_STRUCT, |
| 41 |
rtype.elements = s_fields, |
| 42 |
|
| 43 |
r.s32 = 0xbad; |
| 44 |
r.f32 = 999.999; |
| 45 |
r.s8 = 0x51; |
| 46 |
|
| 47 |
// Here we emulate the following call: |
| 48 |
//r = make_s(); |
| 49 |
|
| 50 |
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &rtype, NULL) == FFI_OK); |
| 51 |
ffi_call(&cif, FFI_FN(make_s), &r, NULL); |
| 52 |
|
| 53 |
CHECK(r.s32 == 0x1234); |
| 54 |
CHECK(r.f32 == 7.0); |
| 55 |
CHECK(r.s8 == 0x78); |
| 56 |
exit(0); |
| 57 |
} |