Merge pull request #221 from tromey/document-closure-ffi_arg Document closure ffi arg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/doc/libffi.texi b/doc/libffi.texi
index 0459899..87a4f50 100644
--- a/doc/libffi.texi
+++ b/doc/libffi.texi
@@ -776,36 +776,47 @@ the closure function:
@findex ffi_prep_closure_loc
@defun ffi_status ffi_prep_closure_loc (ffi_closure *@var{closure}, ffi_cif *@var{cif}, void (*@var{fun}) (ffi_cif *@var{cif}, void *@var{ret}, void **@var{args}, void *@var{user_data}), void *@var{user_data}, void *@var{codeloc})
-Prepare a closure function.
+Prepare a closure function. The arguments to
+@code{ffi_prep_closure_loc} are:
-@var{closure} is the address of a @code{ffi_closure} object; this is
-the writable address returned by @code{ffi_closure_alloc}.
+@table @var
+@item closure
+The address of a @code{ffi_closure} object; this is the writable
+address returned by @code{ffi_closure_alloc}.
+
+@item cif
+The @code{ffi_cif} describing the function parameters. Note that this
+object, and the types to which it refers, must be kept alive until the
+closure itself is freed.
-@var{cif} is the @code{ffi_cif} describing the function parameters.
-Note that this object, and the types to which it refers, must be kept
-alive until the closure itself is freed.
+@item user_data
+An arbitrary datum that is passed, uninterpreted, to your closure
+function.
-@var{user_data} is an arbitrary datum that is passed, uninterpreted,
-to your closure function.
+@item codeloc
+The executable address returned by @code{ffi_closure_alloc}.
-@var{codeloc} is the executable address returned by
-@code{ffi_closure_alloc}.
+@item fun
+The function which will be called when the closure is invoked. It is
+called with the arguments:
-@var{fun} is the function which will be called when the closure is
-invoked. It is called with the arguments:
@table @var
@item cif
The @code{ffi_cif} passed to @code{ffi_prep_closure_loc}.
@item ret
A pointer to the memory used for the function's return value.
-@var{fun} must fill this, unless the function is declared as returning
-@code{void}. Note that this points to memory that is exactly the size
-of the type given as the return type when initializing the CIF. In
-particular, closures do not have the special promotion behavior of
-@code{ffi_call}.
-@c FIXME: is this NULL for void-returning functions?
-@c (experimentally it is not, but it seems like a good idea)
+
+If the function is declared as returning @code{void}, then this value
+is garbage and should not be used.
+
+Otherwise, @var{fun} must fill the object to which this points,
+following the same special promotion behavior as @code{ffi_call}.
+That is, in most cases, @var{ret} points to an object of exactly the
+size of the type specified when @var{cif} was constructed. However,
+integral types narrower than the system register size are widened. In
+these cases your program may assume that @var{ret} points to an
+@code{ffi_arg} object.
@item args
A vector of pointers to memory holding the arguments to the function.
@@ -814,6 +825,7 @@ A vector of pointers to memory holding the arguments to the function.
The same @var{user_data} that was passed to
@code{ffi_prep_closure_loc}.
@end table
+@end table
@code{ffi_prep_closure_loc} will return @code{FFI_OK} if everything
went ok, and one of the other @code{ffi_status} values on error.