From bb3c7f225a5cf8ece5b55a734b2b166724f27d63 Mon Sep 17 00:00:00 2001 From: rtoy <rtoy> Date: Wed, 15 Sep 2010 11:32:49 +0000 Subject: [PATCH] Fix FD-STREAM-FILE-POSITION, which was returning the wrong thing for streams with a string-buffer (all external formats except ISO-8859-1) and for streams without a string-buffer but with an in-buffer (ISO-8859-1). This caused source location information to be totally wrong. --- code/fd-stream.lisp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/code/fd-stream.lisp b/code/fd-stream.lisp index 5f8d174c2..5b29673ea 100644 --- a/code/fd-stream.lisp +++ b/code/fd-stream.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.119 2010/09/08 03:04:54 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.120 2010/09/15 11:32:49 rtoy Rel $") ;;; ;;; ********************************************************************** ;;; @@ -1691,14 +1691,15 @@ (incf posn (- (the index (caddr later)) (the index (cadr later))))) (incf posn (fd-stream-obuf-tail stream)) + ;; Adjust for unread input: ;; If there is any input read from UNIX but not supplied to ;; the user of the stream, the *real* file position will ;; smaller than reported, because we want to look like the ;; unread stuff is still available. - #-unicode (decf posn (- (fd-stream-ibuf-tail stream) (fd-stream-ibuf-head stream))) + #+unicode (if (fd-stream-string-buffer stream) ;; The string buffer contains Lisp characters, @@ -1717,8 +1718,18 @@ (loop for k of-type fixnum from (1- (fd-stream-string-index stream)) below (1- (fd-stream-string-buffer-len stream)) do (decf posn (aref ocount k))))) - (decf posn (- (fd-stream-ibuf-tail stream) - (fd-stream-ibuf-head stream)))) + (when (fd-stream-in-buffer stream) + ;; When we have an in-buffer (but no + ;; string-buffer!), we need to adjust for the + ;; octets that have not yet been supplied. + ;; This situation (should!) only happens for an + ;; external-format of ISO-8859-1. If there's + ;; no string-buffer and no in-buffer, then the + ;; ibuf tail and head pointers contain all the + ;; information needed. + (decf posn (- in-buffer-length + (fd-stream-in-index stream))))) + (when (fd-stream-unread stream) ;;@@ (decf posn)) ;; Divide bytes by element size. -- GitLab