From 40902249f2739db0830d663704b4931e37ee0d52 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 9 Nov 2004 02:14:43 +0000 Subject: [PATCH] r10140: add sb-unicode patch --- src/strings.lisp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/strings.lisp b/src/strings.lisp index c63d943..b8965b1 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -299,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 @@ -322,6 +322,27 @@ 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-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))) -- 2.34.1