Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#31 stream-write-char SBCL unicode problem on dynamic pages

open
nobody
None
5
2012-09-14
2005-12-08
Anonymous
No

I think the function "stream-write-char" in
lw-buffering cannot possibly work under unicode,
where more than one byte may be needed. The
following patch apparently makes it work for me.
I am using a Unicode-enabled SBCL version 0.9.5.

Index: acl-compat/lw-buffering.lisp

RCS file:
/cvsroot/portableaserve/portableaserve/acl-compat/lw-buffering.lisp,v
retrieving revision 1.14
diff -r1.14 lw-buffering.lisp
229a230,232

;; This works; obviously it is sbcl specific.
;; This needs to be reported as a bug; perhaps the
latest portable allegroserve
;; fixes this problem.
231c234,240
< (stream-write-byte stream (char-code character)))


(let ((octets (sb-ext::string-to-octets
(concatenate 'string (list character)))))
(do ((i 0 (+ i 1))
)
((= i (length octets)) nil)
(stream-write-byte stream (aref octets i)))))
;; (stream-write-byte stream (char-code character))

This diff shows how to exercise the problem. You can
stream utf-8 files fine, but if you produce one from a
function, as in (html "this is a dynamic page", you trip
over the problem above:
Index: aserve/example.cl
===================================================================
RCS file:
/cvsroot/portableaserve/portableaserve/aserve/example.cl,v
retrieving revision 1.12
diff -r1.12 example.cl
240c246
< :content-type "text/plain"


:content-type "text/plain; charset=utf-8"
244c250
< (html "This is a dynamic page")))))


         (html "This is a $-1 ýdynamic page")))))

(Put a unicode character into the string you are trying
to send!)

Obviously, my solution is SBCL specific; I'm not really
proposing this code as a solution, just trying to
inform y'all about the problem and demonstrate how to
solve it; I'm not an expert at writing portable lisp code.

Robert L. Read --- read &T robertlread.net

Discussion