Fix sample closure code

This commit is contained in:
Andrew Haley
2013-11-16 06:35:51 -05:00
committed by Anthony Green
parent db0ace3a38
commit 31257b3189
5 changed files with 25 additions and 16 deletions

View File

@@ -1,3 +1,8 @@
2013-11-15 Andrew Haley <aph@redhat.com>
* doc/libffi.texi (Closure Example): Fix the sample code.
* doc/libffi.info, doc/stamp-vti, doc/version.texi: Rebuilt.
2013-11-15 Andrew Haley <aph@redhat.com> 2013-11-15 Andrew Haley <aph@redhat.com>
* testsuite/libffi.call/va_struct1.c (main): Fix broken test. * testsuite/libffi.call/va_struct1.c (main): Fix broken test.

View File

@@ -478,19 +478,21 @@ A trivial example that creates a new 'puts' by binding 'fputs' with
#include <ffi.h> #include <ffi.h>
/* Acts like puts with the file given at time of enclosure. */ /* Acts like puts with the file given at time of enclosure. */
void puts_binding(ffi_cif *cif, ffi_arg *ret, void* args[], void puts_binding(ffi_cif *cif, void *ret, void* args[],
FILE *stream) void *stream)
{ {
*ret = fputs(*(char **)args[0], stream); *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
} }
typedef int (*puts_t)(char *);
int main() int main()
{ {
ffi_cif cif; ffi_cif cif;
ffi_type *args[1]; ffi_type *args[1];
ffi_closure *closure; ffi_closure *closure;
int (*bound_puts)(char *); void *bound_puts;
int rc; int rc;
/* Allocate closure and bound_puts */ /* Allocate closure and bound_puts */
@@ -509,7 +511,7 @@ A trivial example that creates a new 'puts' by binding 'fputs' with
if (ffi_prep_closure_loc(closure, &cif, puts_binding, if (ffi_prep_closure_loc(closure, &cif, puts_binding,
stdout, bound_puts) == FFI_OK) stdout, bound_puts) == FFI_OK)
{ {
rc = bound_puts("Hello World!"); rc = ((puts_t)bound_puts)("Hello World!");
/* rc now holds the result of the call to fputs */ /* rc now holds the result of the call to fputs */
} }
} }
@@ -610,7 +612,7 @@ Node: Type Example11207
Node: Multiple ABIs12473 Node: Multiple ABIs12473
Node: The Closure API12844 Node: The Closure API12844
Node: Closure Example15788 Node: Closure Example15788
Node: Missing Features17342 Node: Missing Features17396
Node: Index17795 Node: Index17849
 
End Tag Table End Tag Table

View File

@@ -541,21 +541,23 @@ A trivial example that creates a new @code{puts} by binding
#include <ffi.h> #include <ffi.h>
/* Acts like puts with the file given at time of enclosure. */ /* Acts like puts with the file given at time of enclosure. */
void puts_binding(ffi_cif *cif, ffi_arg *ret, void* args[], void puts_binding(ffi_cif *cif, void *ret, void* args[],
FILE *stream) void *stream)
@{ @{
*ret = fputs(*(char **)args[0], stream); *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
@} @}
typedef int (*puts_t)(char *);
int main() int main()
@{ @{
ffi_cif cif; ffi_cif cif;
ffi_type *args[1]; ffi_type *args[1];
ffi_closure *closure; ffi_closure *closure;
int (*bound_puts)(char *); void *bound_puts;
int rc; int rc;
/* Allocate closure and bound_puts */ /* Allocate closure and bound_puts */
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts); closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
@@ -569,10 +571,10 @@ int main()
&ffi_type_sint, args) == FFI_OK) &ffi_type_sint, args) == FFI_OK)
@{ @{
/* Initialize the closure, setting stream to stdout */ /* Initialize the closure, setting stream to stdout */
if (ffi_prep_closure_loc(closure, &cif, puts_binding, if (ffi_prep_closure_loc(closure, &cif, puts_binding,
stdout, bound_puts) == FFI_OK) stdout, bound_puts) == FFI_OK)
@{ @{
rc = bound_puts("Hello World!"); rc = ((puts_t)bound_puts)("Hello World!");
/* rc now holds the result of the call to fputs */ /* rc now holds the result of the call to fputs */
@} @}
@} @}

View File

@@ -1,4 +1,4 @@
@set UPDATED 13 November 2013 @set UPDATED 16 November 2013
@set UPDATED-MONTH November 2013 @set UPDATED-MONTH November 2013
@set EDITION 3.0.14-rc0 @set EDITION 3.0.14-rc0
@set VERSION 3.0.14-rc0 @set VERSION 3.0.14-rc0

View File

@@ -1,4 +1,4 @@
@set UPDATED 13 November 2013 @set UPDATED 16 November 2013
@set UPDATED-MONTH November 2013 @set UPDATED-MONTH November 2013
@set EDITION 3.0.14-rc0 @set EDITION 3.0.14-rc0
@set VERSION 3.0.14-rc0 @set VERSION 3.0.14-rc0