From c7c7bab2b37d8b9fbda8f955f09540db17573afa Mon Sep 17 00:00:00 2001 From: Juho Snellman Date: Mon, 8 Jan 2007 02:36:23 +0000 Subject: [PATCH] 1.0.1.11: 1.0.1.6 caused an error to be signaled for READ/WRITE-SEQUENCE on unsigned-byte vectors and bivalent streams, which broke ASDF-INSTALL. (Reported by Josip Gracin) --- src/code/stream.lisp | 4 +-- tests/stream.impure.lisp | 64 +++++++++++++++++++++++++++++++++++++++++++++- version.lisp-expr | 2 +- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/code/stream.lisp b/src/code/stream.lisp index db0b3e7..609df65 100644 --- a/src/code/stream.lisp +++ b/src/code/stream.lisp @@ -1820,7 +1820,7 @@ (+ start bytes-read) end)) (let ((read-function - (if (subtypep (stream-element-type stream) 'character) + (if (subtypep (array-element-type data) 'character) #'ansi-stream-read-char #'ansi-stream-read-byte))) (do ((i offset-start (1+ i))) @@ -1873,7 +1873,7 @@ (labels ((output-seq-in-loop () (let ((write-function - (if (subtypep (stream-element-type stream) 'character) + (if (subtypep (array-element-type data) 'character) (ansi-stream-out stream) (ansi-stream-bout stream)))) (do ((i offset-start (1+ i))) diff --git a/tests/stream.impure.lisp b/tests/stream.impure.lisp index 78e331b..e7036b2 100644 --- a/tests/stream.impure.lisp +++ b/tests/stream.impure.lisp @@ -225,6 +225,24 @@ (read-sequence sequence stream) (assert (equalp sequence #(-1))))) + ;; A bivalent stream can be read to a unsigned-byte vector or a + ;; string + + (let ((sequence (make-array 1 :element-type '(unsigned-byte 8)))) + (with-open-file (stream pathname + :direction :input + :element-type :default) + (read-sequence sequence stream) + (assert (equalp sequence #(255))))) + + (let ((sequence (make-array 1 :element-type 'character))) + (with-open-file (stream pathname + :direction :input + :external-format :latin-1 + :element-type :default) + (read-sequence sequence stream) + (assert (equalp sequence #(#.(code-char 255)))))) + ;; Check that a TYPE-ERROR is signalled for incompatible (sequence, ;; stream) pairs. @@ -250,7 +268,22 @@ (type-error (condition) (assert (= (type-error-datum condition) -1)) (assert (subtypep (type-error-expected-type condition) - '(unsigned-byte 8)))))))) + '(unsigned-byte 8))))))) + + ;; Can't read a signed-byte from a bivalent stream + + (let ((sequence (make-array 1 :element-type '(signed-byte 8)))) + (with-open-file (stream pathname + :direction :input + :element-type :default) + (handler-case (progn + (read-sequence sequence stream) + (error "READ-SEQUENCE didn't signal an error")) + (type-error (condition) + (assert (= (type-error-datum condition) 255)) + (assert (subtypep (type-error-expected-type condition) + '(signed-byte 8)))))))) + ;;; Check WRITE-SEQUENCE signals a TYPE-ERROR when the stream can't ;;; write a sequence element. @@ -263,6 +296,8 @@ (let ((pathname "write-sequence.data") (generic-sequence (make-array 1 :initial-contents '(255))) + (string (make-array 1 :element-type 'character + :initial-element (code-char 255))) (unsigned-sequence (make-array 1 :element-type '(unsigned-byte 8) :initial-contents '(255))) @@ -289,6 +324,21 @@ :element-type '(signed-byte 8)) (write-sequence signed-sequence stream)) + ;; Bivalent streams on unsigned-byte and strings + + (with-open-file (stream pathname + :direction :output + :if-exists :supersede + :element-type :default) + (write-sequence unsigned-sequence stream)) + + (with-open-file (stream pathname + :direction :output + :external-format :latin-1 + :if-exists :supersede + :element-type :default) + (write-sequence string stream)) + ;; Check a TYPE-ERROR is signalled for unsigned and signed vectors ;; which are incompatible with the stream element type. (with-open-file (stream pathname @@ -313,6 +363,18 @@ (type-error (condition) (assert (= (type-error-datum condition) -1)) (assert (subtypep (type-error-expected-type condition) + '(unsigned-byte 8)))))) + + (with-open-file (stream pathname + :direction :output + :if-exists :supersede + :element-type :default) + (handler-case (progn + (write-sequence signed-sequence stream) + (error "WRITE-SEQUENCE didn't signal an error")) + (type-error (condition) + (assert (= (type-error-datum condition) -1)) + (assert (subtypep (type-error-expected-type condition) '(unsigned-byte 8))))))) ;;; success diff --git a/version.lisp-expr b/version.lisp-expr index b1b8a0b..19f21c9 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.1.10" +"1.0.1.11" -- 1.7.10.4