Commit b903e98f authored by rtoy's avatar rtoy
Browse files

Fix a couple of issues with changing the stream external format in

midstream.

o When changing the external format, the new converted characters need
  to go into the string-buffer at the point after the last character
  was read.  This maintains consistency if the format is changed
  again before we have to read in another buffer of octets.
o Handle the case where an external format that uses the string-buffer
  is changed to ISO8859-1, which doesn't.  In this case, the converted
  characters need to be copied to the in-buffer in the right place and
  the string-buffer needs to be set to NIL to indicate that the
  string-buffer is not used anymore.
o Add a note that we don't handle the case of changing ISO8859-1 to
  another external-format that uses a string-buffer.
parent aa238b62
Loading
Loading
Loading
Loading
+30 −11
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
;;; domain.
;;; 
(ext:file-comment
 "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream-extfmt.lisp,v 1.10 2010/07/20 21:34:29 rtoy Exp $")
 "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream-extfmt.lisp,v 1.10.2.1 2010/09/06 15:41:30 rtoy Exp $")
;;;
;;; **********************************************************************
;;;
@@ -76,6 +76,11 @@
      (setf (fd-stream-out stream) (ef-cout extfmt)
	    ;;@@ (fd-stream-sout stream) (ef-sout extfmt)
	    ))
    ;; FIXME: We currently don't handle the case of changing from
    ;; ISO8859-1 to something else.  This is because ISO8859-1 doesn't
    ;; use the string-buffer, so when we switch to another external
    ;; format that does, we need to set up the string-buffer
    ;; appropriately.
    (when (and lisp::*enable-stream-buffer-p* updatep
	       (lisp-stream-string-buffer stream))
      ;; We want to reconvert any octets that haven't been converted
@@ -83,7 +88,7 @@
      ;; This is done by converting (the previously converted) octets
      ;; until we've converted the right number of characters.
      (let ((ibuf (lisp-stream-in-buffer stream))
	    (sindex (1- (lisp-stream-string-index stream)))
	    (sindex (lisp-stream-string-index stream))
	    (index 0)
	    (state (fd-stream-saved-oc-state stream)))
	;; Reconvert all the octets we've already converted and read.
@@ -93,29 +98,43 @@
	    (octets-to-string ibuf
			      :start 0
			      :external-format old-format
			      :string (make-string sindex)
			      :string (make-string (1- sindex))
			      :state state
			      :error (fd-stream-octets-to-char-error stream))
	  (declare (ignore s pos))
	  (setf state new-state)
	  (setf index count))
	
	;; We now know the last octet that was used.  Now convert the
	;; rest of the octets using the new format.
	;; rest of the octets using the new format.  The new
	;; characters are placed in the string buffer at the point
	;; just after the last character that we've already read.
	(multiple-value-bind (s pos count new-state)
	    (octets-to-string ibuf
			      :start index
			      :end (fd-stream-in-length stream)
			      :external-format (fd-stream-external-format stream)
			      :string (lisp-stream-string-buffer stream)
			      :s-start 1
			      :s-start sindex
			      :state state
			      :error (fd-stream-octets-to-char-error stream))
	  (declare (ignore s))
	  (setf (lisp-stream-string-index stream) 1)
	  (cond ((eq (fd-stream-external-format stream) :iso8859-1)
		 ;; ISO8859-1 doesn't use the string-buffer, so we
		 ;; need to copy the string to the in-buffer and then
		 ;; set the string-buffer to nil to indicate we're not
		 ;; using the string buffer anymore.
		 (let ((index (- in-buffer-length count)))
		   (dotimes (k count)
		     (setf (aref ibuf (+ k index))
			   (char-code (aref s (+ k sindex)))))
		   (setf (lisp-stream-in-index stream) index)
		   (setf (lisp-stream-string-buffer stream) nil)
		   (setf (lisp-stream-string-buffer-len stream) 0)
		   (setf (lisp-stream-string-index stream) 0)))
		(t
		 (setf (lisp-stream-string-index stream) sindex)
		 (setf (lisp-stream-string-buffer-len stream) pos)
		 (setf (lisp-stream-in-index stream) (+ index count))
	  (setf (fd-stream-oc-state stream) new-state))))
		 (setf (fd-stream-oc-state stream) new-state))))))
    extfmt))