From c0052f5544d27980c74d5a17cd55dc2069085602 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Sat, 9 Aug 2014 12:53:57 -0700
Subject: [PATCH] Fix ticket:105 by not flaming out on a closed stream.

 * code/reader.lisp:
   * The READER-ERROR condition tries to be helpful and print out the
     position of where the error occurred using FILE-POSITION. But
     FILE-POSITION flames out when the stream is closed, so check for
     a closed stream before calling FILE-POSITION

 * tests/trac.lisp:
   * Add test from the bug report.

 * general-info/release-20f.txt:
   * Update.
---
 src/code/reader.lisp             |  5 ++++-
 src/general-info/release-20f.txt |  1 +
 tests/trac.lisp                  | 29 +++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/code/reader.lisp b/src/code/reader.lisp
index b06230ce2..996b1f3fe 100644
--- a/src/code/reader.lisp
+++ b/src/code/reader.lisp
@@ -62,8 +62,11 @@
                          (reader-error-format-arguments condition))
                   nil error-stream
                   (file-position error-stream)))
+       (format t "open-stream-p ~A~%" (open-stream-p error-stream))
        (format stream (intl:gettext "Reader error ~@[at ~D ~]on ~S:~%~?")
-	       (file-position error-stream) error-stream
+	       (and (open-stream-p error-stream)
+		    (file-position error-stream))
+	       error-stream
 	       (reader-error-format-control condition)
 	       (reader-error-format-arguments condition))))))
 
diff --git a/src/general-info/release-20f.txt b/src/general-info/release-20f.txt
index b6ce0d516..388ca02f7 100644
--- a/src/general-info/release-20f.txt
+++ b/src/general-info/release-20f.txt
@@ -109,6 +109,7 @@ New in this release:
     * Ticket #101, item 1 fixed.
     * Ticket #105, fixed.
     * Ticket #84 fixed on x86.
+    * Ticket #105 fixed.
 
   * Other changes:
 
diff --git a/tests/trac.lisp b/tests/trac.lisp
index 9a02189f9..571b0691d 100644
--- a/tests/trac.lisp
+++ b/tests/trac.lisp
@@ -366,4 +366,33 @@
   (assert-error 'reader-error (read-from-string ".1e-45"))
   (assert-error 'reader-error (read-from-string "1d-324"))
   (assert-error 'reader-error (read-from-string "1w-324")))
+
+(defun read-string-fn (str)
+     (handler-case
+       (let ((acc nil))
+         (with-input-from-string
+           (stream str)
+           (loop do
+                 (let* ((eof-marker (cons nil nil))
+                        (elem (read stream nil eof-marker)))
+                   (if (eq elem eof-marker)
+                       (loop-finish)
+                     (push elem acc)))))
+         (setq acc (nreverse acc))
+         (values :OK acc))
+       (error (condition)
+              (return-from read-string-fn
+                (values :ERROR (format nil "~A" condition))))
+       (storage-condition (condition)
+                          (return-from read-string-fn
+                            (values :STORAGE (format nil "~A" condition))))))
+
+(define-test trac.105
+  (:tag :trac)
+  (assert-equal (values :ERROR
+			"Reader error on #<String-Input Stream>:
+No dispatch function defined for #\\W.")
+		(read-string-fn "#\wtf")))
+			   
+
   
\ No newline at end of file
-- 
GitLab