From cb657edcb17cc3c4a6e1c35b7ce33aaf9db48903 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Thu, 21 Mar 2002 04:05:15 +0000 Subject: [PATCH] r1597: Added with-foreign-string --- src/libraries.cl | 8 +++++--- src/strings.cl | 24 +++++++++++++++++------- test-examples.cl | 3 ++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/libraries.cl b/src/libraries.cl index 8943587..ac04d93 100644 --- a/src/libraries.cl +++ b/src/libraries.cl @@ -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 diff --git a/src/strings.cl b/src/strings.cl index 5a4b567..0bb5742 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.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 diff --git a/test-examples.cl b/test-examples.cl index 2a4c100..5ff2f58 100644 --- a/test-examples.cl +++ b/test-examples.cl @@ -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") -- 2.34.1