diff options
author | Tom Tromey <tom@tromey.com> | 2015-11-17 21:18:20 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2016-02-22 16:07:55 -0700 |
commit | 38a4d72c95936d27cba1ac6e84e3094ffdfaa77c (patch) | |
tree | 389d99afd9cb696fc3ac6b35ee91b8d6d4dce64f /testsuite/libffi.call | |
parent | f2f234aef203a5e836b83cb772f9473f7ea0d5ce (diff) | |
download | libffi-38a4d72c95936d27cba1ac6e84e3094ffdfaa77c.tar.gz |
add ffi_get_struct_offsets
Diffstat (limited to 'testsuite/libffi.call')
-rw-r--r-- | testsuite/libffi.call/offsets.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/testsuite/libffi.call/offsets.c b/testsuite/libffi.call/offsets.c new file mode 100644 index 0000000..23d88b3 --- /dev/null +++ b/testsuite/libffi.call/offsets.c @@ -0,0 +1,46 @@ +/* Area: Struct layout + Purpose: Test ffi_get_struct_offsets + Limitations: none. + PR: none. + Originator: Tom Tromey. */ + +/* { dg-do run } */ +#include "ffitest.h" +#include <stddef.h> + +struct test_1 +{ + char c; + float f; + char c2; + int i; +}; + +int +main (void) +{ + ffi_type test_1_type; + ffi_type *test_1_elements[5]; + size_t test_1_offsets[4]; + + test_1_elements[0] = &ffi_type_schar; + test_1_elements[1] = &ffi_type_float; + test_1_elements[2] = &ffi_type_schar; + test_1_elements[3] = &ffi_type_sint; + test_1_elements[4] = NULL; + + test_1_type.size = 0; + test_1_type.alignment = 0; + test_1_type.type = FFI_TYPE_STRUCT; + test_1_type.elements = test_1_elements; + + CHECK (ffi_get_struct_offsets (FFI_DEFAULT_ABI, &test_1_type, test_1_offsets) + == FFI_OK); + CHECK (test_1_type.size == sizeof (struct test_1)); + CHECK (offsetof (struct test_1, c) == test_1_offsets[0]); + CHECK (offsetof (struct test_1, f) == test_1_offsets[1]); + CHECK (offsetof (struct test_1, c2) == test_1_offsets[2]); + CHECK (offsetof (struct test_1, i) == test_1_offsets[3]); + + return 0; +} |