r1597: Added with-foreign-string
authorKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 21 Mar 2002 04:05:15 +0000 (04:05 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 21 Mar 2002 04:05:15 +0000 (04:05 +0000)
src/libraries.cl
src/strings.cl
test-examples.cl

index 8943587db1197e6d4d55907529a672a4f9818383..ac04d9365a16a5a57ac9ec296e3fe055f7b0de6c 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: libraries.cl,v 1.4 2002/03/16 22:54:06 kevin Exp $
+;;;; $Id: libraries.cl,v 1.5 2002/03/21 04:05:15 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -22,7 +22,8 @@
 (defvar *loaded-libraries* nil
   "List of foreign libraries loaded. Used to prevent reloading a library")
 
-(defun load-foreign-library (filename &key module supporting-libraries)
+(defun load-foreign-library (filename &key module supporting-libraries
+                                          force-load)
   #+allegro (declare (ignore module supporting-libraries))
   #+lispworks  (declare (ignore supporting-libraries))
   #+cmu (declare (ignore module))
@@ -31,7 +32,8 @@
     (if (pathnamep filename)    ;; ensure filename is a string to check if
        (setq filename (namestring filename)))  ; already loaded
 
-    (if (find filename *loaded-libraries* :test #'string-equal)
+    (if (and (not force-load)
+            (find filename *loaded-libraries* :test #'string-equal))
        t ;; return T, but don't reload library
       (progn
        #+cmu (alien:load-foreign filename 
index 5a4b5671b291f92c271bb7c345a99e9d071ac6b2..0bb574252f32a89a7efa5fac694e33bc5e853a48 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: strings.cl,v 1.8 2002/03/19 16:42:59 kevin Exp $
+;;;; $Id: strings.cl,v 1.9 2002/03/21 04:05:15 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -139,22 +139,32 @@ that CMU automatically converts strings from c-calls."
   `(ff:allocate-fobject :char :c ,size)
   )
 
-(defmacro with-cstring ((foreign-string lisp-string) &body body)
+(defmacro with-foreign-string ((foreign-string lisp-string) &body body)
+  (let ((result (gensym)))
+    `(let* ((,foreign-string (convert-to-foreign-string ,lisp-string))
+           (,result (progn ,@body)))
+      (declare (dynamic-extent ,foreign-string))
+      (free-foreign-object ,foreign-string)
+      ,result)))
+
+(defmacro with-cstring ((cstring lisp-string) &body body)
   #+cmu
-  `(let ((,foreign-string ,lisp-string)) ,@body) 
+  `(let ((,cstring ,lisp-string)) ,@body) 
   #+allegro
   (let ((acl-native (gensym)))
     `(excl:with-native-string (,acl-native ,lisp-string)
-       (let ((,foreign-string (if ,lisp-string ,acl-native 0)))
+       (let ((,cstring (if ,lisp-string ,acl-native 0)))
         ,@body)))
   #+lispworks
   (let ((result (gensym)))
-    `(let* ((,foreign-string (convert-to-cstring ,lisp-string))
-           (,result ,@body))
-       (fli:free-foreign-object ,foreign-string)
+    `(let* ((,cstring (convert-to-cstring ,lisp-string))
+           (,result (progn ,@body)))
+       (fli:free-foreign-object ,cstring)
        ,result))
   )
 
+
+
 ;; Modified from CMUCL's source to handle non-null terminated strings
 #+cmu
 (defun cmucl-naturalize-cstring (sap &key 
index 2a4c100a94c5632b729e6e752c5256a640059314..5ff2f5822e5449a5f8fd08130d50a94311cf6c8a 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: test-examples.cl,v 1.5 2002/03/18 02:27:32 kevin Exp $
+;;;; $Id: test-examples.cl,v 1.6 2002/03/21 04:05:15 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -27,6 +27,7 @@
                               :directory '(:relative "examples"))
                *load-truename*))))
 
+  (load-test "c-test-fns")
   (load-test "array-2d")
   (load-test "strtol")
   (load-test "gettime")