This doesn't look like a problem on the Alexandria side. Stuffing ub8 values into any place that requires characters *always* requires additional information about character encoding (is it latin1? latin2? windows-1250?) and dealing with character encodings is out of scope of Alexandria. I think that Flexi Streams/Babel should be explicitly used in this context.
On 20.08.2022 18:35, Madhu wrote:
- alexandria-1/io.lisp: (read-stream-content-into-string): fix recent
lossage: This addresses problems in commits (13b1575, 6ff6820, 9c97e6f, on 2021-10-24), which changed the element-type of the array used by READ-SEQUENCE to read from the stream from CHARACTER to the STREAM-ELEMENT-TYPE of the stream.
On CCL, ECL etc. this breaks nyxt's source/start.lisp:(listen-socket) which basically does (iolib:with-open-socket (s :address-family :local :connect :passive :local-filename "/tmp/foo") (alexandria:read-stream-content-into-string (iolib:accept-connection s)))
Iolib returns an octet stream for which the STREAM-ELEMENT-TYPE is not CHARACTER. READ-STREAM-CONTENT-INTO-STRING uses WITH-OUTPUT-TO-STRING and that calls MAKE-STRING-OUTPUT-STREAM, the argument :ELEMENT-TYPE ((UNSIGNED-BYTE 8)) which fails because it must be a subtype of character
The present fix is to check if it is not a character stream and force set the element-type to 'character if it is not.
alexandria-1/io.lisp | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/alexandria-1/io.lisp b/alexandria-1/io.lisp index d3be536..8c93dd6 100644 --- a/alexandria-1/io.lisp +++ b/alexandria-1/io.lisp @@ -65,6 +65,8 @@ (defun read-stream-content-into-string (stream &key (buffer-size 4096)) (check-type buffer-size positive-integer) (let ((*print-pretty* nil) (element-type (stream-element-type stream)))
- (unless (subtypep element-type 'character)
(setq element-type 'character)) (with-output-to-string (datum nil :element-type element-type) (let ((buffer (make-array buffer-size :element-type element-type))) (loop