2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "docbook/dtd/xml/4.2/docbookx.dtd" [
4 <!ENTITY uffi "<application><emphasis>UFFI</emphasis></application>">
5 <!ENTITY ffi "<acronym>FFI</acronym>">
6 <!ENTITY cmucl "<application>CMUCL</application>">
7 <!ENTITY scl "<application>SCL</application>">
8 <!ENTITY lw "<application>Lispworks</application>">
9 <!ENTITY sbcl "<application>SBCL</application>">
10 <!ENTITY openmcl "<application>OpenMCL</application>">
11 <!ENTITY mcl "<application>MCL</application>">
12 <!ENTITY acl "<application>AllegroCL</application>">
13 <!ENTITY cl "<application>ANSI Common Lisp</application>">
14 <!ENTITY t "<constant>T</constant>">
15 <!ENTITY nil "<constant>NIL</constant>">
16 <!ENTITY null "<constant>NULL</constant>">
17 <!ENTITY c "<computeroutput>C</computeroutput>">
18 <!ENTITY defsystem "<application>defsystem</application>">
19 <!ENTITY asdf "<application>ASDF</application>">
20 <!ENTITY bookinfo SYSTEM "bookinfo.sgml">
21 <!ENTITY preface SYSTEM "preface.sgml">
22 <!ENTITY intro SYSTEM "intro.sgml">
23 <!ENTITY notes SYSTEM "notes.sgml">
24 <!ENTITY ref SYSTEM "ref.sgml">
25 <!ENTITY appendix SYSTEM "appendix.sgml">
26 <!ENTITY glossary SYSTEM "glossary.sgml">
32 <title>&uffi; Reference Guide</title>
34 <firstname>Kevin</firstname>
35 <othername>M.</othername>
36 <surname>Rosenberg</surname>
38 <orgname>Heart Hospital of New Mexico</orgname>
40 <email>kevin@rosenberg.net</email>
41 <street>504 Elm Street N.E.</street>
42 <city>Albuquerque</city>
43 <state>New Mexico</state>
44 <postcode>87102</postcode>
50 <simpara>$Id: bookinfo.sgml 7990 2003-10-12 21:26:56Z kevin $</simpara>
51 <simpara>File $Date: 2003-10-12 15:26:56 -0600 (Sun, 12 Oct 2003) $</simpara>
54 <year>2002-2003</year>
55 <holder>Kevin M. Rosenberg</holder>
60 <para>The &uffi; package was designed and
61 written by Kevin M. Rosenberg.
66 Permission is granted to copy, distribute and/or modify this document
67 under the terms of the GNU Free Documentation License, Version 1.1
68 or any later version published by the Free Software Foundation;
69 with no Invariant Sections, with the no
70 Front-Cover Texts, and with no Back-Cover Texts.
71 A copy of the license is included in the &uffi; distribution.
75 <para><application>Allegro CL</application>® is a registered
76 trademark of Franz Inc.
80 <para><application>Lispworks</application>® is a registered
81 trademark of Xanalys Inc.
85 <para><application>Microsoft
86 Windows</application>® is a registered trademark of
92 product names are the registered trademarks or trademarks of
93 their respective holders.
101 <title>Preface</title>
102 <para>This reference guide describes the usage and features
104 chapter provides an overview to the design of &uffi;.
105 Following that chapter is the reference section for all user
106 accessible functions of &uffi;. The appendix covers the
107 installation and implementation-specifc features of &uffi;.
113 <title>Introduction</title>
115 <title>Purpose</title>
116 <para> This reference guide describes
117 &uffi;, a package that provides a cross-implementation
118 interface from Common Lisp to C-language compatible libraries.
126 Every Common Lisp implementation has
127 a method for interfacing to C-language compatible
128 libraries. These methods are often termed a
129 <emphasis>Foreign Function Library Interface</emphasis>
130 (&ffi;). Unfortunately, these methods vary widely
132 implementations, thus preventing the writing of a portable FFI to a
133 particular C-library.
136 &uffi; gathers a common subset of functionality between Common Lisp
137 implementations. &uffi; wraps this common subset of functionality with
138 it's own syntax and provides macro translation of uffi functions into
139 the specific syntax of supported Common Lisp implementations.
142 Developers who use &uffi; to interface with C libraries will
143 automatically have their code function in each of uffi's supported
149 <title>Supported Implementations</title>
150 <para>The primary tested and supported platforms for &uffi; are:
152 <itemizedlist mark="opencircle">
153 <listitem><para>&acl; v6.2 on Debian GNU/Linux
154 FreeBSD 4.5, Solaris v2.8, and Microsoft Windows XP.</para></listitem>
155 <listitem><para>&lw; v4.2 on Debian GNU/Linux and Microsoft Windows XP.</para></listitem>
156 <listitem><para>&cmucl; 18d on Debian GNU/Linux, FreeBSD 4.5, and Solaris 2.8</para></listitem>
157 <listitem><para>&sbcl; 0.7.8 on Debian GNU/Linux</para></listitem>
158 <listitem><para>&scl; 1.1.1 on Debian GNU/Linux</para></listitem>
159 <listitem><para>&openmcl; 0.13 on Debian GNU/Linux for PowerPC</para></listitem>
161 <para>Beta code is included with &uffi; for
163 <itemizedlist mark="opencircle">
164 <listitem><para>&openmcl; and &mcl; with MacOSX</para></listitem>
169 <title>Design</title>
171 <title>Overview</title>
173 &uffi; was designed as a cross-implementation
174 compatible <emphasis>Foreign Function Interface</emphasis>.
176 only a common subset of functionality can be
177 provided. Likewise, not every optimization for that a specific
178 implementation provides can be supported. Wherever possible,
179 though, implementation-specific optimizations are invoked.
184 <title>Priorities</title>
186 The design of &uffi; is dictated by the order of these priorities:
191 Code using &uffi; must operate correctly on all
192 supported implementations.
197 Take advantage of implementation-specific optimizations. Ideally,
198 there will not a situation where an implementation-specific
199 &ffi; will be chosen due to lack of optimizations in &uffi;.
203 <para>Provide a simple interface to developers using
204 &uffi;. This priority is quite a bit lower than the above priorities.
205 This lower priority is manifest by programmers having to pass types in
206 pointer and array dereferencing, needing to use
207 <constant>cstring</constant> wrapper functions, and the use of
208 ensure-char-character and ensure-char-integer functions. My hope is
209 that the developer inconvenience will be outweighed by the generation
210 of optimized code that is cross-implementation compatible.
221 <title>Programming Notes</title>
224 <title>Implementation Specific Notes</title>
238 <title>&cmucl;</title>
245 <title>Foreign Object Representation and Access</title>
246 <para> There are two main approaches used to represent foreign
247 objects: an integer that represents an address in memory, and a
248 object that also includes run-time typing. The advantage of
249 run-time typing is the system can dereference pointers and perform
250 array access without those functions requiring a type at the cost
251 of additional overhead to generate and store the run-time
252 typing. The advantage of integer representation, at least for
253 &acl;, is that the compiler can generate inline code to
254 dereference pointers. Further, the overhead of the run-time type
255 information is eliminated. The disadvantage is the program must
257 the type to the functions to dereference objects and array.
262 <title>Optimizing Code Using UFFI</title>
264 <title>Background</title>
266 Two implementions have different techniques to optimize
267 (open-code) foreign objects. &acl; can open-code foreign
269 access if pointers are integers and the type of object is
270 specified in the access function. Thus, &uffi; represents objects
271 in &acl; as integers which don't have type information.
273 &cmucl; works best when keeping objects as typed
274 objects. However, it's compiler can open-code object access when
275 the object type is specified in <function>declare</function>
276 commands and in <varname>:type</varname> specifiers in
277 <function>defstruct</function> and <function>defclass</function>.
278 </para> <para> &lw;, in converse to &acl; and &cmucl; does not do
279 any open coding of object access. &lw;, by default, maintains
280 objects with run-time typing. </para>
283 <title>Cross-Implementation Optimization</title>
285 To fully optimize across platforms, both explicit type
286 information must be passed to dereferencing of pointers and
287 arrays. Though this optimization only helps with &acl;, &uffi;
288 is designed to require this type information be passed the
289 dereference functions. Second, declarations of type should be
290 made in functions, structures, and classes where foreign
291 objects will be help. This will optimize access for &lw;
294 Here is an example that should both methods being used for
295 maximum cross-implementation optimization:
297 (uffi:def-type the-struct-type-def the-struct-type)
298 (let ((a-foreign-struct (allocate-foreign-object 'the-struct-type)))
299 (declare 'the-struct-type-def a-foreign-struct)
300 (get-slot-value a-foreign-struct 'the-struct-type 'field-name))
310 <title>Declarations</title>
314 <title>Overview</title>
315 <para>Declarations are used to give the compiler optimizing
316 information about foreign types. Currently, only &cmucl;
317 supports declarations. On &acl; and &lw;, these expressions
318 declare the type generically as &t;
323 <refentry id="def-type">
325 <refname>def-type</refname>
326 <refpurpose>Defines a Common Lisp type.
328 <refclass>Macro</refclass>
331 <title>Syntax</title>
333 <function>def-type</function> <replaceable>name type</replaceable>
337 <title>Arguments and Values</title>
340 <term><parameter>name</parameter></term>
342 <para>A symbol naming the type</para>
346 <term><parameter>type</parameter></term>
348 <para>A form that is evaluated that specifies the &uffi; type.
355 <title>Description</title>
356 <para>Defines a Common Lisp type based on a &uffi; type.
360 <title>Examples</title>
362 (def-type char-ptr '(* :char))
365 (declare (type char-ptr ptr))
370 <title>Side Effects</title>
371 <para>Defines a new &cl; type.</para>
374 <title>Affected by</title>
378 <title>Exceptional Situations</title>
386 <title>Primitive Types</title>
388 <title>Overview</title>
390 Primitive types have a single value, these include
391 characters, numbers, and pointers. They are all symbols in
396 <para><constant>:char</constant> - Signed 8-bits. A
397 dereferenced :char pointer returns an character.</para>
400 <para><constant>:unsigned-char</constant> - Unsigned 8-bits. A dereferenced :unsigned-char
401 pointer returns an character.</para>
404 <para><constant>:byte</constant> - Signed 8-bits. A
405 dereferenced :byte pointer returns an integer.</para>
408 <para><constant>:unsigned-byte</constant> - Unsigned 8-bits. A
409 dereferenced :unsigned-byte pointer returns an integer.</para>
412 <para><constant>:short</constant> - Signed 16-bits.</para>
415 <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
418 <para><constant>:int</constant> - Signed 32-bits.</para>
421 <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
424 <para><constant>:long</constant> - Signed 32 or 64 bits, depending upon the platform.</para>
427 <para><constant>:unsigned-long</constant> - Unsigned 32 or 64 bits, depending upon the platform.</para>
430 <para><constant>:float</constant> - 32-bit floating point.</para>
433 <para><constant>:double</constant> - 64-bit floating point.</para>
436 <para><constant>:cstring</constant> -
437 A &null; terminated string used for passing and returning characters strings with a &c; function.
441 <para><constant>:void</constant> -
442 The absence of a value. Used to indicate that a function does not return a value.</para>
445 <para><constant>:pointer-void</constant> -
446 Points to a generic object.</para>
449 <para><constant>*</constant> - Used to declare a pointer to an object</para>
454 <refentry id="def-constant">
456 <refname>def-constant</refname>
457 <refpurpose>Binds a symbol to a constant.
459 <refclass>Macro</refclass>
462 <title>Syntax</title>
464 <function>def-constant</function> <replaceable>name value &key export</replaceable>
468 <title>Arguments and Values</title>
471 <term><parameter>name</parameter></term>
473 <para>A symbol that will be bound to the value.
478 <term><parameter>value</parameter></term>
480 <para>An evaluated form that is bound the the name.
485 <term><parameter>export</parameter></term>
487 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
493 <title>Description</title>
495 This is a thin wrapper around
496 <function>defconstant</function>. It evaluates at
497 compile-time and optionally exports the symbol from the package.
501 <title>Examples</title>
503 (def-constant pi2 (* 2 pi))
504 (def-constant exported-pi2 (* 2 pi) :export t)
508 <title>Side Effects</title>
509 <para>Creates a new special variable..</para>
512 <title>Affected by</title>
516 <title>Exceptional Situations</title>
521 <refentry id="def-foreign-type">
523 <refname>def-foreign-type</refname>
524 <refpurpose>Defines a new foreign type.
526 <refclass>Macro</refclass>
529 <title>Syntax</title>
531 <function>def-foreign-type</function> <replaceable>name type</replaceable>
535 <title>Arguments and Values</title>
538 <term><parameter>name</parameter></term>
540 <para>A symbol naming the new foreign type.
545 <term><parameter>value</parameter></term>
547 <para>A form that is not evaluated that defines the new
555 <title>Description</title>
556 <para>Defines a new foreign type.
560 <title>Examples</title>
562 (def-foreign-type my-generic-pointer :pointer-void)
563 (def-foreign-type a-double-float :double-float)
564 (def-foreign-type char-ptr (* :char))
568 <title>Side Effects</title>
569 <para>Defines a new foreign type.
573 <title>Affected by</title>
577 <title>Exceptional Situations</title>
582 <refentry id="null-char-p">
584 <refname>null-char-p</refname>
585 <refpurpose>Tests a character for &null; value.
587 <refclass>Macro</refclass>
590 <title>Syntax</title>
592 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
596 <title>Arguments and Values</title>
599 <term><parameter>char</parameter></term>
601 <para>A character or integer.
606 <term><parameter>is-null</parameter></term>
608 <para>A boolean flag indicating if char is a &null; value.
615 <title>Description</title>
617 A predicate testing if a character or integer is &null;. This
618 abstracts the difference in implementations where some return a
619 <computeroutput>character</computeroutput> and some return a
620 <computeroutput>integer</computeroutput> whence dereferencing a
621 <computeroutput>C</computeroutput> character pointer.
625 <title>Examples</title>
627 (def-array-pointer ca :unsigned-char)
628 (let ((fs (convert-to-foreign-string "ab")))
629 (values (null-char-p (deref-array fs 'ca 0))
630 (null-char-p (deref-array fs 'ca 2))))
636 <title>Side Effects</title>
641 <title>Affected by</title>
645 <title>Exceptional Situations</title>
652 <title>Aggregate Types</title>
654 <title>Overview</title>
656 Aggregate types are comprised of one or more primitive types.
660 <refentry id="def-enum">
662 <refname>def-enum</refname>
663 <refpurpose>Defines a &c; enumeration.
665 <refclass>Macro</refclass>
668 <title>Syntax</title>
670 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
674 <title>Arguments and Values</title>
677 <term><parameter>name</parameter></term>
679 <para>A symbol that names the enumeration.
684 <term><parameter>fields</parameter></term>
686 <para>A list of field defintions. Each definition can be
687 a symbol or a list of two elements. Symbols get assigned a value of the
688 current counter which starts at <computeroutput>0</computeroutput> and
689 increments by <computeroutput>1</computeroutput> for each subsequent symbol. It the field definition is a list, the first position is the symbol and the second
690 position is the value to assign the the symbol. The current counter gets set
691 to <computeroutput>1+</computeroutput> this value.
696 <term><parameter>separator-string</parameter></term>
698 <para>A string that governs the creation of constants. The
699 default is <computeroutput>"#"</computeroutput>.</para>
705 <title>Description</title>
707 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
708 values are created by the <function>concatenation</function> of the
709 enumeration name, separator-string, and field symbol. Also creates
710 a foreign type with the name <parameter>name</parameter> of type
711 <constant>:int</constant>.
715 <title>Examples</title>
717 (def-enum abc (:a :b :c))
718 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
719 ;; the foreign type "abc" to be :int
721 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
722 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
723 ;; the foreign type efoo to be :int
727 <title>Side Effects</title>
728 <para>Creates a :int foreign type, defines constants.</para>
731 <title>Affected by</title>
735 <title>Exceptional Situations</title>
741 <refentry id="def-struct">
743 <refname>def-struct</refname>
744 <refpurpose>Defines a &c; structure.
746 <refclass>Macro</refclass>
749 <title>Syntax</title>
751 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
755 <title>Arguments and Values</title>
758 <term><parameter>name</parameter></term>
760 <para>A symbol that names the structure.
765 <term><parameter>fields</parameter></term>
767 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
774 <title>Description</title>
776 Declares a structure. A special type is available as a slot
777 in the field. It is a pointer that points to an instance of the parent
778 structure. It's type is <constant>:pointer-self</constant>.
783 <title>Examples</title>
785 (def-struct foo (a :unsigned-int)
788 (next :pointer-self))
792 <title>Side Effects</title>
793 <para>Creates a foreign type.</para>
796 <title>Affected by</title>
800 <title>Exceptional Situations</title>
806 <refentry id="get-slot-value">
808 <refname>get-slot-value</refname>
809 <refpurpose>Retrieves a value from a slot of a structure.
811 <refclass>Macro</refclass>
814 <title>Syntax</title>
816 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
820 <title>Arguments and Values</title>
823 <term><parameter>obj</parameter></term>
825 <para>A pointer to foreign structure.
830 <term><parameter>type</parameter></term>
832 <para>A name of the foreign structure.
837 <term><parameter>field</parameter></term>
839 <para>A name of the desired field in foreign structure.
844 <term><returnvalue>value</returnvalue></term>
846 <para>The value of the field in the structure.
853 <title>Description</title>
855 Accesses a slot value from a structure.
859 <title>Examples</title>
861 (get-slot-value foo-ptr 'foo-structure 'field-name)
865 <title>Side Effects</title>
869 <title>Affected by</title>
873 <title>Exceptional Situations</title>
878 <refentry id="get-slot-pointer">
880 <refname>get-slot-pointer</refname>
881 <refpurpose>Retrieves a pointer from a slot of a structure.
883 <refclass>Macro</refclass>
886 <title>Syntax</title>
888 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
892 <title>Arguments and Values</title>
895 <term><parameter>obj</parameter></term>
897 <para>A pointer to foreign structure.
902 <term><parameter>type</parameter></term>
904 <para>A name of the foreign structure.
909 <term><parameter>field</parameter></term>
911 <para>A name of the desired field in foreign structure.
916 <term><returnvalue>pointer</returnvalue></term>
918 <para>The value of the field in the structure.
925 <title>Description</title>
927 This is similar to <function>get-slot-value</function>. It
928 is used when the value of a slot is a pointer type.
932 <title>Examples</title>
934 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
938 <title>Side Effects</title>
942 <title>Affected by</title>
946 <title>Exceptional Situations</title>
952 <refentry id="def-array-pointer">
954 <refname>def-array-pointer</refname>
955 <refpurpose>Defines a pointer to a array of type.
957 <refclass>Macro</refclass>
960 <title>Syntax</title>
962 <function>def-array-pointer</function> <replaceable>name type</replaceable>
966 <title>Arguments and Values</title>
969 <term><parameter>name</parameter></term>
971 <para>A name of the new foreign type.
976 <term><parameter>type</parameter></term>
978 <para>The foreign type of the array elements.
985 <title>Description</title>
987 Defines a type tat is a pointer to an array of type.
991 <title>Examples</title>
993 (def-array-pointer byte-array-pointer :unsigned-char)
997 <title>Side Effects</title>
998 <para>Defines a new foreign type.</para>
1001 <title>Affected by</title>
1005 <title>Exceptional Situations</title>
1011 <refentry id="deref-array">
1013 <refname>deref-array</refname>
1014 <refpurpose>Deference an array.
1016 <refclass>Macro</refclass>
1019 <title>Syntax</title>
1021 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
1025 <title>Arguments and Values</title>
1028 <term><parameter>array</parameter></term>
1030 <para>A foreign array.
1035 <term><parameter>type</parameter></term>
1037 <para>The foreign type of the array.
1042 <term><parameter>position</parameter></term>
1044 <para>An integer specifying the position to retrieve from
1050 <term><returnvalue>value</returnvalue></term>
1052 <para>The value stored in the position of the array.
1059 <title>Description</title>
1061 Dereferences (retrieves) the value of an array element.
1065 <title>Examples</title>
1067 (def-array-pointer ca :char)
1068 (let ((fs (convert-to-foreign-string "ab")))
1069 (values (null-char-p (deref-array fs 'ca 0))
1070 (null-char-p (deref-array fs 'ca 2))))
1076 <title>Notes</title>
1078 The TYPE argument is ignored for CL implementations other than
1079 AllegroCL. If you want to cast a pointer to another type use
1080 WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.
1084 <title>Side Effects</title>
1088 <title>Affected by</title>
1092 <title>Exceptional Situations</title>
1097 <refentry id="def-union">
1099 <refname>def-union</refname>
1100 <refpurpose>Defines a foreign union type.
1102 <refclass>Macro</refclass>
1105 <title>Syntax</title>
1107 <function>def-union</function> <replaceable>name &rest fields</replaceable>
1111 <title>Arguments and Values</title>
1114 <term><parameter>name</parameter></term>
1116 <para>A name of the new union type.
1121 <term><parameter>fields</parameter></term>
1123 <para>A list of fields of the union.
1130 <title>Description</title>
1132 Defines a foreign union type.
1136 <title>Examples</title>
1138 (def-union test-union
1142 (let ((u (allocate-foreign-object 'test-union))
1143 (setf (get-slot-value u 'test-union 'an-int) (+ 65 (* 66 256)))
1145 (ensure-char-character (get-slot-value u 'test-union 'a-char))
1146 (free-foreign-object u)))
1151 <title>Side Effects</title>
1152 <para>Defines a new foreign type.</para>
1155 <title>Affected by</title>
1159 <title>Exceptional Situations</title>
1168 <title>Objects</title>
1170 <title>Overview</title>
1172 Objects are entities that can allocated, referred to by pointers, and
1178 <refentry id="allocate-foreign-object">
1180 <refname>allocate-foreign-object</refname>
1181 <refpurpose>Allocates an instance of a foreign object.
1183 <refclass>Macro</refclass>
1186 <title>Syntax</title>
1188 <function>allocate-foreign-object</function> <replaceable>type &optional size</replaceable> => <returnvalue>ptr</returnvalue>
1192 <title>Arguments and Values</title>
1195 <term><parameter>type</parameter></term>
1197 <para>The type of foreign object to allocate. This parameter is evaluated.
1202 <term><parameter>size</parameter></term>
1204 <para>An optional size parameter that is evaluated. If specified, allocates and returns an
1205 array of <parameter>type</parameter> that is <parameter>size</parameter> members long. This parameter is evaluated.
1210 <term><returnvalue>ptr</returnvalue></term>
1212 <para>A pointer to the foreign object.
1219 <title>Description</title>
1221 Allocates an instance of a foreign object. It returns a pointer to the object.
1225 <title>Examples</title>
1227 (def-struct ab (a :int) (b :double))
1228 (allocate-foreign-object 'ab)
1233 <title>Side Effects</title>
1237 <title>Affected by</title>
1241 <title>Exceptional Situations</title>
1247 <refentry id="free-foreign-object">
1249 <refname>free-foreign-object</refname>
1250 <refpurpose>Frees memory that was allocated for a foreign boject.
1252 <refclass>Macro</refclass>
1255 <title>Syntax</title>
1257 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
1261 <title>Arguments and Values</title>
1264 <term><parameter>ptr</parameter></term>
1266 <para>A pointer to the allocated foreign object to free.
1273 <title>Description</title>
1275 Frees the memory used by the allocation of a foreign object.
1279 <title>Side Effects</title>
1283 <title>Affected by</title>
1287 <title>Exceptional Situations</title>
1293 <refentry id="with-foreign-object">
1295 <refname>with-foreign-object</refname>
1296 <refpurpose>Wraps the allocation of a foreign object around a body of code.
1298 <refclass>Macro</refclass>
1301 <title>Syntax</title>
1303 <function>with-foreign-object</function> <replaceable>(var type) &body body</replaceable> => <returnvalue>form-return</returnvalue>
1307 <title>Arguments and Values</title>
1310 <term><parameter>var</parameter></term>
1312 <para>The variable name to bind.
1317 <term><parameter>type</parameter></term>
1319 <para>The type of foreign object to allocate. This parameter is evaluated.
1324 <term><returnvalue>form-return</returnvalue></term>
1326 <para>The result of evaluating the <parameter>body</parameter>.
1333 <title>Description</title>
1335 This function wraps the allocation, binding, and destruction of a foreign object.
1337 &lw; platforms the object is stack allocated for efficiency. Benchmarks show that &acl; performs
1338 much better with static allocation.
1342 <title>Examples</title>
1344 (defun gethostname2 ()
1345 "Returns the hostname"
1346 (uffi:with-foreign-object (name '(:array :unsigned-char 256))
1347 (if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256))
1348 (uffi:convert-from-foreign-string name)
1349 (error "gethostname() failed."))))
1353 <title>Side Effects</title>
1357 <title>Affected by</title>
1361 <title>Exceptional Situations</title>
1366 <refentry id="size-of-foreign-type">
1368 <refname>size-of-foreign-type</refname>
1369 <refpurpose>Returns the number of data bytes used by a foreign object type.
1371 <refclass>Macro</refclass>
1374 <title>Syntax</title>
1376 <function>size-of-foreign-type</function> <replaceable>ftype</replaceable>
1380 <title>Arguments and Values</title>
1383 <term><parameter>ftype</parameter></term>
1385 <para>A foreign type specifier. This parameter is evaluated.
1392 <title>Description</title>
1394 Returns the number of data bytes used by a foreign object type. This does not include any Lisp storage overhead.
1398 <title>Examples</title>
1401 (size-of-foreign-object :unsigned-byte)
1403 (size-of-foreign-object 'my-100-byte-vector-type)
1409 <title>Side Effects</title>
1411 </refsect1> <refsect1>
1412 <title>Affected by</title>
1416 <title>Exceptional Situations</title>
1421 <refentry id="pointer-address">
1423 <refname>pointer-address</refname>
1424 <refpurpose>Returns the address of a pointer.
1426 <refclass>Macro</refclass>
1429 <title>Syntax</title>
1431 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
1435 <title>Arguments and Values</title>
1438 <term><parameter>ptr</parameter></term>
1440 <para>A pointer to a foreign object.
1445 <term><parameter>address</parameter></term>
1447 <para>An integer representing the pointer's address.
1454 <title>Description</title>
1456 Returns the address as an integer of a pointer.
1460 <title>Side Effects</title>
1464 <title>Affected by</title>
1468 <title>Exceptional Situations</title>
1474 <refentry id="deref-pointer">
1476 <refname>deref-pointer</refname>
1477 <refpurpose>Deferences a pointer.
1479 <refclass>Macro</refclass>
1482 <title>Syntax</title>
1484 <function>deref-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
1488 <title>Arguments and Values</title>
1491 <term><parameter>ptr</parameter></term>
1493 <para>A pointer to a foreign object.
1498 <term><parameter>type</parameter></term>
1500 <para>A foreign type of the object being pointed to.
1505 <term><returnvalue>value</returnvalue></term>
1507 <para>The value of the object where the pointer points.
1514 <title>Description</title>
1516 Returns the object to which a pointer points.
1520 <title>Examples</title>
1523 (let ((intp (allocate-foreign-object :int)))
1524 (setf (deref-pointer intp :int) 10)
1526 (deref-pointer intp :int)
1527 (free-foreign-object intp)))
1533 <title>Notes</title>
1535 The TYPE argument is ignored for CL implementations other than
1536 AllegroCL. If you want to cast a pointer to another type use
1537 WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.
1541 <title>Side Effects</title>
1545 <title>Affected by</title>
1549 <title>Exceptional Situations</title>
1554 <refentry id="ensure-char-character">
1556 <refname>ensure-char-character</refname>
1557 <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
1560 <refclass>Macro</refclass>
1563 <title>Syntax</title>
1565 <function>ensure-char-character</function> <replaceable>object</replaceable> => <returnvalue>char</returnvalue>
1569 <title>Arguments and Values</title>
1572 <term><parameter>object</parameter></term>
1574 <para>Either a character or a integer specifying a character code.
1579 <term><returnvalue>char</returnvalue></term>
1588 <title>Description</title>
1590 Ensures that an objects obtained by dereferencing
1591 <constant>:char</constant> and <constant>:unsigned-char</constant>
1592 pointers are a lisp character.
1596 <title>Examples</title>
1599 (let ((fs (convert-to-foreign-string "a")))
1601 (ensure-char-character (deref-pointer fs :char))
1602 (free-foreign-object fs)))
1608 <title>Side Effects</title>
1612 <title>Affected by</title>
1616 <title>Exceptional Situations</title>
1617 <para>Depending upon the implementation and what &uffi; expects, this
1618 macro may signal an error if the object is not a character or
1623 <refentry id="ensure-char-integer">
1625 <refname>ensure-char-integer</refname>
1626 <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
1629 <refclass>Macro</refclass>
1632 <title>Syntax</title>
1634 <function>ensure-char-integer</function> <replaceable>object</replaceable> => <returnvalue>int</returnvalue>
1638 <title>Arguments and Values</title>
1641 <term><parameter>object</parameter></term>
1643 <para>Either a character or a integer specifying a character code.
1648 <term><returnvalue>int</returnvalue></term>
1657 <title>Description</title>
1659 Ensures that an object obtained by dereferencing a
1660 <constant>:char</constant> pointer is an integer.
1664 <title>Examples</title>
1667 (let ((fs (convert-to-foreign-string "a")))
1669 (ensure-char-integer (deref-pointer fs :char))
1670 (free-foreign-object fs)))
1676 <title>Side Effects</title>
1680 <title>Affected by</title>
1684 <title>Exceptional Situations</title>
1685 <para>Depending upon the implementation and what &uffi; expects, this
1686 macro may signal an error if the object is not a character or
1691 <refentry id="make-null-pointer">
1693 <refname>make-null-pointer</refname>
1694 <refpurpose>Create a &null; pointer.
1696 <refclass>Macro</refclass>
1699 <title>Syntax</title>
1701 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1705 <title>Arguments and Values</title>
1708 <term><parameter>type</parameter></term>
1710 <para>A type of object to which the pointer refers.
1715 <term><parameter>ptr</parameter></term>
1717 <para>The &null; pointer of type <parameter>type</parameter>.
1724 <title>Description</title>
1726 Creates a &null; pointer of a specified type.
1730 <title>Side Effects</title>
1734 <title>Affected by</title>
1738 <title>Exceptional Situations</title>
1744 <refentry id="null-pointer-p">
1746 <refname>null-pointer-p</refname>
1747 <refpurpose>Tests a pointer for &null; value.
1749 <refclass>Macro</refclass>
1752 <title>Syntax</title>
1754 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1758 <title>Arguments and Values</title>
1761 <term><parameter>ptr</parameter></term>
1763 <para>A foreign object pointer.
1768 <term><returnvalue>is-null</returnvalue></term>
1770 <para>The boolean flag.
1777 <title>Description</title>
1779 A predicate testing if a pointer is has a &null; value.
1783 <title>Side Effects</title>
1787 <title>Affected by</title>
1791 <title>Exceptional Situations</title>
1797 <refentry id="null-cstring-pointer">
1799 <refname>+null-cstring-pointer+</refname>
1800 <refpurpose>A constant &null; cstring pointer.
1802 <refclass>Constant</refclass>
1805 <title>Description</title>
1807 A &null; cstring pointer. This can be used for testing
1808 if a cstring returned by a function is &null;.
1813 <refentry id="with-cast-pointer">
1815 <refname>with-cast-pointer</refname>
1816 <refpurpose>Wraps a body of code with a pointer cast to a new type.
1818 <refclass>Macro</refclass>
1821 <title>Syntax</title>
1823 <function>with-cast-pointer</function> (<replaceable>binding-name ptr type) & body body</replaceable> => <returnvalue>value</returnvalue>
1827 <title>Arguments and Values</title>
1830 <term><parameter>ptr</parameter></term>
1832 <para>A pointer to a foreign object.
1837 <term><parameter>type</parameter></term>
1839 <para>A foreign type of the object being pointed to.
1844 <term><returnvalue>value</returnvalue></term>
1846 <para>The value of the object where the pointer points.
1853 <title>Description</title>
1855 Executes BODY with POINTER cast to be a pointer to type TYPE. If
1856 BINDING-NAME is provided the cast pointer will be bound to this
1857 name during the execution of BODY. If BINDING-NAME is not provided
1858 POINTER must be a name bound to the pointer which should be
1859 cast. This name will be bound to the cast pointer during the
1862 This is a no-op in AllegroCL but will wrap BODY in a LET form if
1863 BINDING-NAME is provided.
1865 This macro is meant to be used in conjunction with DEREF-POINTER or
1866 DEREF-ARRAY. In Allegro CL the "cast" will actually take place in
1867 DEREF-POINTER or DEREF-ARRAY.
1871 <title>Examples</title>
1873 (with-foreign-object (size :int)
1874 ;; FOO is a foreign function returning a :POINTER-VOID
1875 (let ((memory (foo size)))
1877 ;; at this point we know for some reason that MEMORY points
1878 ;; to an array of unsigned bytes
1879 (with-cast-pointer (memory :unsigned-byte)
1880 (dotimes (i (deref-pointer size :int))
1882 (deref-array memory '(:array :unsigned-byte) i)))))))
1886 <title>Side Effects</title>
1890 <title>Affected by</title>
1894 <title>Exceptional Situations</title>
1899 <refentry id="def-foreign-var">
1901 <refname>def-foreign-var</refname>
1903 Defines a symbol macro to access a variable in foreign code
1905 <refclass>Macro</refclass>
1908 <title>Syntax</title>
1910 <function>def-foreign-var</function> <replaceable>name type module</replaceable>
1914 <title>Arguments and Values</title>
1917 <term><parameter>name</parameter></term>
1920 A string or list specificying the symbol macro's name. If it is a
1921 string, that names the foreign variable. A Lisp name is created
1922 by translating #\_ to #\- and by converting to upper-case in
1923 case-insensitive Lisp implementations. If it is a list, the first
1924 item is a string specifying the foreign variable name and the
1925 second it is a symbol stating the Lisp name.
1930 <term><parameter>type</parameter></term>
1932 <para>A foreign type of the foreign variable.
1937 <term><returnvalue>module</returnvalue></term>
1940 A string specifying the module (or library) the foreign variable
1941 resides in. (Required by Lispworks)
1948 <title>Description</title>
1950 Defines a symbol macro which can be used to access (get and set) the
1951 value of a variable in foreign code.
1955 <title>Examples</title>
1957 <title>C code</title>
1966 foo_struct the_struct = { 42, 3.2 };
1974 <title>Lisp code</title>
1976 (uffi:def-struct foo-struct
1980 (uffi:def-function ("foo" foo)
1985 (uffi:def-foreign-var ("baz" *baz*) :int "foo")
1986 (uffi:def-foreign-var ("the_struct" *the-struct*) foo-struct "foo")
2001 <title>Side Effects</title>
2005 <title>Affected by</title>
2009 <title>Exceptional Situations</title>
2017 <title>Strings</title>
2019 <title>Overview</title>
2022 &uffi; has functions to two types of
2023 <varname>C</varname>-compatible
2024 strings: <emphasis>cstring</emphasis> and
2025 <emphasis>foreign</emphasis> strings.
2027 cstrings are used <emphasis>only</emphasis> as parameters to and from
2028 functions. In some implementations a cstring is not a foreign type but
2029 rather the Lisp string itself. On other platforms a cstring is a newly
2030 allocated foreign vector for storing characters. The following is an
2031 example of using cstrings to both send and return a value.
2035 (uffi:def-function ("getenv" c-getenv)
2037 :returning :cstring)
2039 (defun my-getenv (key)
2040 "Returns an environment variable, or NIL if it does not exist"
2041 (check-type key string)
2042 (uffi:with-cstring (key-native key)
2043 (uffi:convert-from-cstring (c-getenv key-native))))
2046 <para> In contrast, foreign strings are always a foreign vector of
2047 characters which have memory allocated. Thus, if you need to allocate
2048 memory to hold the return value of a string, you must use a foreign
2049 string and not a cstring. The following is an example of using a foreign
2050 string for a return value. </para>
2053 (uffi:def-function ("gethostname" c-gethostname)
2054 ((name (* :unsigned-char))
2058 (defun gethostname ()
2059 "Returns the hostname"
2060 (let* ((name (uffi:allocate-foreign-string 256))
2061 (result-code (c-gethostname name 256))
2062 (hostname (when (zerop result-code)
2063 (uffi:convert-from-foreign-string name))))
2064 (uffi:free-foreign-object name)
2065 (unless (zerop result-code)
2066 (error "gethostname() failed."))))
2069 <para> Foreign functions that return pointers to freshly allocated
2070 strings should in general not return cstrings, but foreign strings.
2071 (There is no portable way to release such cstrings from Lisp.) The
2072 following is an example of handling such a function. </para>
2075 (uffi:def-function ("readline" c-readline)
2077 :returning (* :char))
2079 (defun readline (prompt)
2080 "Reads a string from console with line-editing."
2081 (with-cstring (c-prompt prompt)
2082 (let* ((c-str (c-readline c-prompt))
2083 (str (convert-from-foreign-string c-str)))
2084 (uffi:free-foreign-object c-str)
2090 <refentry id="convert-from-cstring">
2092 <refname>convert-from-cstring</refname>
2093 <refpurpose>Converts a cstring to a Lisp string.
2095 <refclass>Macro</refclass>
2098 <title>Syntax</title>
2100 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
2104 <title>Arguments and Values</title>
2107 <term><parameter>cstring</parameter></term>
2114 <term><returnvalue>string</returnvalue></term>
2116 <para>A Lisp string.
2123 <title>Description</title>
2125 Converts a Lisp string to a <constant>cstring</constant>. This is
2126 most often used when processing the results of a foreign function
2127 that returns a cstring.
2131 <title>Side Effects</title>
2135 <title>Affected by</title>
2139 <title>Exceptional Situations</title>
2145 <refentry id="convert-to-cstring">
2147 <refname>convert-to-cstring</refname>
2148 <refpurpose>Converts a Lisp string to a cstring.
2150 <refclass>Macro</refclass>
2153 <title>Syntax</title>
2155 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
2159 <title>Arguments and Values</title>
2162 <term><parameter>string</parameter></term>
2164 <para>A Lisp string.
2169 <term><returnvalue>cstring</returnvalue></term>
2178 <title>Description</title>
2180 Converts a Lisp string to a
2181 <varname>cstring</varname>. The
2182 <varname>cstring</varname> should be freed with
2183 <function>free-cstring</function>.
2187 <title>Side Effects</title>
2188 <para>On some implementations, this function allocates memory.</para>
2191 <title>Affected by</title>
2195 <title>Exceptional Situations</title>
2201 <refentry id="free-cstring">
2203 <refname>free-cstring</refname>
2204 <refpurpose>Free memory used by cstring.
2206 <refclass>Macro</refclass>
2209 <title>Syntax</title>
2211 <function>free-cstring</function> <replaceable>cstring</replaceable>
2215 <title>Arguments and Values</title>
2218 <term><parameter>cstring</parameter></term>
2227 <title>Description</title>
2229 Frees any memory possibly allocated by
2230 <function>convert-to-cstring</function>. On some implementions, a cstring is just the Lisp string itself.
2234 <title>Side Effects</title>
2238 <title>Affected by</title>
2242 <title>Exceptional Situations</title>
2248 <refentry id="with-cstring">
2250 <refname>with-cstring</refname>
2251 <refpurpose>Binds a newly created cstring.
2253 <refclass>Macro</refclass>
2256 <title>Syntax</title>
2258 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
2262 <title>Arguments and Values</title>
2265 <term><parameter>cstring</parameter></term>
2267 <para>A symbol naming the cstring to be created.
2272 <term><parameter>string</parameter></term>
2274 <para>A Lisp string that will be translated to a cstring.
2279 <term><parameter>body</parameter></term>
2281 <para>The body of where the cstring will be bound.
2288 <title>Description</title>
2290 Binds a symbol to a cstring created from conversion of a string. Automatically frees the <varname>cstring</varname>.
2294 <title>Examples</title>
2297 (def-function ("getenv" c-getenv)
2299 :returning :cstring)
2302 "Returns an environment variable, or NIL if it does not exist"
2303 (check-type key string)
2304 (with-cstring (key-cstring key)
2305 (convert-from-cstring (c-getenv key-cstring))))
2310 <title>Side Effects</title>
2314 <title>Affected by</title>
2318 <title>Exceptional Situations</title>
2324 <refentry id="convert-from-foreign-string">
2326 <refname>convert-from-foreign-string</refname>
2327 <refpurpose>Converts a foreign string into a Lisp string.
2329 <refclass>Macro</refclass>
2332 <title>Syntax</title>
2334 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
2338 <title>Arguments and Values</title>
2341 <term><parameter>foreign-string</parameter></term>
2343 <para>A foreign string.
2348 <term><parameter>length</parameter></term>
2350 <para>The length of the foreign string to
2351 convert. The default is the length of the string until a &null;
2352 character is reached.
2357 <term><parameter>null-terminated-p</parameter></term>
2359 <para>A boolean flag with a default value of &t; When true,
2360 the string is converted until the first &null; character is reached.
2365 <term><returnvalue>string</returnvalue></term>
2367 <para>A Lisp string.
2374 <title>Description</title>
2376 Returns a Lisp string from a foreign string.
2377 Can translated ASCII and binary strings.
2381 <title>Side Effects</title>
2385 <title>Affected by</title>
2389 <title>Exceptional Situations</title>
2395 <refentry id="convert-to-foreign-string">
2397 <refname>convert-to-foreign-string</refname>
2398 <refpurpose>Converts a Lisp string to a foreign string.
2400 <refclass>Macro</refclass>
2403 <title>Syntax</title>
2405 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
2409 <title>Arguments and Values</title>
2412 <term><parameter>string</parameter></term>
2414 <para>A Lisp string.
2419 <term><returnvalue>foreign-string</returnvalue></term>
2421 <para>A foreign string.
2428 <title>Description</title>
2430 Converts a Lisp string to a foreign string. Memory should be
2431 freed with <function>free-foreign-object</function>.
2435 <title>Side Effects</title>
2439 <title>Affected by</title>
2443 <title>Exceptional Situations</title>
2450 <refentry id="allocate-foreign-string">
2452 <refname>allocate-foreign-string</refname>
2453 <refpurpose>Allocates space for a foreign string.
2455 <refclass>Macro</refclass>
2458 <title>Syntax</title>
2460 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
2464 <title>Arguments and Values</title>
2467 <term><parameter>size</parameter></term>
2469 <para>The size of the space to be allocated in bytes.
2474 <term><parameter>unsigned</parameter></term>
2476 <para>A boolean flag with a default value of &t;. When true,
2477 marks the pointer as an <constant>:unsigned-char</constant>.
2482 <term><returnvalue>foreign-string</returnvalue></term>
2484 <para>A foreign string which has undefined contents.
2491 <title>Description</title>
2493 Allocates space for a foreign string. Memory should
2494 be freed with <function>free-foreign-object</function>.
2498 <title>Side Effects</title>
2502 <title>Affected by</title>
2506 <title>Exceptional Situations</title>
2514 <title>Functions & Libraries</title>
2516 <refentry id="def-function">
2518 <refname>def-function</refname>
2519 <refpurpose>Declares a function.
2521 <refclass>Macro</refclass>
2524 <title>Syntax</title>
2526 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
2530 <title>Arguments and Values</title>
2533 <term><parameter>name</parameter></term>
2535 <para>A string or list specificying the function name. If it is a string, that names the foreign function. A Lisp name is created by translating #\_ to #\- and by converting to upper-case in case-insensitive Lisp implementations. If it is a list, the first item is a string specifying the foreign function name and the second it is a symbol stating the Lisp name.
2540 <term><parameter>args</parameter></term>
2542 <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
2547 <term><parameter>module</parameter></term>
2549 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
2553 <term><returnvalue>returning</returnvalue></term>
2555 <para>A declaration specifying the result type of the
2556 foreign function. If <constant>:void</constant> indicates module does not return any value.
2563 <title>Description</title>
2564 <para>Declares a foreign function.
2568 <title>Examples</title>
2570 (def-function "gethostname"
2571 ((name (* :unsigned-char))
2577 <title>Side Effects</title>
2581 <title>Affected by</title>
2585 <title>Exceptional Situations</title>
2590 <refentry id="load-foreign-library">
2592 <refname>load-foreign-library</refname>
2593 <refpurpose>Loads a foreign library.
2595 <refclass>Function</refclass>
2598 <title>Syntax</title>
2600 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries force-load</replaceable> => <returnvalue>success</returnvalue>
2604 <title>Arguments and Values</title>
2607 <term><parameter>filename</parameter></term>
2609 <para>A string or pathname specifying the library location
2610 in the filesystem. At least one implementation (&lw;) can not
2611 accept a logical pathname.
2616 <term><parameter>module</parameter></term>
2618 <para>A string designating the name of the module to apply
2619 to functions in this library. (Required for Lispworks)
2624 <term><parameter>supporting-libraries</parameter></term>
2626 <para>A list of strings naming the libraries required to
2627 link the foreign library. (Required by CMUCL)
2632 <term><parameter>force-load</parameter></term>
2634 <para>Forces the loading of the library if it has been previously loaded.
2639 <term><returnvalue>success</returnvalue></term>
2641 <para>A boolean flag, &t; if the library was able to be
2642 loaded successfully or if the library has been previously loaded,
2650 <title>Description</title>
2651 <para>Loads a foreign library. Applies a module name to functions
2652 within the library. Ensures that a library is only loaded once during
2653 a session. A library can be reloaded by using the <symbol>:force-load</symbol> key.
2657 <title>Examples</title>
2659 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
2661 :supporting-libraries '("c"))
2666 <title>Side Effects</title>
2667 <para>Loads the foreign code into the Lisp system.
2671 <title>Affected by</title>
2672 <para>Ability to load the file.</para>
2675 <title>Exceptional Situations</title>
2680 <refentry id="find-foreign-library">
2682 <refname>find-foreign-library</refname>
2683 <refpurpose>Finds a foreign library file.
2685 <refclass>Function</refclass>
2688 <title>Syntax</title>
2690 <function>find-foreign-library</function> <replaceable>names directories & drive-letters types</replaceable> => <returnvalue>path</returnvalue>
2694 <title>Arguments and Values</title>
2697 <term><parameter>names</parameter></term>
2699 <para>A string or list of strings containing the base name of the library file.
2704 <term><parameter>directories</parameter></term>
2706 <para>A string or list of strings containing the directory the library file.
2711 <term><parameter>drive-letters</parameter></term>
2713 <para>A string or list of strings containing the drive letters for the library file.
2718 <term><parameter>types</parameter></term>
2720 <para>A string or list of strings containing the file type of the library file. Default
2721 is &nil;. If &nil;, will use a default type based on the currently running implementation.
2726 <term><returnvalue>path</returnvalue></term>
2728 <para>A path containing the path found, or &nil; if the library file was not found.
2735 <title>Description</title>
2736 <para>Finds a foreign library by searching through a number of possible locations. Returns
2737 the path of the first found file.
2741 <title>Examples</title>
2743 (find-foreign-library '("libmysqlclient" "libmysql")
2744 '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/")
2745 :types '("so" "dll")
2746 :drive-letters '("C" "D" "E"))
2747 => #P"D:\\mysql\\lib\\opt\\libmysql.dll"
2751 <title>Side Effects</title>
2756 <title>Affected by</title>
2760 <title>Exceptional Situations</title>
2769 <title>Installation</title>
2771 <title>Download &uffi;</title>
2773 You need to download the &uffi; package from its web
2774 <ulink url="http://uffi.med-info.com"><citetitle>home</citetitle></ulink>.
2775 You also need to have a copy of &asdf;. If you need a copy of
2776 &asdf;, it is included in the
2778 url="http://www.sourceforge.net/projects/cclan">
2779 <citetitle>CCLAN</citetitle></ulink> package. You can download
2780 the file <filename>defsystem.lisp</filename> from the CVS
2781 <ulink url="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cclan/asdf/asdf.lisp"><citetitle>tree</citetitle></ulink>.
2785 <title>Installation</title>
2787 After downloading and installing &asdf;, simply
2788 <function>push</function> the
2789 directory containing &uffi; into
2790 <varname>asdf:*central-registry*</varname> variable. Whenever you
2791 want to load the &uffi; package, use the function
2792 <computeroutput>(asdf:oos 'asdf:load-op :uffi)</computeroutput>.
2799 <glossentry id="gloss-ffi">
2800 <glossterm>Foreign Function Interface
2801 <acronym>FFI</acronym>)
2805 An interface to a C-compatible library.