See TODO file -- actively maintained. Includes changes that you
might expect in the interface.
+20 Mar 2002
+ * Updated strings.cl so that foreign-strings are always unsigned.
+ Fixes a problem with strtol example.
+ * Added ensure-char-character and ensure-char-integer to handle
+ differences in implementations dereferencing of (* :char).
+ * Added section on design priorities for UFFI
+ * Added section in TODO on splitting implementation-dependent code
19 Mar 2002
* Added size parameter to allocate-foreign-object. Creates an array
# Programer: Kevin M. Rosenberg, M.D.
# Date Started: Mar 2002
#
-# CVS Id: $Id: Makefile,v 1.24 2002/03/18 23:02:13 kevin Exp $
+# CVS Id: $Id: Makefile,v 1.25 2002/03/19 16:42:58 kevin Exp $
#
# This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
#
docs:
@(cd doc; make dist-doc)
-VERSION=0.2.9
+VERSION=0.2.10
DISTDIR=uffi-${VERSION}
DIST_TARBALL=${DISTDIR}.tar.gz
DIST_ZIP=${DISTDIR}.zip
LW prefers unsigned and CMUCL prefers signed string arrays. I lean
to having unsigned be the default type.
-- Need to clean signedness of allocate-foreign-string
-
- Add def-union routine
+
+- Split implementation-dependent code into separate files in preparation
+for MCL and CormanLisp ports.
</sect1>
<sect1>
- <title>Design Overview</title>
- <para>
- &uffi; was designed as a cross-implementation compatible
- <emphasis>Foreign Function Interface</emphasis>. Necessarily,
- only a common subset of functionality can be
- provided. Likewise, not every optimization for that a specific
- implementation provides can be supported. Wherever possible,
- though, implementation-specific optimizations are invoked.
- </para>
+ <title>Design</title>
+ <sect2>
+ <title>Overview</title>
+ <para>
+ &uffi; was designed as a cross-implementation
+ compatible <emphasis>Foreign Function Interface</emphasis>.
+ Necessarily,
+ only a common subset of functionality can be
+ provided. Likewise, not every optimization for that a specific
+ implementation provides can be supported. Wherever possible,
+ though, implementation-specific optimizations are invoked.
+ </para>
+ </sect2>
+
+ <sect2>
+ <title>Priorities</title>
+ <para>
+ The design of &uffi; is dictated by the order of these priorities:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Code using &uffi; must operate correctly on all
+ supported implementations.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Take advantage of implementation-specific optimizations. Ideally,
+ there will not a situation where an implementation-specific
+ &ffi; will be chosen due to lack of optimizations in &uffi;.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Provide a simple interface to developers using
+&uffi;. This priority is quite a bit lower than the above priorities.
+This lower priority is manifest by programmers having to pass types in
+pointer and array dereferencing, needing to use
+<constant>cstring</constant> wrapper functions, and the use of
+ensure-char-character and ensure-char-integer functions. My hope is
+that the developer inconvenience will be outweighed by the generation
+of optimized code that is cross-implementation compatible.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </sect2>
</sect1>
</chapter>
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: gethostname.cl,v 1.5 2002/03/14 21:03:12 kevin Exp $
+;;;; $Id: gethostname.cl,v 1.6 2002/03/19 16:42:59 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
;;; This example is inspired by the example on the CL-Cookbook web site
(uffi:def-function ("gethostname" c-gethostname)
- ((name :cstring)
+ ((name (* :unsigned-char))
(len :int))
:returning :int)
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: objects.cl,v 1.8 2002/03/18 22:47:57 kevin Exp $
+;;;; $Id: objects.cl,v 1.9 2002/03/19 16:42:59 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
(defmacro deref-pointer (ptr type)
"Returns a object pointed"
+ #+(or cmu lispworks) (declare (ignore type))
#+cmu `(alien:deref ,ptr)
#+lispworks `(fli:dereference ,ptr)
#+allegro `(ff:fslot-value-typed ,type :c ,ptr)
)
+#+lispworks ;; with LW, deref is a character
+(defmacro ensure-char-character (obj)
+ "Ensures that the dereference of a :char is a character"
+ )
+
+#+(or allegro cmu)
+(defmacro ensure-char-character (obj)
+ "Ensures that the dereference of a :char is a character"
+ `(code-char ,obj)
+ )
+
+#+lispworks
+(defmacro ensure-char-integer (obj)
+ "Ensures that the dereference of a :char is a character"
+ `(char-code ,obj))
+
+#+(or allegro cmu)
+(defmacro ensure-char-integer (obj)
+ ) ;; (* :char) dereference is already an integer
+
(defmacro pointer-address (obj)
#+cmu
`(system:sap-int (alien:alien-sap ,obj))
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: strings.cl,v 1.7 2002/03/18 22:47:57 kevin Exp $
+;;;; $Id: strings.cl,v 1.8 2002/03/19 16:42:59 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
(i (gensym)))
`(when (stringp ,obj)
(let* ((,size (length ,obj))
- (,storage (alien:make-alien char (1+ ,size))))
- (setq ,storage (alien:cast ,storage (* char)))
- (dotimes (,i ,size)
- (declare (fixnum ,i)
- (optimize (speed 3) (safety 0)))
- (setf (alien:deref ,storage ,i) (char-code (char ,obj ,i))))
- (setf (alien:deref ,storage ,size) 0)
+ (,storage (alien:make-alien (alien:unsigned 8) (1+ ,size))))
+ (setq ,storage (alien:cast ,storage (* (alien:unsigned 8))))
+ (locally
+ (declare (optimize (speed 3) (safety 0)))
+ (dotimes (,i ,size)
+ (declare (fixnum ,i))
+ (setf (alien:deref ,storage ,i) (char-code (char ,obj ,i))))
+ (setf (alien:deref ,storage ,size) 0))
,storage)))
)
-(defmacro allocate-foreign-string (size &key (unsigned
- #+cmu nil
- #+lispworks t))
+(defmacro allocate-foreign-string (size &key (unsigned t))
#+cmu
(let ((array-def (gensym)))
`(let ((,array-def (list 'alien:array 'c-call:char ,size)))
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: gethostname.cl,v 1.5 2002/03/14 21:03:12 kevin Exp $
+;;;; $Id: gethostname.cl,v 1.6 2002/03/19 16:42:59 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
;;; This example is inspired by the example on the CL-Cookbook web site
(uffi:def-function ("gethostname" c-gethostname)
- ((name :cstring)
+ ((name (* :unsigned-char))
(len :int))
:returning :int)