From: Kevin M. Rosenberg Date: Tue, 19 Mar 2002 16:42:59 +0000 (+0000) Subject: r1592: Updated to 0.2.10 X-Git-Tag: v1.6.1~574 X-Git-Url: http://git.kpe.io/?p=uffi.git;a=commitdiff_plain;h=e1ba5e8ff148275ed252b179f43a4b045c1dcaf6 r1592: Updated to 0.2.10 --- diff --git a/ChangeLog b/ChangeLog index b3925d4..4ff03b9 100644 --- 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 diff --git a/Makefile b/Makefile index 53235f1..f43cf4d 100644 --- 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 258b007..f8940da 100644 --- 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. diff --git a/doc/intro.sgml b/doc/intro.sgml index df58ab6..6f8b9b6 100644 --- a/doc/intro.sgml +++ b/doc/intro.sgml @@ -48,15 +48,52 @@ particular C-library. - Design Overview - - &uffi; was designed as a cross-implementation compatible - Foreign Function Interface. 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. - + Design + + Overview + + &uffi; was designed as a cross-implementation + compatible Foreign Function Interface. + 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. + + + + + Priorities + + The design of &uffi; is dictated by the order of these priorities: + + + + + Code using &uffi; must operate correctly on all + supported implementations. + + + + + 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;. + + + + 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 +cstring 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. + + + + diff --git a/examples/gethostname.cl b/examples/gethostname.cl index dc31822..e90e7da 100644 --- a/examples/gethostname.cl +++ b/examples/gethostname.cl @@ -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) diff --git a/src/objects.cl b/src/objects.cl index f9651d4..fdecab2 100644 --- a/src/objects.cl +++ b/src/objects.cl @@ -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)) diff --git a/src/strings.cl b/src/strings.cl index a32edde..5a4b567 100644 --- a/src/strings.cl +++ b/src/strings.cl @@ -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))) diff --git a/tests/gethostname.cl b/tests/gethostname.cl index dc31822..e90e7da 100644 --- a/tests/gethostname.cl +++ b/tests/gethostname.cl @@ -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)