diff options
author | Anthony Green <green@moxielogic.com> | 2016-03-14 13:54:53 -0400 |
---|---|---|
committer | Anthony Green <green@moxielogic.com> | 2016-03-14 13:54:53 -0400 |
commit | 9de24a3ff31c7446de29c1adcd9276fd7ba93897 (patch) | |
tree | d7f6674baaf21e73d5b8085c0574ed6dcecfc17f /doc | |
parent | ee718066f763b65d1888f9cc7155d3a1880f80e9 (diff) | |
parent | 38a4d72c95936d27cba1ac6e84e3094ffdfaa77c (diff) | |
download | libffi-9de24a3ff31c7446de29c1adcd9276fd7ba93897.tar.gz |
Merge pull request #212 from tromey/struct-layout
add ffi_get_struct_offsets
Diffstat (limited to 'doc')
-rw-r--r-- | doc/libffi.texi | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/doc/libffi.texi b/doc/libffi.texi index 5c9fddd..94b7a9e 100644 --- a/doc/libffi.texi +++ b/doc/libffi.texi @@ -440,7 +440,8 @@ on the chosen ABI. @item The size and alignment of a new structure type will not be set by -@code{libffi} until it has been passed to @code{ffi_prep_cif}. +@code{libffi} until it has been passed to @code{ffi_prep_cif} or +@code{ffi_get_struct_offsets}. @item A structure type cannot be shared across ABIs. Instead each ABI needs @@ -448,8 +449,9 @@ its own copy of the structure type. @end itemize So, before examining these fields, it is safest to pass the -@code{ffi_type} object to @code{ffi_prep_cif} first. This function -will do all the needed setup. +@code{ffi_type} object to @code{ffi_prep_cif} or +@code{ffi_get_struct_offsets} first. This function will do all the +needed setup. @example ffi_type *desired_type; @@ -463,6 +465,28 @@ if (ffi_prep_cif (&cif, desired_abi, 0, desired_type, NULL) == FFI_OK) @} @end example +@code{libffi} also provides a way to get the offsets of the members of +a structure. + +@findex ffi_get_struct_offsets +@defun ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, size_t *offsets) +Compute the offset of each element of the given structure type. +@var{abi} is the ABI to use; this is needed because in some cases the +layout depends on the ABI. + +@var{sizes} is an out parameter. The caller is responsible for +providing enough space for all the results to be written -- one +element per element type in @var{struct_type}. If @var{sizes} is +@code{NULL}, then the type will be laid out but not otherwise +modified. This can be useful for accessing the type's size or layout, +as mentioned above. + +This function returns @code{FFI_OK} on success; @code{FFI_BAD_ABI} if +@var{abi} is invalid; or @code{FFI_BAD_TYPEDEF} if @var{struct_type} +is invalid in some way. Note that only @code{FFI_STRUCT} types are +valid here. +@end defun + @node Arrays Unions Enums @subsection Arrays, Unions, and Enumerations |