X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=doc%2Fmanual%2Fffi.texinfo;h=ea1399572d271c3c4cea4e9f6143c5a915d5f445;hb=4293ef0eaa26fc153dfae88de3d1dbe5043ac39e;hp=5546ce62160399c1f87580b3df1a7be8ad3c4208;hpb=2a4fabe1541b905591fbd6b83122209df6a48fab;p=sbcl.git diff --git a/doc/manual/ffi.texinfo b/doc/manual/ffi.texinfo index 5546ce6..ea13995 100644 --- a/doc/manual/ffi.texinfo +++ b/doc/manual/ffi.texinfo @@ -24,7 +24,7 @@ notably in the name of the @code{SB-ALIEN} package. * Operations On Foreign Values:: * Foreign Variables:: * Foreign Data Structure Examples:: -* Loading Unix Object Files:: +* Loading Shared Object Files:: * Foreign Function Calls:: * Step-By-Step Example of the Foreign Function Interface:: @end menu @@ -216,9 +216,9 @@ determine which field is active from context. @item The foreign type specifier @code{(sb-alien:enum @var{name} &rest @var{specs})} describes an enumeration type that maps between integer -values and keywords. If @var{name} is @code{nil}, then the type is +values and symbols. If @var{name} is @code{nil}, then the type is anonymous. Each element of the @var{specs} list is either a Lisp -keyword, or a list @code{(@var{keyword} @var{value})}. @var{value} is +symbol, or a list @code{(@var{symbol} @var{value})}. @var{value} is an integer. If @var{value} is not supplied, then it defaults to one greater than the value for the preceding spec (or to zero if it is the first spec). @@ -282,12 +282,14 @@ return zero values. @item The foreign type specifier @code{sb-alien:c-string} is similar to -@code{(* char)}, but is interpreted as a null-terminated string, and -is automatically converted into a Lisp string when accessed; or if the +@code{(* char)}, but is interpreted as a null-terminated string, and is +automatically converted into a Lisp string when accessed; or if the pointer is C @code{NULL} or @code{0}, then accessing it gives Lisp -@code{nil}. Lisp strings are stored with a trailing NUL -termination, so no copying (either by the user or the implementation) -is necessary when passing them to foreign code. +@code{nil}. Lisp strings of type @code{base-string} are stored with a +trailing NUL termination, so no copying (either by the user or the +implementation) is necessary when passing them to foreign code; strings +of type @code{(simple-array character (*))} are copied by the +implementation as required. Assigning a Lisp string to a @code{c-string} structure field or variable stores the contents of the string to the memory already @@ -711,33 +713,14 @@ which can be manipulated in Lisp like this: (setq my-struct (slot my-struct 'n)) @end lisp -@node Loading Unix Object Files +@node Loading Shared Object Files @comment node-name, next, previous, up -@section Loading Unix Object Files +@section Loading Shared Object Files Foreign object files can be loaded into the running Lisp process by calling @code{load-shared-object}. -The @code{sb-alien:load-shared-object} loads a single object file into -the currently running Lisp. The external symbols defining routines and -variables are made available for future external references (e.g. by -@code{extern-alien}). Forward references to foreign symbols aren't -supported: @code{load-shared-object} must be run before any of the -defined symbols are referenced. - -@quotation -Note: As of SBCL 0.7.5, all foreign code (code loaded with -@code{load-shared-object}) is lost when a Lisp -core is saved with @code{sb-ext:save-lisp-and-die}, and no attempt is -made to restore it when the core is loaded. Historically this has been -an annoyance both for SBCL users and for CMUCL users. It's hard to -solve this problem completely cleanly, but some generally-reliable -partial solution might be useful. Once someone in either camp gets -sufficiently annoyed to create it, SBCL is likely to adopt some -mechanism for automatically restoring foreign code when a saved core -is loaded. -@end quotation - +@include fun-sb-alien-load-shared-object.texinfo @node Foreign Function Calls @comment node-name, next, previous, up @@ -1138,7 +1121,7 @@ struct c_struct *c_function (i, s, r, a) printf("s = %s\n", s); printf("r->x = %d\n", r->x); printf("r->s = %s\n", r->s); - for (j = 0; j < 10; j++) printf("a[%d] = %d.\n", j, a[j]); + for (j = 0; j < 10; j++) printf("a[%d] = %d.\n", j, a[j]); r2 = (struct c_struct *) malloc (sizeof(struct c_struct)); r2->x = i + 5; r2->s = "a C string"; @@ -1201,16 +1184,15 @@ routine, e.g.: @samp{cc -c test.c && ld -shared -o test.so test.o} (In order to enable incremental loading with some linkers, you may need to say @samp{cc -G 0 -c test.c}) -Once the C code has been compiled, you can start up Lisp and load it -in: @samp{sbcl} Lisp should start up with its normal prompt. +Once the C code has been compiled, you can start up Lisp and load it in: +@samp{sbcl}. Lisp should start up with its normal prompt. Within Lisp, compile the Lisp file. (This step can be done separately. You don't have to recompile every time.) @samp{(compile-file "test.lisp")} Within Lisp, load the foreign object file to define the necessary -symbols: @samp{(load-shared-object "test.so")}. This must be done -before loading any code that refers to these symbols. +symbols: @samp{(load-shared-object "test.so")}. Now you can load the compiled Lisp (``fasl'') file into Lisp: @samp{(load "test.fasl")}