Skip to content

Commit

Permalink
0.8.9.40:
Browse files Browse the repository at this point in the history
	Yay!  Finally, a patch inspired by PFD's ansi-tests
	... make ECHO-STREAMs understand READ-SEQUENCE;
	... add more tests than are in ansi-tests, because the interaction
		with UNREAD-CHAR is potentially tricky.
  • Loading branch information
csrhodes committed Apr 14, 2004
1 parent b93f08e commit f1a812d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,8 @@ changes in sbcl-0.8.10 relative to sbcl-0.8.9:
values. (thanks to Zach Beane)
* bug fix: streams with element-type (SIGNED-BYTE <N>) for <N>
greater than 32 handle EOF correctly.
* fixed some bugs revealed by Paul Dietz' test suite:
** READ-SEQUENCE now works on ECHO-STREAMs.

planned incompatible changes in 0.8.x:
* (not done yet, but planned:) When the profiling interface settles
Expand Down
39 changes: 33 additions & 6 deletions src/code/stream.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@
(in #'echo-in)
(bin #'echo-bin)
(misc #'echo-misc)
(n-bin #'ill-bin))
(n-bin #'echo-n-bin))
(:constructor %make-echo-stream (input-stream output-stream))
(:copier nil))
unread-stuff)
Expand Down Expand Up @@ -921,6 +921,36 @@
(t (,out-fun result out) result)))))))
(in-fun echo-in read-char write-char eof-error-p eof-value)
(in-fun echo-bin read-byte write-byte eof-error-p eof-value))

(defun echo-n-bin (stream buffer start numbytes eof-error-p)
(let ((new-start start)
(read 0))
(loop
(let ((thing (pop (echo-stream-unread-stuff stream))))
(cond
(thing
(setf (aref buffer new-start) thing)
(incf new-start)
(incf read)
(when (= read numbytes)
(return-from echo-n-bin numbytes)))
(t (return nil)))))
(let ((bytes-read (read-n-bytes (echo-stream-input-stream stream) buffer
new-start (- numbytes read) nil)))
(cond
((not eof-error-p)
(write-sequence buffer (echo-stream-output-stream stream)
:start new-start :end (+ new-start bytes-read))
(+ bytes-read read))
((> numbytes (+ read bytes-read))
(write-sequence buffer (echo-stream-output-stream stream)
:start new-start :end (+ new-start bytes-read))
(error 'end-of-file :stream stream))
(t
(write-sequence buffer (echo-stream-output-stream stream)
:start new-start :end (+ new-start bytes-read))
(aver (= numbytes (+ new-start bytes-read)))
numbytes)))))

;;;; base STRING-STREAM stuff

Expand Down Expand Up @@ -1659,11 +1689,8 @@
(simple-array (signed-byte 8) (*))
simple-string)
(let* ((numbytes (- end start))
(bytes-read (sb!sys:read-n-bytes stream
data
offset-start
numbytes
nil)))
(bytes-read (read-n-bytes stream data offset-start
numbytes nil)))
(if (< bytes-read numbytes)
(+ start bytes-read)
end)))
Expand Down
27 changes: 27 additions & 0 deletions tests/stream.pure.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,30 @@

(with-open-file (s "/dev/null" :element-type '(signed-byte 48))
(assert (eq :eof (read-byte s nil :eof))))

(let* ((is (make-string-input-stream "foo"))
(os (make-string-output-stream))
(s (make-echo-stream is os))
(sequence (copy-seq "abcdef")))
(assert (= (read-sequence sequence s) 3))
(assert (string= sequence "foodef"))
(assert (string= (get-output-stream-string os) "foo")))

(let* ((is (make-string-input-stream "foo"))
(os (make-string-output-stream))
(s (make-echo-stream is os))
(sequence (copy-seq "abcdef")))
(assert (char= #\f (read-char s)))
(assert (= (read-sequence sequence s) 2))
(assert (string= sequence "oocdef"))
(assert (string= (get-output-stream-string os) "foo")))

(let* ((is (make-string-input-stream "foo"))
(os (make-string-output-stream))
(s (make-echo-stream is os))
(sequence (copy-seq "abcdef")))
(assert (char= #\f (read-char s)))
(unread-char #\f s)
(assert (= (read-sequence sequence s) 3))
(assert (string= sequence "foodef"))
(assert (string= (get-output-stream-string os) "foo")))
2 changes: 1 addition & 1 deletion version.lisp-expr
Original file line number Diff line number Diff line change
Expand Up @@ -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".)
"0.8.9.39"
"0.8.9.40"

0 comments on commit f1a812d

Please sign in to comment.