r1742: *** empty log message ***
[uffi.git] / doc / ref.sgml
index 82ee66a5df717e7d9ed15cbbfa5e3d8d607c39f1..607edfced873810076050e650872e0270ec179d5 100644 (file)
@@ -315,7 +315,7 @@ abstracts the difference in implementations where some return a
       <refsect1>
        <title>Examples</title>
        <programlisting>
-(def-array ca :char)
+(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))))
@@ -640,17 +640,17 @@ structure. It's type is <constant>:pointer-self</constant>.
     </refentry>
 
 
-    <refentry id="def-array">
+    <refentry id="def-array-pointer">
       <refnamediv>
-       <refname>def-array</refname>
-       <refpurpose>Defines a foreign array type.
+       <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</function> <replaceable>name type</replaceable>
+         <function>def-array-pointer</function> <replaceable>name type</replaceable>
        </synopsis>
       </refsynopsisdiv>
       <refsect1>
@@ -675,13 +675,13 @@ structure. It's type is <constant>:pointer-self</constant>.
       <refsect1>
        <title>Description</title>
        <para>
-         Defines a foreign array type.
+         Defines a type tat is a pointer to an array of type.
        </para>
       </refsect1>
       <refsect1>
        <title>Examples</title>
        <programlisting>
-(def-array byte-array :unsigned-char)
+(def-array-pointer byte-array-pointer :unsigned-char)
        </programlisting>
       </refsect1>
       <refsect1>
@@ -868,7 +868,7 @@ can be freed.
       <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
-         <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
+         <function>allocate-foreign-object</function> <replaceable>type &amp;optional size</replaceable> => <returnvalue>ptr</returnvalue>
        </synopsis>
       </refsynopsisdiv>
       <refsect1>
@@ -877,7 +877,15 @@ can be freed.
          <varlistentry>
            <term><parameter>type</parameter></term>
            <listitem>
-             <para>A type of foreign object to allocate.
+             <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. If specified, allocates and returns an
+array of <parameter>type</parameter> that is <parameter>size</parameter> members long.
              </para>
            </listitem>
          </varlistentry>
@@ -900,7 +908,7 @@ can be freed.
        <title>Examples</title>
        <programlisting>
 (def-struct ab (a :int) (b :double))
-(allocate-foreign-object ab)
+(allocate-foreign-object 'ab)
 => #&lt;ptr&gt;
        </programlisting>
       </refsect1>
@@ -965,6 +973,79 @@ can be freed.
     </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="pointer-address">
       <refnamediv>
        <refname>pointer-address</refname>
@@ -1093,7 +1174,7 @@ can be freed.
     <refentry id="ensure-char-character">
       <refnamediv>
        <refname>ensure-char-character</refname>
-       <refpurpose>Ensures that a dereferenced :char pointer is
+       <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
 a character.
        </refpurpose>
        <refclass>Macro</refclass>
@@ -1161,7 +1242,7 @@ integer.</para>
     <refentry id="ensure-char-integer">
       <refnamediv>
        <refname>ensure-char-integer</refname>
-       <refpurpose>Ensures that a dereferenced :char pointer is
+       <refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is
 an integer.
        </refpurpose>
        <refclass>Macro</refclass>
@@ -1947,6 +2028,91 @@ a session.
       </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>