From: Kevin M. Rosenberg Date: Sat, 23 Nov 2002 18:03:30 +0000 (+0000) Subject: r3460: new deb pkg X-Git-Tag: v1.6.1~255 X-Git-Url: http://git.kpe.io/?a=commitdiff_plain;h=0ddd686eaa4dc3e28cf3e9472c9d46360b0091cf;hp=e88c7547a91c7ea966e1606963736f136e36ac7f;p=uffi.git r3460: new deb pkg --- diff --git a/debian/changelog b/debian/changelog index 4cbbf51..79e9f4d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +cl-uffi (1.1.7-1) unstable; urgency=low + + * bug fixes on allegro + + -- Kevin M. Rosenberg 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 Thu, 21 Nov 2002 19:51:55 -0700 + cl-uffi (1.1.5-1) unstable; urgency=low * Documentation changes diff --git a/doc/html.tar.gz b/doc/html.tar.gz index e5331db..31797e6 100644 Binary files a/doc/html.tar.gz and b/doc/html.tar.gz differ diff --git a/doc/ref.sgml b/doc/ref.sgml index 39ae02e..f299c19 100644 --- a/doc/ref.sgml +++ b/doc/ref.sgml @@ -1498,21 +1498,51 @@ if a cstring returned by a function is &null;. &uffi; has functions to two types of C-compatible - strings, cstring and foreign 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 -allocate a cstring. + strings: cstring and +foreign strings. + +cstrings are used only 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. - -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. - + + +(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)))) + + + 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. + + +(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.")))) + + @@ -1655,7 +1685,7 @@ that returns a cstring. Description Frees any memory possibly allocated by - convert-to-cstring. + convert-to-cstring. On some implementions, a cstring is just the Lisp string itself. diff --git a/doc/uffi.pdf b/doc/uffi.pdf index f591354..7caca46 100644 Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ