+10 Mar 2002
+ * Made Allegro CL array access more efficient
+ * Renamed c-string to cstring to emphasize it as a basic type
+
9 Mar 2002
- - Changed def-routine name to def-function
- - Fixed bug in def-function for Lispworks
- - Fixed error in +null-c-string-pointer+ name
- - Fixed error in (make-null-pointer) for Lispworks
- - Reworked Lispwork c-strings to be (* :char) rather than
+ * Changed def-routine name to def-function
+ * Fixed bug in def-function for Lispworks
+ * Fixed error in +null-c-string-pointer+ name
+ * Fixed error in (make*null*pointer) for Lispworks
+ * Reworked Lispwork c-strings to be (* :char) rather than
the implementation default of (* (:unsigned :char)) to be
consistent with CMUCL. Bumped version to 0.2.0 because of
change this change.
- - Modified getenv.cl example to avoid name collison with LW
- - Modified compress.cl to setup output buffer as :unsigned-char
- - Added test-all-examples function. All routines tested
+ * Modified getenv.cl example to avoid name collison with LW
+ * Modified compress.cl to setup output buffer as :unsigned*char
+ * Added test*all*examples function. All routines tested
okay with ACL, LW, and CMUCL
8 Mar 2002
- - Added ZIP file output with LF->CRLF translations to distribution
- - Modified def-enum to use uffi:def-constant rather than
+ * Added ZIP file output with LF->CRLF translations to distribution
+ * Modified def*enum to use uffi:def*constant rather than
cl:defconstant
# Programer: Kevin M. Rosenberg, M.D.
# Date Started: Mar 2002
#
-# CVS Id: $Id: Makefile,v 1.7 2002/03/10 05:13:09 kevin Exp $
+# CVS Id: $Id: Makefile,v 1.8 2002/03/10 11:13:07 kevin Exp $
#
# Copyright (c) 2002 by Kevin M. Rosenberg
#
docs:
@(cd doc; make dist-doc)
-VERSION=0.2.0
+VERSION=0.2.1
DISTDIR=uffi-${VERSION}
DIST_TARBALL=${DISTDIR}.tar.gz
DIST_ZIP=${DISTDIR}.zip
SOURCE_FILES=src doc examples Makefile COPYING COPYRIGHT README \
- INSTALL uffi.lsm ChangeLog NEWS
+ INSTALL uffi.lsm ChangeLog NEWS test-all-examples.cl
dist: realclean docs
@rm -fr ${DISTDIR} ${DIST_TARBALL} ${DIST_ZIP}
</para>
</sect2>
<sect2>
- <title>+null-c-string-ptr+</title>
+ <title>+null-cstring-ptr+</title>
<para>
A constant returning a &null; character pointer;
</para>
<sect1>
<title>Strings</title>
<sect2>
- <title>convert-from-c-string</title>
+ <title>convert-from-cstring</title>
<para>
- Converts a Lisp string to a <varname>c-string</varname>.
+ Converts a Lisp string to a <varname>cstring</varname>.
</para>
</sect2>
<sect2>
- <title>convert-to-c-string</title>
+ <title>convert-to-cstring</title>
<para>
Converts a Lisp string to a
- <varname>c-string</varname>. These
- <varname>c-string's</varname> should be freed with
- <function>free-c-string</function>.
+ <varname>cstring</varname>. These
+ <varname>cstring's</varname> should be freed with
+ <function>free-cstring</function>.
</para>
</sect2>
<sect2>
- <title>free-c-string</title>
+ <title>free-cstring</title>
<para>
Frees any memory possibly allocated by
- <function>convert-to-c-string</function>.
+ <function>convert-to-cstring</function>.
</para>
</sect2>
<sect2>
- <title>with-c-string</title>
+ <title>with-cstring</title>
<para>
- Binds a lexical variable to a newly allocated <varname>c-string</varname>. Automatically frees <varname>c-string</varname>.
+ Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
</para>
</sect2>
<sect2>
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: compress.cl,v 1.4 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: compress.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function ("compress" c-compress)
((dest (* :unsigned-char))
(destlen (* :long))
- (source :c-string)
+ (source :cstring)
(source-len :long))
:returning :int
:module "zlib")
(dest (uffi:allocate-foreign-string destsize :unsigned t))
(destlen (uffi:allocate-foreign-object :long)))
(setf (uffi:deref-pointer destlen :long) destsize)
- (uffi:with-c-string (source-native source)
+ (uffi:with-cstring (source-native source)
(let ((result (c-compress dest destlen source-native sourcelen))
(newdestlen (uffi:deref-pointer destlen :long)))
(unwind-protect
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: getenv.cl,v 1.4 2002/03/10 05:13:09 kevin Exp $
+;;;; $Id: getenv.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function ("getenv" c-getenv)
- ((name :c-string))
- :returning :c-string)
+ ((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-c-string (key-native key)
- (let ((value-c-string (c-getenv key-native)))
- (uffi:convert-from-c-string value-c-string))))
+ (uffi:with-cstring (key-native key)
+ (let ((value-cstring (c-getenv key-native)))
+ (uffi:convert-from-cstring value-cstring))))
#+test-uffi
(progn
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: gethostname.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: gethostname.cl,v 1.4 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
;;; This example is inspired by the example on the CL-Cookbook web site
(uffi:def-function ("gethostname" c-gethostname)
- ((name :c-string)
+ ((name :cstring)
(len :int))
:returning :int)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: getshells.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: getshells.cl,v 1.4 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function "getusershell"
nil
- :returning :c-string)
+ :returning :cstring)
(defun getshells ()
"Returns list of valid shells"
(setusershell)
(let (shells)
- (do ((shell (uffi:convert-from-c-string (getusershell))
- (uffi:convert-from-c-string (getusershell))))
+ (do ((shell (uffi:convert-from-cstring (getusershell))
+ (uffi:convert-from-cstring (getusershell))))
((null shell))
(push shell shells))
(endusershell)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: strtol.cl,v 1.5 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: strtol.cl,v 1.6 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-type char-ptr (* :char))
-;; This example does not use :c-string to pass the input string since
+;; This example does not use :cstring to pass the input string since
;; the routine needs to do pointer arithmetic to see how many characters
;; were parsed
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: aggregates.cl,v 1.1 2002/03/09 19:55:33 kevin Exp $
+;;;; $Id: aggregates.cl,v 1.2 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
(defmacro def-array (name-array type)
#+allegro
`(ff:def-foreign-type ,name-array
- (:struct (:my-field (:array ,(convert-from-uffi-type type :array)))))
+ (:array ,(convert-from-uffi-type type :array)))
#+lispworks
`(fli:define-c-typedef ,name-array
(:pointer (:pointer ,(convert-from-uffi-type type :array))))
#+(or lispworks cmu) (declare (ignore type))
#+cmu `(alien:deref ,obj ,i)
#+lispworks `(fli:dereference ,obj :index ,i)
- #+allegro `(ff:fslot-value-typed ,type :c ,obj ':my-field ,i)
+ #+allegro `(ff:fslot-value-typed ,type :c ,obj ,i)
)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: immediates.cl,v 1.2 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: immediates.cl,v 1.3 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
'((* . *) (:void . c-call:void)
(:short . c-call:short)
(:pointer-void . (* t))
- (:c-string . c-call:c-string)
+ (:cstring . c-call:cstring)
(:char . c-call:char) (:unsigned-char . (alien:unsigned 8))
(:int . alien:integer) (:unsigned-int . c-call:unsigned-int)
(:long . c-call:long) (:unsigned-long . c-call:unsigned-long)
'((* . *) (:void . :void)
(:short . :short)
(:pointer-void . (* :void))
- (:c-string . (* :char))
+ (:cstring . (* :char))
(:char . :char) (:unsigned-char . :unsigned-char)
(:int . :int) (:unsigned-int . :unsigned-int)
(:long . :long) (:unsigned-long . :unsigned-long)
'((* . :pointer) (:void . :void)
(:short . :short)
(:pointer-void . (:pointer :void))
- (:c-string . (:pointer :char))
+ (:cstring . (:pointer :char))
(:char . :char) (:unsigned-char . (:unsigned :char))
(:int . :int) (:unsigned-int . (:unsigned :int))
(:long . :long) (:unsigned-long . (:unsigned :long))
(cond
#+allegro
((and (or (eq context :routine) (eq context :return))
- (eq type :c-string))
+ (eq type :cstring))
(setq type '((* :char) integer)))
#+cmu
((eq context :type)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: objects.cl,v 1.2 2002/03/10 00:11:47 kevin Exp $
+;;;; $Id: objects.cl,v 1.3 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
#+cmu `(alien:null-alien ,obj)
)
-(def-constant +null-c-string-pointer+
- #+cmu nil
- #+allegro 0
- #+lispworks (fli:make-pointer :address 0 :type '(:unsigned :char)))
(defmacro make-null-pointer (type)
#+(or allegro cmu) (declare (ignore type))
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: strings.cl,v 1.3 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: strings.cl,v 1.4 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
(in-package :uffi)
-(defmacro convert-from-c-string (obj)
+(def-constant +null-cstring-pointer+
+ #+cmu nil
+ #+allegro 0
+ #+lispworks (fli:make-pointer :address 0 :type :char))
+
+(defmacro convert-from-cstring (obj)
"Converts a string from a c-call. Same as convert-from-foreign-string, except
that CMU automatically converts strings from c-calls."
#+cmu obj
(values (excl:native-to-string ,stored)))))
)
-(defmacro convert-to-c-string (obj)
+(defmacro convert-to-cstring (obj)
#+lispworks
`(if (null ,obj)
- +null-c-string-pointer+
+ +null-cstring-pointer+
(fli:make-pointer
:address (fli:pointer-address (fli:convert-to-foreign-string ,obj))
:type :char))
(declare (ignore obj))
)
-(defmacro free-c-string (obj)
+(defmacro free-cstring (obj)
#+lispworks
`(unless (fli:null-pointer-p ,obj)
(fli:free-foreign-object ,obj))
:null-terminated-p ,null-terminated-p
:external-format '(:latin-1 :eol-style :lf)))
#+cmu
- `(cmucl-naturalize-c-string (alien:alien-sap ,obj)
+ `(cmucl-naturalize-cstring (alien:alien-sap ,obj)
:length ,length
:null-terminated-p ,null-terminated-p)
)
(defmacro convert-to-foreign-string (obj)
#+lispworks
`(if (null ,obj)
- +null-c-string-pointer+
+ +null-cstring-pointer+
(fli:make-pointer
:address (fli:pointer-address (fli:convert-to-foreign-string ,obj))
:type :char))
`(ff:allocate-fobject :char :c ,size)
)
-(defmacro with-c-string ((foreign-string lisp-string) &body body)
+(defmacro with-cstring ((foreign-string lisp-string) &body body)
#+cmu
`(let ((,foreign-string ,lisp-string)) ,@body)
#+allegro
,@body)))
#+lispworks
(let ((result (gensym)))
- `(let* ((,foreign-string (convert-to-c-string ,lisp-string))
+ `(let* ((,foreign-string (convert-to-cstring ,lisp-string))
(,result ,@body))
(fli:free-foreign-object ,foreign-string)
,result))
;; Modified from CMUCL's source to handle non-null terminated strings
#+cmu
-(defun cmucl-naturalize-c-string (sap &key
+(defun cmucl-naturalize-cstring (sap &key
length
(null-terminated-p t))
(declare (type system:system-area-pointer sap))
--- /dev/null
+(mk:load-system :uffi)
+
+(pushnew :test-uffi cl:*features*)
+
+(flet ((load-test (name)
+ (load (merge-pathnames
+ (make-pathname :name name
+ :type "cl"
+ :directory '(:relative "examples"))
+ *load-truename*))))
+
+ (load-test "strtol")
+ (load-test "gettime")
+ (load-test "getenv")
+ (load-test "gethostname")
+ (load-test "getshells")
+ (load-test "compress"))
+
+(setq cl:*features* (remove :test-uffi cl:*features*))
+
+
+
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: compress.cl,v 1.4 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: compress.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function ("compress" c-compress)
((dest (* :unsigned-char))
(destlen (* :long))
- (source :c-string)
+ (source :cstring)
(source-len :long))
:returning :int
:module "zlib")
(dest (uffi:allocate-foreign-string destsize :unsigned t))
(destlen (uffi:allocate-foreign-object :long)))
(setf (uffi:deref-pointer destlen :long) destsize)
- (uffi:with-c-string (source-native source)
+ (uffi:with-cstring (source-native source)
(let ((result (c-compress dest destlen source-native sourcelen))
(newdestlen (uffi:deref-pointer destlen :long)))
(unwind-protect
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: getenv.cl,v 1.4 2002/03/10 05:13:09 kevin Exp $
+;;;; $Id: getenv.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function ("getenv" c-getenv)
- ((name :c-string))
- :returning :c-string)
+ ((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-c-string (key-native key)
- (let ((value-c-string (c-getenv key-native)))
- (uffi:convert-from-c-string value-c-string))))
+ (uffi:with-cstring (key-native key)
+ (let ((value-cstring (c-getenv key-native)))
+ (uffi:convert-from-cstring value-cstring))))
#+test-uffi
(progn
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: gethostname.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: gethostname.cl,v 1.4 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
;;; This example is inspired by the example on the CL-Cookbook web site
(uffi:def-function ("gethostname" c-gethostname)
- ((name :c-string)
+ ((name :cstring)
(len :int))
:returning :int)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: getshells.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: getshells.cl,v 1.4 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-function "getusershell"
nil
- :returning :c-string)
+ :returning :cstring)
(defun getshells ()
"Returns list of valid shells"
(setusershell)
(let (shells)
- (do ((shell (uffi:convert-from-c-string (getusershell))
- (uffi:convert-from-c-string (getusershell))))
+ (do ((shell (uffi:convert-from-cstring (getusershell))
+ (uffi:convert-from-cstring (getusershell))))
((null shell))
(push shell shells))
(endusershell)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: strtol.cl,v 1.5 2002/03/10 05:09:00 kevin Exp $
+;;;; $Id: strtol.cl,v 1.6 2002/03/10 11:13:07 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(uffi:def-type char-ptr (* :char))
-;; This example does not use :c-string to pass the input string since
+;; This example does not use :cstring to pass the input string since
;; the routine needs to do pointer arithmetic to see how many characters
;; were parsed