X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=inline;f=src%2Fstrings.lisp;h=d91142747219aee42d7a6abda37e7a64e621e0e5;hb=09ef86d2df68776a773bcf35a32ee45e204f2200;hp=89c41b2ec03a8ca4d240d449a134c33c92c2a2ef;hpb=3e1ab6ebfcf56e76edffaff284aca937e8152408;p=uffi.git diff --git a/src/strings.lisp b/src/strings.lisp index 89c41b2..d911427 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -190,8 +190,9 @@ that LW/CMU automatically converts strings from c-calls." `(if (ccl:%null-ptr-p ,obj) nil #+(and mcl (not openmcl)) (ccl:%get-cstring ,obj 0 ,@(if length (list length) nil)) - #+openmcl (let ((str (ccl:%get-cstring ,obj))) - ,(if length '(subseq str 0 length) 'str))) + #+openmcl ,@(if length + `((ccl:%str-from-ptr ,obj ,length)) + `((ccl:%get-cstring ,obj)))) ) @@ -298,7 +299,7 @@ that LW/CMU automatically converts strings from c-calls." (setf (char result i) (code-char (system:sap-ref-8 sap i)))) result))) -#+sbcl +#+(and sbcl (not sb-unicode)) (defun sbcl-naturalize-cstring (sap &key length (null-terminated-p t)) (declare (type sb-sys:system-area-pointer sap)) (locally @@ -321,6 +322,28 @@ that LW/CMU automatically converts strings from c-calls." (* length sb-vm:n-byte-bits)) result))) +#+(and sbcl sb-unicode) +(defun sbcl-naturalize-cstring (sap &key length (null-terminated-p t)) + (declare (type sb-sys:system-area-pointer sap)) + (locally + (declare (optimize (speed 3) (safety 0))) + (cond + (null-terminated-p + (let ((casted (sb-alien:cast (sb-alien:sap-alien sap (* char)) + #+sb-unicode sb-alien:utf8-string + #-sb-unicode sb-alien:c-string))) + (if length + (copy-seq (subseq casted 0 length)) + (copy-seq casted)))) + (t + (let ((result (make-string length))) + ;; this will not work in sb-unicode + (sb-kernel:copy-from-system-area sap 0 + result (* sb-vm:vector-data-offset + sb-vm:n-word-bits) + (* length sb-vm:n-byte-bits)) + result))))) + (eval-when (:compile-toplevel :load-toplevel :execute) (def-function "strlen" ((str (* :unsigned-char))) @@ -347,4 +370,4 @@ that LW/CMU automatically converts strings from c-calls." (let* ((len (or len (strlen s))) (str (make-string len))) (dotimes (i len str) - (setf (schar str i) (code-char (uffi:deref-array s '(:array :byte) i)))))) + (setf (schar str i) (code-char (uffi:deref-array s '(:array :unsigned-byte) i))))))