Fix bug 242 for fd-streams
[sbcl.git] / src / code / reader.lisp
index 4eb3400..b6f28cf 100644 (file)
 
 (defun read-comment (stream ignore)
   (declare (ignore ignore))
-  (let ((stream (in-synonym-of stream)))
-    (if (ansi-stream-p stream)
-       (prepare-for-fast-read-char stream
-         (do ((char (fast-read-char nil nil)
-                    (fast-read-char nil nil)))
-             ((or (not char) (char= char #\newline))
-              (done-with-fast-read-char))))
-       ;; CLOS stream
-       (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
-           ((or (eq char :eof) (char= char #\newline))))))
+  (handler-bind
+      ((character-decoding-error
+       #'(lambda (decoding-error)
+           (declare (ignorable decoding-error))
+           (style-warn "Character decoding error in a ;-comment at position ~A reading source file ~A, resyncing." (file-position stream) stream)
+           (invoke-restart 'attempt-resync))))
+    (let ((stream (in-synonym-of stream)))
+      (if (ansi-stream-p stream)
+         (prepare-for-fast-read-char stream
+          (do ((char (fast-read-char nil nil)
+                     (fast-read-char nil nil)))
+              ((or (not char) (char= char #\newline))
+               (done-with-fast-read-char))))
+         ;; CLOS stream
+         (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
+             ((or (eq char :eof) (char= char #\newline)))))))
   ;; Don't return anything.
   (values))
 
        (#.+char-attr-single-escape+ (go SINGLE-ESCAPE))
        (#.+char-attr-package-delimiter+ (go COLON))
        (#.+char-attr-multiple-escape+ (go MULT-ESCAPE))
-       (#.+char-attr-invalid+ (%reader-error "invalid constituent"))
+       (#.+char-attr-invalid+ (%reader-error stream "invalid constituent"))
        ;; can't have eof, whitespace, or terminating macro as first char!
        (t (go SYMBOL)))
      SIGN ; saw "sign"