r3460: new deb pkg
authorKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 23 Nov 2002 18:03:30 +0000 (18:03 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 23 Nov 2002 18:03:30 +0000 (18:03 +0000)
debian/changelog
doc/html.tar.gz
doc/ref.sgml
doc/uffi.pdf

index 4cbbf51728eaefd091f159d4b412417d98036923..79e9f4d6bab257696a05795fa01605ea575f239a 100644 (file)
@@ -1,3 +1,15 @@
+cl-uffi (1.1.7-1) unstable; urgency=low
+
+  * bug fixes on allegro
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Sat, 23 Nov 2002 11:03:18 -0700
+
+cl-uffi (1.1.6-1) unstable; urgency=low
+
+  * More documention of cstrings and foreign strings
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Thu, 21 Nov 2002 19:51:55 -0700
+
 cl-uffi (1.1.5-1) unstable; urgency=low
 
   * Documentation changes
index e5331dbf2278fbc0366e686b3bc367d60a48c39f..31797e6658310eb228a8c9753b70c643bb5fe771 100644 (file)
Binary files a/doc/html.tar.gz and b/doc/html.tar.gz differ
index 39ae02ebaf9a920fceb1b76cef1a1671bd0f70fb..f299c197cee87f90e5045c6c1ddca6b4d89198c1 100644 (file)
@@ -1498,21 +1498,51 @@ if a cstring returned by a function is &null;.
 
          &uffi; has functions to two types of
 <varname>C</varname>-compatible
-         strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
-
-cstrings are used as parameters to and from functions. An
-implementation, such as CMUCL and Lispworks, a cstring may not be a
-foreign type but rather the Lisp string itself while on other
-platforms a cstring is a newly allocated foreign vector for storing
-characters. Thus, it is not possible to portably
-<emphasis>allocate</emphasis> a cstring. 
+         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>
-<para>
-In contrast, foreign strings
-are always a foreign vector of characters which have a memory
-allocated to hold them. Because of this, if you need to allocate memory to
-hold the return value of a string, use a foreign string and not a cstring.
-       </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">
@@ -1655,7 +1685,7 @@ that returns a cstring.
        <title>Description</title>
        <para>
          Frees any memory possibly allocated by
-         <function>convert-to-cstring</function>.
+         <function>convert-to-cstring</function>. On some implementions, a cstring is just the Lisp string itself.
        </para>
       </refsect1>
       <refsect1>
index f59135461c9228004b490373402ba91c24f9a412..7caca46df988c17bfc51f5be873efadef3fcb2c9 100644 (file)
Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ