r1592: Updated to 0.2.10
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 19 Mar 2002 16:42:59 +0000 (16:42 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 19 Mar 2002 16:42:59 +0000 (16:42 +0000)
ChangeLog
Makefile
TODO
doc/intro.sgml
examples/gethostname.cl
src/objects.cl
src/strings.cl
tests/gethostname.cl

index b3925d412ce304021a5fc9f091542b7d5d06340c..4ff03b976fd4755b780c740cacb43ea6db1e3bc4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
 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
index 53235f12c65dd44a44f6df5b9a15a670f84873ed..f43cf4d8982f816798e1952caa66e7c589ade942 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
 #  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
 #
@@ -31,7 +31,7 @@ realclean: clean
 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
diff --git a/TODO b/TODO
index 258b00705b6d91c7f27ad3cd19e804ed8d092cfe..f8940da160153e7ddf76ab371ad0f272739e92ea 100644 (file)
--- a/TODO
+++ b/TODO
@@ -13,6 +13,7 @@ expansions. CMUCL strtol is broken because of signedness.  Right now,
 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.
index df58ab6683625a9f0144e945f97ab212b7cbd7f5..6f8b9b6f7e02744127624e191c9d62fc9e5b8183 100644 (file)
@@ -48,15 +48,52 @@ particular C-library.
   </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>
index dc318225ecf76090cd885b2b310b1a7fb208b596..e90e7dadfae9d2ea52e5b66867c735b8592f5119 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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
 ;;;;
@@ -22,7 +22,7 @@
 ;;; 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)
 
index f9651d468c53603e763012d736c524360e5838ad..fdecab26d91c9909582a8bfdaffa8f84389be4f9 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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
 ;;;;
@@ -66,11 +66,32 @@ an array of TYPE with size SIZE."
 
 (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))
index a32edde37bac370c3915c467bcca5751c9107398..5a4b5671b291f92c271bb7c345a99e9d071ac6b2 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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
 ;;;;
@@ -107,20 +107,19 @@ that CMU automatically converts strings from c-calls."
        (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)))
index dc318225ecf76090cd885b2b310b1a7fb208b596..e90e7dadfae9d2ea52e5b66867c735b8592f5119 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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
 ;;;;
@@ -22,7 +22,7 @@
 ;;; 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)