X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/90e8bbf63d6ab5647f284af1cbab30ae37c5ae1c..62be149ffae95206b138401d7cea23cdba055a68:/gffi/basic-types.lisp diff --git a/gffi/basic-types.lisp b/gffi/basic-types.lisp index d1da957..9b3695e 100644 --- a/gffi/basic-types.lisp +++ b/gffi/basic-types.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: basic-types.lisp,v 1.2 2006-06-08 13:24:25 espen Exp $ +;; $Id: basic-types.lisp,v 1.5 2007-01-02 15:20:32 espen Exp $ (in-package "GFFI") @@ -514,6 +514,12 @@ have been written as temporal.") #+(or cmu sbcl)(sap-ref-double location offset) #+clisp(ffi:memory-as location 'double-float offset))) +(deftype optimized-double-float () 'double-float) + +(define-type-method to-alien-form ((type optimized-double-float) form &optional copy-p) + (declare (ignore type copy-p)) + form) + ;;; Character @@ -570,6 +576,7 @@ have been written as temporal.") ;;; String (defun utf8-length (string) + "Returns the length including the trailing zero, of STRING encoded as UTF8" (1+ (loop for char across string as char-code = (char-code char) @@ -580,7 +587,8 @@ have been written as temporal.") ((< char-code #x1FFFFF) 4))))) (defun encode-utf8-string (string &optional location) - (let ((location (or location (allocate-memory (utf8-length string))))) + (let* ((len (utf8-length string)) + (location (or location (allocate-memory len)))) (loop for char across string for i from 0 @@ -599,8 +607,8 @@ have been written as temporal.") ((< char-code #x80) (setf (ref-byte location i) char-code)) ((< char-code #x800) (encode 11)) ((< char-code #x10000) (encode 16)) - ((< char-code #x200000) (encode 21)))) - finally (setf (ref-byte location (1+ i)) 0)) + ((< char-code #x200000) (encode 21))))) + (setf (ref-byte location (1- len)) 0) location)) (defun decode-utf8-string (c-string)