summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2015-11-17 21:18:20 -0700
committerTom Tromey <tom@tromey.com>2016-02-22 16:07:55 -0700
commit38a4d72c95936d27cba1ac6e84e3094ffdfaa77c (patch)
tree389d99afd9cb696fc3ac6b35ee91b8d6d4dce64f /doc
parentf2f234aef203a5e836b83cb772f9473f7ea0d5ce (diff)
downloadlibffi-38a4d72c95936d27cba1ac6e84e3094ffdfaa77c.tar.gz
add ffi_get_struct_offsets
Diffstat (limited to 'doc')
-rw-r--r--doc/libffi.texi30
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