X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=uffi%2Fclsql-uffi.lisp;h=7bc3a94c55678c8d2a7af65f579f493c429bd1f9;hb=f0b691b8b5c1222c339dbef3b27dd457da615a65;hp=f50682fa799b308300a9e4bb02c81cea8d9618a6;hpb=26f5250313d43508e4d22eb7f4f745cd50ffb17b;p=clsql.git diff --git a/uffi/clsql-uffi.lisp b/uffi/clsql-uffi.lisp index f50682f..7bc3a94 100644 --- a/uffi/clsql-uffi.lisp +++ b/uffi/clsql-uffi.lisp @@ -7,7 +7,7 @@ ;;;; Programmers: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: clsql-uffi.lisp,v 1.2 2002/12/13 12:21:54 kevin Exp $ +;;;; $Id: clsql-uffi.lisp,v 1.23 2003/05/17 07:50:55 kevin Exp $ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -83,10 +83,16 @@ (defmacro split-64-bit-integer (int64) `(values (ash ,int64 -32) (logand ,int64 +2^32-1+))) +(defvar +ascii-N-value+ (char-code #\N)) +(defvar +ascii-U-value+ (char-code #\U)) + +(uffi:def-type char-ptr-def (* :unsigned-char)) + (defun char-ptr-points-to-null (char-ptr) "Returns T if foreign character pointer refers to 'NULL' string. Only called for numeric entries" ;; Uses short cut and returns T if first character is #\N. It should ;; never be non-numeric + (declare (type char-ptr-def char-ptr)) (let ((char (uffi:ensure-char-character (uffi:deref-pointer char-ptr :char)))) (eql char #\N))) @@ -114,5 +120,71 @@ low32 (make-64-bit-integer high32 low32))))) (t + ;; Choose optimized routine + #-(or cmu sbcl lispworks scl) + (native-to-string char-ptr) + #+(or cmu sbcl lispworks scl) (uffi:convert-from-foreign-string char-ptr))))))) + +(uffi:def-function "strlen" + ((str (* :unsigned-char))) + :returning :unsigned-int) + +#-allegro +(defun native-to-string (s) + (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0)) + (type char-ptr-def s)) + (let* ((len (strlen s)) + (str (make-string len))) + (declare (fixnum len) + (simple-string str)) + (do ((i 0)) + ((= i len)) + (declare (fixnum i)) + (setf (schar str i) + (code-char (uffi:deref-array s '(:array :unsigned-char) i))) + (incf i)) + str)) + +#+(and allegro ics) +(defun native-to-string (s) + (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0)) + (type char-ptr-def s)) + (let* ((len (strlen s)) + (str (make-string len))) + (declare (fixnum len) + (simple-string str)) + (do ((i 0)) + ((= i len)) + (declare (fixnum i)) + (setf (schar str i) + (code-char (uffi:deref-array s '(:array :unsigned-char) i))) + (incf i)) + str)) + +#-(and allegro ics) +(defun native-to-string (s) + (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0)) + (type char-ptr-def s)) + (let* ((len (strlen s)) + (len4 (floor len 4)) + (str (make-string len))) + (declare (fixnum len) + (type (simple-array (signed-byte 32) (*)) str)) + (do ((i 0)) + ((= i len4)) + (declare (fixnum i)) + (setf (aref (the (simple-array (signed-byte 32) (*)) str) i) + (uffi:deref-array s '(:array :int) i)) + (incf i)) + (do ((i (* 4 len4))) + ((= i len)) + (declare (fixnum i)) + (setf (aref (the (simple-array (signed-byte 8) (*)) str) i) + (uffi:deref-array s '(:array :unsigned-char) i)) + (incf i)) + str)) + + +