From: ······@gmail.com
Subject: (SBCL) convert a C string to Lisp using a specific encoding (sbcl-naturalize-cstring)
Date: 
Message-ID: <1145962830.189603.156430@t31g2000cwb.googlegroups.com>
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?

From: kavenchuk
Subject: Re: (SBCL) convert a C string to Lisp using a specific encoding (sbcl-naturalize-cstring)
Date: 
Message-ID: <1146046681.557072.249010@j33g2000cwa.googlegroups.com>
see
http://sourceforge.net/mailarchive/forum.php?thread_id=10175602&forum_id=4134
From: ······@gmail.com
Subject: Re: (SBCL) convert a C string to Lisp using a specific encoding (sbcl-naturalize-cstring)
Date: 
Message-ID: <1146051278.465836.279720@j33g2000cwa.googlegroups.com>
Thank you, this look like exactly what I was looking for, except that
I'm not sure - do I need to patch the above UFFI's function also? If
so, how?
From: kavenchuk
Subject: Re: (SBCL) convert a C string to Lisp using a specific encoding (sbcl-naturalize-cstring)
Date: 
Message-ID: <1146119671.153190.225630@v46g2000cwv.googlegroups.com>
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