From 504069ea3d15a2c17fb78d7cf58c6d4437447c75 Mon Sep 17 00:00:00 2001 From: rtoy <rtoy> Date: Mon, 6 Dec 2004 17:07:06 +0000 Subject: [PATCH] After doing a READ-VECTOR, FILE-POSITION was returning the wrong value for simple-streams. Add a test for this too. Bug report and fix from Lynn Quam, cmucl-imp, 2004-12-04. --- pcl/simple-streams/impl.lisp | 13 ++++++++----- pcl/simple-streams/rt/simple-streams-test.lisp | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pcl/simple-streams/impl.lisp b/pcl/simple-streams/impl.lisp index 5217c4f64..9a7a7e8ee 100644 --- a/pcl/simple-streams/impl.lisp +++ b/pcl/simple-streams/impl.lisp @@ -5,7 +5,7 @@ ;;; domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/pcl/simple-streams/impl.lisp,v 1.6 2004/07/11 03:49:33 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/pcl/simple-streams/impl.lisp,v 1.7 2004/12/06 17:07:05 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -624,13 +624,16 @@ (index (or start 0) (1+ index)) (end (or end (* (length vector) (vector-elt-width vector)))) (endian-swap (endian-swap-value vector endian-swap)) - (byte (funcall j-read-byte encap nil nil t) - (funcall j-read-byte encap nil nil nil))) - ((or (null byte) (>= index end)) index) - (setf (bref vector (logxor index endian-swap)) byte))))) + (flag t nil)) + ((>= index end) index) + (let ((byte (funcall j-read-byte encap nil nil flag))) + (unless byte (return index)) + (setf (bref vector (logxor index endian-swap)) byte)))))) + ((or lisp-stream fundamental-stream) (unless (typep vector '(or string (simple-array (signed-byte 8) (*)) (simple-array (unsigned-byte 8) (*)))) (error "Wrong vector type for read-vector on stream not of type simple-stream.")) (read-sequence vector stream :start (or start 0) :end end)))) + diff --git a/pcl/simple-streams/rt/simple-streams-test.lisp b/pcl/simple-streams/rt/simple-streams-test.lisp index 81430c134..a1d636e7a 100644 --- a/pcl/simple-streams/rt/simple-streams-test.lisp +++ b/pcl/simple-streams/rt/simple-streams-test.lisp @@ -411,3 +411,20 @@ result) t) + +;;; From Lynn Quam, cmucl-imp, 2004-12-04: After doing a READ-VECTOR, +;;; FILE-POSITION returns the wrong value. + +(deftest file-position-6 + ;; Test the file-position is write. + (with-open-file (st1 "/etc/passwd" :class 'stream:file-simple-stream) + (with-open-file (st2 "/etc/passwd" :element-type '(unsigned-byte 8)) + (let* ((buf1 (make-array 100 :element-type '(unsigned-byte 8))) + (buf2 (make-array 100 :element-type '(unsigned-byte 8))) + (n1 (stream:read-vector buf1 st1)) + (n2 (read-sequence buf2 st2))) + (list n1 (file-position st1) + n2 (file-position st2))))) + (100 100 100 100) + ) + -- GitLab