r3585: *** empty log message ***
[hyperobject.git] / doc / ref.sgml
diff --git a/doc/ref.sgml b/doc/ref.sgml
new file mode 100644 (file)
index 0000000..f299c19
--- /dev/null
@@ -0,0 +1,2218 @@
+<!-- -*- DocBook -*- -->
+
+  
+<reference>
+  <title>Declarations</title>
+
+  <partintro>
+    <sect1>
+      <title>Overview</title>
+      <para>Declarations are used to give the compiler optimizing
+       information about foreign types. Currently, only &cmucl;
+       supports declarations. On &acl; and &lw;, these expressions 
+       declare the type generically as &t;
+      </para>
+    </sect1>
+  </partintro>
+
+      <refentry id="def-type">
+       <refnamediv>
+         <refname>def-type</refname>
+       <refpurpose>Defines a Common Lisp type. 
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-type</function> <replaceable>name type</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A symbol naming the type</para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A form that is evaluated that specifies the &uffi; type.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>Defines a Common Lisp type based on a &uffi; type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-type char-ptr '(* :char))
+...
+(defun foo (ptr)
+  (declare (type char-ptr ptr))
+  ...
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Defines a new &cl; type.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+  </reference>
+
+
+  <reference>
+    <title>Primitive Types</title>
+    <partintro>
+      <title>Overview</title>
+       <para>
+         Primitive types have a single value, these include
+         characters, numbers, and pointers. They are all symbols in
+         the keyword package.
+       </para>
+       <itemizedlist>
+         <listitem>
+           <para><constant>:char</constant> - Signed 8-bits. A
+dereferenced :char pointer returns an character.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:unsigned-char</constant> - Unsigned 8-bits. A dereferenced :unsigned-char
+pointer returns an character.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:byte</constant> - Signed 8-bits. A
+dereferenced :byte pointer returns an integer.</para>
+          </listitem>
+         <listitem>
+           <para><constant>:unsigned-byte</constant> - Unsigned 8-bits. A
+dereferenced :unsigned-byte pointer returns an integer.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:short</constant> - Signed 16-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:int</constant> - Signed 32-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:long</constant> - Signed 32-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:unsigned-long</constant> - Unsigned 32-bits.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:float</constant> - 32-bit floating point.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:double</constant> - 64-bit floating point.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:cstring</constant> - 
+A &null; terminated string used for passing and returning characters strings with a &c; function.
+           </para>
+         </listitem>
+         <listitem>
+           <para><constant>:void</constant> - 
+The absence of a value. Used to indicate that a function does not return a value.</para>
+         </listitem>
+         <listitem>
+           <para><constant>:pointer-void</constant> - 
+Points to a generic object.</para>
+         </listitem>
+         <listitem>
+           <para><constant>*</constant> - Used to declare a pointer to an object</para>
+         </listitem>
+       </itemizedlist>
+      </partintro>
+
+      <refentry id="def-constant">
+       <refnamediv>
+         <refname>def-constant</refname>
+       <refpurpose>Binds a symbol to a constant. 
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-constant</function> <replaceable>name value &amp;key export</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A symbol that will be bound to the value.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>value</parameter></term>
+           <listitem>
+             <para>An evaluated form that is bound the the name.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>export</parameter></term>
+           <listitem>
+             <para>When &t;, the name is exported from the current package. The default is &nil;</para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         This is a thin wrapper around
+         <function>defconstant</function>. It evaluates at
+           compile-time and optionally exports the symbol from the package.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-constant pi2 (* 2 pi))
+(def-constant exported-pi2 (* 2 pi) :export t)
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Creates a new special variable..</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="def-foreign-type">
+       <refnamediv>
+         <refname>def-foreign-type</refname>
+       <refpurpose>Defines a new foreign type. 
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsect1>
+       <title>Syntax</title>
+<synopsis>
+         <function>def-foreign-type</function> <replaceable>name type</replaceable>
+</synopsis>
+      </refsect1>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A symbol naming the new foreign type.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>value</parameter></term>
+           <listitem>
+             <para>A form that is not evaluated that defines the new
+foreign type.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>Defines a new foreign type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-foreign-type my-generic-pointer :pointer-void)
+(def-foreign-type a-double-float :double-float)
+(def-foreign-type char-ptr (* :char))
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Defines a new foreign type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="null-char-p">
+       <refnamediv>
+         <refname>null-char-p</refname>
+       <refpurpose>Tests a character for &null; value.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsect1>
+       <title>Syntax</title>
+<synopsis>
+         <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
+</synopsis>
+      </refsect1>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>char</parameter></term>
+           <listitem>
+             <para>A character or integer.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>is-null</parameter></term>
+           <listitem>
+             <para>A boolean flag indicating if char is a &null; value.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         A predicate testing if a character or integer is &null;. This
+abstracts the difference in implementations where some return a 
+<computeroutput>character</computeroutput> and some return a 
+<computeroutput>integer</computeroutput> whence dereferencing a 
+<computeroutput>C</computeroutput> character pointer.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-array-pointer ca :unsigned-char)
+(let ((fs (convert-to-foreign-string "ab")))
+   (values (null-char-p (deref-array fs 'ca 0))
+           (null-char-p (deref-array fs 'ca 2))))
+=> &nil;
+   &t;
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+  </reference>
+
+  <reference>
+    <title>Aggregate Types</title>
+    <partintro>
+      <title>Overview</title>
+      <para>
+       Aggregate types are comprised of one or more primitive types.
+      </para>
+    </partintro>
+
+    <refentry id="def-enum">
+      <refnamediv>
+       <refname>def-enum</refname>
+       <refpurpose>Defines a &c; enumeration.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-enum</function> <replaceable>name fields &amp;key separator-string</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A symbol that names the enumeration.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>fields</parameter></term>
+           <listitem>
+             <para>A list of field defintions. Each definition can be
+a symbol or a list of two elements. Symbols get assigned a value of the
+current counter which starts at <computeroutput>0</computeroutput> and
+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
+position is the value to assign the the symbol. The current counter gets set
+to <computeroutput>1+</computeroutput> this value.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>separator-string</parameter></term>
+           <listitem>
+             <para>A string that governs the creation of constants. The
+default is <computeroutput>"#"</computeroutput>.</para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
+values are created by the <function>concatenation</function> of the
+enumeration name, separator-string, and field symbol. Also creates
+a foreign type with the name <parameter>name</parameter> of type
+<constant>:int</constant>.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-enum abc (:a :b :c)) 
+;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
+;; the foreign type "abc" to be :int
+
+(def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
+;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
+;; the foreign type efoo to be :int
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Creates a :int foreign type, defines constants.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+      <refentry id="def-struct">
+       <refnamediv>
+         <refname>def-struct</refname>
+       <refpurpose>Defines a &c; structure.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-struct</function> <replaceable>name &amp;rest fields</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A symbol that names the structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>fields</parameter></term>
+           <listitem>
+             <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Declares a structure. A special type is available as a slot
+in the field. It is a pointer that points to an instance of the parent
+structure. It's type is <constant>:pointer-self</constant>.
+
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-struct foo (a :unsigned-int) 
+                (b (* :char)) 
+                (c (:array :int 10)) 
+                (next :pointer-self))
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Creates a foreign type.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="get-slot-value">
+      <refnamediv>
+       <refname>get-slot-value</refname>
+       <refpurpose>Retrieves a value from a slot of a structure.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>obj</parameter></term>
+           <listitem>
+             <para>A pointer to foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A name of the foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>field</parameter></term>
+           <listitem>
+             <para>A name of the desired field in foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>value</returnvalue></term>
+           <listitem>
+             <para>The value of the field in the structure.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Accesses a slot value from a structure.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(get-slot-value foo-ptr 'foo-structure 'field-name)
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="get-slot-pointer">
+      <refnamediv>
+       <refname>get-slot-pointer</refname>
+       <refpurpose>Retrieves a pointer from a slot of a structure.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>obj</parameter></term>
+           <listitem>
+             <para>A pointer to foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A name of the foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>field</parameter></term>
+           <listitem>
+             <para>A name of the desired field in foreign structure.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>pointer</returnvalue></term>
+           <listitem>
+             <para>The value of the field in the structure.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         This is similar to <function>get-slot-value</function>. It
+         is used when the value of a slot is a pointer type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="def-array-pointer">
+      <refnamediv>
+       <refname>def-array-pointer</refname>
+       <refpurpose>Defines a pointer to a array of type.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-array-pointer</function> <replaceable>name type</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A name of the new foreign type.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>The foreign type of the array elements.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Defines a type tat is a pointer to an array of type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-array-pointer byte-array-pointer :unsigned-char)
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Defines a new foreign type.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="deref-array">
+      <refnamediv>
+       <refname>deref-array</refname>
+       <refpurpose>Deference an array.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>array</parameter></term>
+           <listitem>
+             <para>A foreign array.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>The foreign type of the array.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>position</parameter></term>
+           <listitem>
+             <para>An integer specifying the position to retrieve from
+the array.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>value</returnvalue></term>
+           <listitem>
+             <para>The value stored in the position of the array.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Dereferences (retrieves) the value of an array element.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-array ca :char)
+(let ((fs (convert-to-foreign-string "ab")))
+   (values (null-char-p (deref-array fs 'ca 0))
+           (null-char-p (deref-array fs 'ca 2))))
+=> &nil;
+   &t;
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="def-union">
+      <refnamediv>
+       <refname>def-union</refname>
+       <refpurpose>Defines a foreign union type.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-union</function> <replaceable>name &amp;rest fields</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <para>A name of the new union type.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>fields</parameter></term>
+           <listitem>
+             <para>A list of fields of the union.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Defines a foreign union type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-union test-union
+  (a-char :char)
+  (an-int :int))
+
+(let ((u (allocate-foreign-object 'test-union))
+  (setf (get-slot-value u 'test-union 'an-int) (+ 65 (* 66 256)))
+  (prog1 
+    (ensure-char-character (get-slot-value u 'test-union 'a-char))
+    (free-foreign-object u)))
+=> #\A
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Defines a new foreign type.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+</reference>
+
+<reference>
+    <title>Objects</title>
+<partintro>
+<title>Overview</title>
+    <para>
+      Objects are entities that can allocated, referred to by pointers, and
+can be freed.
+    </para>
+</partintro>
+
+
+    <refentry id="allocate-foreign-object">
+      <refnamediv>
+       <refname>allocate-foreign-object</refname>
+       <refpurpose>Allocates an instance of a foreign object.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>allocate-foreign-object</function> <replaceable>type &amp;optional size</replaceable> => <returnvalue>ptr</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>The type of foreign object to allocate. This parameter is evaluated.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>size</parameter></term>
+           <listitem>
+             <para>An optional size parameter that is evaluated. If specified, allocates and returns an
+array of <parameter>type</parameter> that is <parameter>size</parameter> members long. This parameter is evaluated.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>ptr</returnvalue></term>
+           <listitem>
+             <para>A pointer to the foreign object.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Allocates an instance of a foreign object. It returns a pointer to the object.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-struct ab (a :int) (b :double))
+(allocate-foreign-object 'ab)
+=> #&lt;ptr&gt;
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="free-foreign-object">
+      <refnamediv>
+       <refname>free-foreign-object</refname>
+       <refpurpose>Frees memory that was allocated for a foreign boject.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>free-foreign-object</function> <replaceable>ptr</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>A pointer to the allocated foreign object to free.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Frees the memory used by the allocation of a foreign object.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="with-foreign-object">
+      <refnamediv>
+       <refname>with-foreign-object</refname>
+       <refpurpose>Wraps the allocation of a foreign object around a body of code.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>with-foreign-object</function> <replaceable>(var type) &amp;body body</replaceable> => <returnvalue>form-return</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>var</parameter></term>
+           <listitem>
+             <para>The variable name to bind.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>The type of foreign object to allocate. This parameter is evaluated.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>form-return</returnvalue></term>
+           <listitem>
+             <para>The result of evaluating the <parameter>body</parameter>.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+This function wraps the allocation, binding, and destruction of a foreign object.
+On &cmucl; and
+&lw; platforms the object is stack allocated for efficiency. Benchmarks show that &acl; performs
+much better with static allocation.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(defun gethostname2 ()
+  "Returns the hostname"
+  (uffi:with-foreign-object (name '(:array :unsigned-char 256))
+    (if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256))
+       (uffi:convert-from-foreign-string name)
+       (error "gethostname() failed."))))
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="size-of-foreign-type">
+      <refnamediv>
+       <refname>size-of-foreign-type</refname>
+       <refpurpose>Returns the number of data bytes used by a foreign object type.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>size-of-foreign-type</function> <replaceable>ftype</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ftype</parameter></term>
+           <listitem>
+             <para>A foreign type specifier. This parameter is evaluated.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Returns the number of data bytes used by a foreign object type. This does not include any Lisp storage overhead.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <para>
+<programlisting>
+(size-of-foreign-object :unsigned-byte)
+=> 1
+(size-of-foreign-object 'my-100-byte-vector-type)
+=> 100
+</programlisting>
+        </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="pointer-address">
+      <refnamediv>
+       <refname>pointer-address</refname>
+       <refpurpose>Returns the address of a pointer.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>A pointer to a foreign object.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>address</parameter></term>
+           <listitem>
+             <para>An integer representing the pointer's address.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Returns the address as an integer of a pointer.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="deref-pointer">
+      <refnamediv>
+       <refname>deref-pointer</refname>
+       <refpurpose>Deferences a pointer.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>deref-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>A pointer to a foreign object.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A foreign type of the object being pointed to.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>value</returnvalue></term>
+           <listitem>
+             <para>The value of the object where the pointer points.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Returns the object to which a pointer points.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <para>
+<programlisting>
+(let ((intp (allocate-foreign-object :int)))
+  (setf (deref-pointer intp :int) 10)
+  (prog1
+    (deref-pointer intp :int)
+    (free-foreign-object intp)))
+=> 10
+</programlisting>
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="ensure-char-character">
+      <refnamediv>
+       <refname>ensure-char-character</refname>
+       <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
+a character.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>ensure-char-character</function> <replaceable>object</replaceable> => <returnvalue>char</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>object</parameter></term>
+           <listitem>
+             <para>Either a character or a integer specifying a character code.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>char</returnvalue></term>
+           <listitem>
+             <para>A character.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Ensures that an object obtained by dereferencing a 
+<constant>:char</constant> pointer is a character.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <para>
+<programlisting>
+(let ((fs (convert-to-foreign-string "a")))
+  (prog1 
+    (ensure-char-character (deref-pointer fs :char))
+    (free-foreign-object fs)))
+=> #\a
+</programlisting>
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>Depending upon the implementation and what &uffi; expects, this
+macro may signal an error if the object is not a character or
+integer.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="ensure-char-integer">
+      <refnamediv>
+       <refname>ensure-char-integer</refname>
+       <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
+an integer.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>ensure-char-integer</function> <replaceable>object</replaceable> => <returnvalue>int</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>object</parameter></term>
+           <listitem>
+             <para>Either a character or a integer specifying a character code.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>int</returnvalue></term>
+           <listitem>
+             <para>An integer.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Ensures that an object obtained by dereferencing a 
+<constant>:char</constant> pointer is an integer.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <para>
+<programlisting>
+(let ((fs (convert-to-foreign-string "a")))
+  (prog1 
+    (ensure-char-integer (deref-pointer fs :char))
+    (free-foreign-object fs)))
+=> 96
+</programlisting>
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>Depending upon the implementation and what &uffi; expects, this
+macro may signal an error if the object is not a character or
+integer.</para>
+      </refsect1>
+    </refentry>
+
+    <refentry id="make-null-pointer">
+      <refnamediv>
+       <refname>make-null-pointer</refname>
+       <refpurpose>Create a &null; pointer.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A type of object to which the pointer refers.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>The &null; pointer of type <parameter>type</parameter>.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Creates a &null; pointer of a specified type.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="null-pointer-p">
+      <refnamediv>
+       <refname>null-pointer-p</refname>
+       <refpurpose>Tests a pointer for &null; value.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>A foreign object pointer.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>is-null</returnvalue></term>
+           <listitem>
+             <para>The boolean flag.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         A predicate testing if a pointer is has a &null; value.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="null-cstring-pointer">
+      <refnamediv>
+       <refname>+null-cstring-pointer+</refname>
+       <refpurpose>A constant &null; cstring pointer.
+       </refpurpose>
+       <refclass>Constant</refclass>
+      </refnamediv>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         A &null; cstring pointer. This can be used for testing
+if a cstring returned by a function is &null;.
+       </para>
+      </refsect1>
+    </refentry>
+
+</reference>
+
+    <reference>
+      <title>Strings</title>
+<partintro>
+<title>Overview</title>
+<para>
+
+         &uffi; has functions to two types of
+<varname>C</varname>-compatible
+         strings: <emphasis>cstring</emphasis> and
+<emphasis>foreign</emphasis> strings.
+
+cstrings are used <emphasis>only</emphasis> as parameters to and from
+functions. In some implementations a cstring is not a foreign type but
+rather the Lisp string itself. On other platforms a cstring is a newly
+allocated foreign vector for storing characters. The following is an
+example of using cstrings to both send and return a value.  
+</para>
+
+<programlisting>
+(uffi:def-function ("getenv" c-getenv) 
+    ((name :cstring))
+  :returning :cstring)
+
+(defun my-getenv (key)
+  "Returns an environment variable, or NIL if it does not exist"
+  (check-type key string)
+  (uffi:with-cstring (key-native key)
+    (uffi:convert-from-cstring (c-getenv key-native))))
+</programlisting>
+
+<para> In contrast, foreign strings are always a foreign vector of
+characters which have memory allocated. Thus, if you need to allocate
+memory to hold the return value of a string, you must use a foreign
+string and not a cstring.  The following is an example of using a foreign
+string for a return value.  </para>
+
+<programlisting>
+(uffi:def-function ("gethostname" c-gethostname)
+    ((name (* :unsigned-char))
+     (len :int))
+  :returning :int)
+
+(defun gethostname ()
+  "Returns the hostname"
+  (let* ((name (uffi:allocate-foreign-string 256))
+         (result-code (c-gethostname name 256))
+         (hostname (when (zerop result-code)
+                     (uffi:convert-from-foreign-string name))))
+    (uffi:free-foreign-object name)
+    (unless (zerop result-code)
+      (error "gethostname() failed."))))
+</programlisting>
+
+</partintro>
+
+    <refentry id="convert-from-cstring">
+      <refnamediv>
+       <refname>convert-from-cstring</refname>
+       <refpurpose>Converts a cstring to a Lisp string.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>cstring</parameter></term>
+           <listitem>
+             <para>A cstring.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>string</returnvalue></term>
+           <listitem>
+             <para>A Lisp string.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Converts a Lisp string to a <constant>cstring</constant>. This is
+most often used when processing the results of a foreign function
+that returns a cstring.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="convert-to-cstring">
+      <refnamediv>
+       <refname>convert-to-cstring</refname>
+       <refpurpose>Converts a Lisp string to a cstring.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>string</parameter></term>
+           <listitem>
+             <para>A Lisp string.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>cstring</returnvalue></term>
+           <listitem>
+             <para>A cstring.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Converts a Lisp string to a
+         <varname>cstring</varname>. The
+         <varname>cstring</varname> should be freed with
+         <function>free-cstring</function>.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>On some implementations, this function allocates memory.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="free-cstring">
+      <refnamediv>
+       <refname>free-cstring</refname>
+       <refpurpose>Free memory used by cstring.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>free-cstring</function> <replaceable>cstring</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>cstring</parameter></term>
+           <listitem>
+             <para>A cstring.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Frees any memory possibly allocated by
+         <function>convert-to-cstring</function>. On some implementions, a cstring is just the Lisp string itself.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="with-cstring">
+      <refnamediv>
+       <refname>with-cstring</refname>
+       <refpurpose>Binds a newly created cstring.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>cstring</parameter></term>
+           <listitem>
+             <para>A symbol naming the cstring to be created.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>string</parameter></term>
+           <listitem>
+             <para>A Lisp string that will be translated to a cstring.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>body</parameter></term>
+           <listitem>
+             <para>The body of where the cstring will be bound.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Binds a symbol to a cstring created from conversion of a string. Automatically frees the <varname>cstring</varname>.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <para>
+           <programlisting>
+(def-function ("getenv" c-getenv) 
+   ((name :cstring))
+   :returning :cstring)
+
+(defun getenv (key)
+  "Returns an environment variable, or NIL if it does not exist"
+  (check-type key string)
+  (with-cstring (key-cstring key)
+    (convert-from-cstring (c-getenv key-cstring))))
+           </programlisting>
+         </para>
+       </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="convert-from-foreign-string">
+      <refnamediv>
+       <refname>convert-from-foreign-string</refname>
+       <refpurpose>Converts a foreign string into a Lisp string.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>convert-from-foreign-string</function> <replaceable>foreign-string &amp;key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>foreign-string</parameter></term>
+           <listitem>
+             <para>A foreign string.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>length</parameter></term>
+           <listitem>
+             <para>The length of the foreign string to
+convert. The default is the length of the string until a &null;
+character is reached.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>null-terminated-p</parameter></term>
+           <listitem>
+             <para>A boolean flag with a default value of &t; When true,
+the string is converted until the first &null; character is reached.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>string</returnvalue></term>
+           <listitem>
+             <para>A Lisp string.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Returns a Lisp string from a foreign string. 
+Can translated ASCII and binary strings.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+    <refentry id="convert-to-foreign-string">
+      <refnamediv>
+       <refname>convert-to-foreign-string</refname>
+       <refpurpose>Converts a Lisp string to a foreign string.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>string</parameter></term>
+           <listitem>
+             <para>A Lisp string.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>foreign-string</returnvalue></term>
+           <listitem>
+             <para>A foreign string.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Converts a Lisp string to a foreign string. Memory should be
+         freed with <function>free-foreign-object</function>.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+
+
+    <refentry id="allocate-foreign-string">
+      <refnamediv>
+       <refname>allocate-foreign-string</refname>
+       <refpurpose>Allocates space for a foreign string.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>allocate-foreign-string</function> <replaceable>size &amp;key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>size</parameter></term>
+           <listitem>
+             <para>The size of the space to be allocated in bytes.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>unsigned</parameter></term>
+           <listitem>
+             <para>A boolean flag with a default value of &t;. When true,
+marks the pointer as an <constant>:unsigned-char</constant>.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>foreign-string</returnvalue></term>
+           <listitem>
+             <para>A foreign string which has undefined contents.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+         Allocates space for a foreign string. Memory should
+         be freed with <function>free-foreign-object</function>.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+  </reference>
+
+  <reference>
+      <title>Functions &amp; Libraries</title>
+
+      <refentry id="def-function">
+       <refnamediv>
+         <refname>def-function</refname>
+       <refpurpose>Declares a function. 
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>def-function</function> <replaceable>name args &amp;key module returning</replaceable>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>name</parameter></term>
+           <listitem>
+             <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.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>args</parameter></term>
+           <listitem>
+             <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>module</parameter></term>
+           <listitem>
+             <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>returning</returnvalue></term>
+           <listitem>
+             <para>A declaration specifying the result type of the
+foreign function. If <constant>:void</constant> indicates module does not return any value.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>Declares a foreign function.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(def-function "gethostname" 
+  ((name (* :unsigned-char))
+   (len :int))
+  :returning :int)
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+      <refentry id="load-foreign-library">
+       <refnamediv>
+         <refname>load-foreign-library</refname>
+       <refpurpose>Loads a foreign library. 
+       </refpurpose>
+       <refclass>Function</refclass>
+      </refnamediv>
+      <refsect1>
+       <title>Syntax</title>
+<synopsis>
+         <function>load-foreign-library</function> <replaceable>filename &amp;key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
+</synopsis>
+      </refsect1>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>filename</parameter></term>
+           <listitem>
+             <para>A string or pathname specifying the library location
+in the filesystem. At least one implementation (&lw;) can not
+accept a logical pathname.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>module</parameter></term>
+           <listitem>
+             <para>A string designating the name of the module to apply
+to functions in this library. (Required for Lispworks)
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>supporting-libraries</parameter></term>
+           <listitem>
+             <para>A list of strings naming the libraries required to
+link the foreign library. (Required by CMUCL)
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>success</returnvalue></term>
+           <listitem>
+             <para>A boolean flag, &t; if the library was able to be
+loaded successfully or if the library has been previously loaded,
+otherwise &nil;.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>Loads a foreign library. Applies a module name to functions
+within the library. Ensures that a library is only loaded once during
+a session.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+  (load-foreign-library #p"/usr/lib/libmysqlclient.so" 
+                        :module "mysql" 
+                        :supporting-libraries '("c"))
+    => T
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>Loads the foreign code into the Lisp system.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>Ability to load the file.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+      <refentry id="find-foreign-library">
+       <refnamediv>
+         <refname>find-foreign-library</refname>
+       <refpurpose>Finds a foreign library file.
+       </refpurpose>
+       <refclass>Function</refclass>
+      </refnamediv>
+      <refsect1>
+       <title>Syntax</title>
+<synopsis>
+         <function>find-foreign-library</function> <replaceable>names directories &amp; drive-letters types</replaceable> => <returnvalue>path</returnvalue>
+</synopsis>
+      </refsect1>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>names</parameter></term>
+           <listitem>
+             <para>A string or list of strings containing the base name of the library file.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>directories</parameter></term>
+           <listitem>
+             <para>A string or list of strings containing the directory the library file.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>drive-letters</parameter></term>
+           <listitem>
+             <para>A string or list of strings containing the drive letters for the library file.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>types</parameter></term>
+           <listitem>
+             <para>A string or list of strings containing the file type of the library file. Default
+is &nil;. If &nil;, will use a default type based on the currently running implementation.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>path</returnvalue></term>
+           <listitem>
+             <para>A path containing the path found, or &nil; if the library file was not found.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>Finds a foreign library by searching through a number of possible locations. Returns
+the path of the first found file.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Examples</title>
+       <programlisting>
+(find-foreign-library '("libmysqlclient" "libmysql")
+    '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/")
+    :types '("so" "dll")
+    :drive-letters '("C" "D" "E"))
+=> #P"D:\\mysql\\lib\\opt\\libmysql.dll"
+       </programlisting>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
+</reference>
+
+