0.9.14.4:
authorJuho Snellman <jsnell@iki.fi>
Wed, 28 Jun 2006 11:35:51 +0000 (11:35 +0000)
committerJuho Snellman <jsnell@iki.fi>
Wed, 28 Jun 2006 11:35:51 +0000 (11:35 +0000)
FILE-POSITION sometimes returned inconsistent results for multibyte
        external-format streams. (Reported by Lutz Euler on sbcl-devel,
        patch from sbcl-devel "Patch: FILE-POSITION bug" by "vbzoli")

NEWS
src/code/fd-stream.lisp
src/code/stream.lisp
tests/external-format.impure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 3f992c6..d6f5be5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ changes in sbcl-0.9.15 relative to sbcl-0.9.14:
     (cons symbol) is, in the default pprint-dispatch-table, now
     sensitive to whether the symbol satisfies FBOUNDP.  (thanks to
     Marcus Pearce)
+  * fixed bug: FILE-POSITION sometimes returned inconsistent results
+    for multibyte external-format streams (thanks to "vbzoli")
 
 changes in sbcl-0.9.14 relative to sbcl-0.9.13:
   * feature: thread support on Solaris/x86, and experimental thread support
index 5de405b..faab631 100644 (file)
     (when sizer
       (loop for char across string summing (funcall sizer char)))))
 
+(defun find-external-format (external-format)
+  (when external-format
+    (find external-format *external-formats* :test #'member :key #'car)))
+
+(defun variable-width-external-format-p (ef-entry)
+  (when (eighth ef-entry) t))
+
+(defun bytes-for-char-fun (ef-entry)
+  (if ef-entry (symbol-function (ninth ef-entry)) (constantly 1)))
+
 ;;; FIXME: OAOOM here vrt. *EXTERNAL-FORMAT-FUNCTIONS* in fd-stream.lisp
 (defmacro define-external-format (external-format size output-restart
                                   out-expr in-expr)
index 1e6dcdc..5d339b7 100644 (file)
     (t
      (let ((res (funcall (ansi-stream-misc stream) stream :file-position nil)))
        (when res
+         #!-sb-unicode
          (- res
             (- +ansi-stream-in-buffer-length+
-               (ansi-stream-in-index stream))))))))
+               (ansi-stream-in-index stream)))
+         #!+sb-unicode
+         (let* ((external-format (stream-external-format stream))
+                (ef-entry (find-external-format external-format))
+                (variable-width-p (variable-width-external-format-p ef-entry))
+                (char-len (bytes-for-char-fun ef-entry)))
+           (- res
+              (if variable-width-p
+                  (loop with buffer = (ansi-stream-cin-buffer stream)
+                        with start = (ansi-stream-in-index stream)
+                        for i from start below +ansi-stream-in-buffer-length+
+                        sum (funcall char-len (aref buffer i)))
+                  (* (funcall char-len #\x)  ; arbitrary argument
+                     (- +ansi-stream-in-buffer-length+
+                        (ansi-stream-in-index stream)))))))))))
 
 
 (defun file-position (stream &optional position)
index cff240a..7724c96 100644 (file)
 
 ;;; See sbcl-devel "Subject: Bug in FILE-POSITION on UTF-8-encoded files"
 ;;; by Lutz Euler on 2006-03-05 for more details.
-(with-test (:name (:file-position :utf-8)
-                  :fails-on :sbcl)
+(with-test (:name (:file-position :utf-8))
   (let ((path "external-format-test.txt"))
     (with-open-file (s path
                        :direction :output
index 2cfc0f5..0724bf6 100644 (file)
@@ -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.9.14.3"
+"0.9.14.4"