Hi, I'm using CLSQL to read data from a database where strings are not
in utf8 (but rather in iso-8859-8 encoding). I've tracked my problem
down to UFFI's function sbcl-naturalize-cstring, that seems to require
the C string to be in utf-8 encoding:
#+(and sbcl sb-unicode)
(defun sbcl-naturalize-cstring (sap &key length (null-terminated-p t))
(declare (type sb-sys:system-area-pointer sap)
(type (or null fixnum) length))
(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
(funcall *system-copy-fn* sap 0 result +system-copy-offset+
(* length +system-copy-multiplier+))
result)))))
The #+sb-unicode sb-alien:utf8-string part seems to be relevant, but
this is really too low-level for me. Is there a way to teach this
function to accept foreign string in a non-utf8 encoding?
UFFI uses own string->c-string conversion (function
convert-to-foreign-string in strings.lisp).
See example of "correct conversion" in my "test-case" (may be not
optimize):
http://sourceforge.net/mailarchive/forum.php?forum_id=4134&max_rows=25&style=flat&viewmonth=200604&viewday=14
Talk to Kevin Rosenberg