diff --git a/src/code/extfmts.lisp b/src/code/extfmts.lisp index 9efcb0a6fae065a0da0bf0da406bafd6ea83cc08..f3f19c29c4e20081be55cc6e5b7634244337190b 100644 --- a/src/code/extfmts.lisp +++ b/src/code/extfmts.lisp @@ -22,7 +22,8 @@ describe-external-format)) (defvar *default-external-format* - :iso8859-1 + #-unicode :iso8859-1 + #+unicode :utf-8 "The default external format to use if no other external format is specified") @@ -460,11 +461,11 @@ (defun %find-external-format (name) ;; avoid loading files, etc., early in the boot sequence - (when (or (eq name :iso8859-1) - (and (eq name :default) (eq *default-external-format* :iso8859-1))) + (when (eq name :iso8859-1) (return-from %find-external-format (gethash :iso8859-1 *external-formats*))) - (when (eq name :utf-8) + (when (or (eq name :utf-8) + (and (eq name :default) (eq *default-external-format* :utf-8))) (return-from %find-external-format (gethash :utf-8 *external-formats*))) @@ -1154,7 +1155,8 @@ character and illegal outputs are replaced by a question mark.") (not (eq unix::*filename-encoding* filenames))) (cerror (intl:gettext "Change it anyway.") (intl:gettext "The external-format for encoding filenames is already set."))) - (setq unix::*filename-encoding* filenames)) + (setq unix::*filename-encoding* filenames) + (setq unix::*default-filename-encoding* filenames)) t) diff --git a/src/code/fd-stream.lisp b/src/code/fd-stream.lisp index 470dfe23e94422627320af48f101f342c630052a..1d9099b0d0781a10e23fb71da0395245efe6e505 100644 --- a/src/code/fd-stream.lisp +++ b/src/code/fd-stream.lisp @@ -2397,20 +2397,20 @@ (setf *available-buffers* nil) (setf *stdin* (make-fd-stream 0 :name "Standard Input" :input t :buffering :line - :external-format :iso8859-1)) + :external-format :utf-8)) (setf *stdout* (make-fd-stream 1 :name "Standard Output" :output t :buffering :line - :external-format :iso8859-1)) + :external-format :utf-8)) (setf *stderr* (make-fd-stream 2 :name "Standard Error" :output t :buffering :line - :external-format :iso8859-1)) + :external-format :utf-8)) (let ((tty (and (not *batch-mode*) (unix:unix-open "/dev/tty" unix:o_rdwr #o666)))) (setf *tty* (if tty (make-fd-stream tty :name "the Terminal" :input t :output t :buffering :line :auto-close t - :external-format :iso8859-1) + :external-format :utf-8) (make-two-way-stream *stdin* *stdout*)))) nil) diff --git a/src/code/lispinit.lisp b/src/code/lispinit.lisp index 01d7f33c228339736c1bf954ffa6af14ecdd6327..42cf568896008eba519a97a3584c881060d7d002 100644 --- a/src/code/lispinit.lisp +++ b/src/code/lispinit.lisp @@ -482,7 +482,9 @@ (set-floating-point-modes :traps '(:overflow :invalid :divide-by-zero)) ;; Clear pseudo atomic in case this core wasn't compiled with support. - #+(or x86 amd64) (setf lisp::*pseudo-atomic-atomic* 0)))) + #+(or x86 amd64) (setf lisp::*pseudo-atomic-atomic* 0) + (unless unix::*filename-encoding* + (setf unix::*filename-encoding* unix::*default-filename-encoding*))))) ;;;; Miscellaneous external functions: diff --git a/src/code/unix.lisp b/src/code/unix.lisp index 9dd6db03d3043b1b2586c0ce3810defdddfadf77..fef496437f3531141f026c101967f6b067ce2189 100644 --- a/src/code/unix.lisp +++ b/src/code/unix.lisp @@ -26,6 +26,9 @@ ;; non-Latin-1 characters "mojibake", but otherwise they'll be inaccessible. ;; Must be set to NIL initially to enable building Lisp! (defvar *filename-encoding* nil) +(defvar *default-filename-encoding* + #-unicode nil + #+unicode :utf-8) (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro %name->file (string) diff --git a/tests/issues.lisp b/tests/issues.lisp index 3ad494bb15b5bb031e32c24a58e7ea1feac11381..eb257e8d127d5406930c42a601874f90688676ce 100644 --- a/tests/issues.lisp +++ b/tests/issues.lisp @@ -579,3 +579,24 @@ with user-info = (unix:unix-getpwuid uid) while user-info finally (assert-false user-info))) + +(define-test issue-139.1 + (:tag :issues) + ;; Verify the value of the default external format and that system streams use :utf-8. + (assert-eql :utf-8 stream:*default-external-format*) + (assert-eql :utf-8 (stream-external-format sys:*stdin*)) + (assert-eql :utf-8 (stream-external-format sys:*stdout*)) + (assert-eql :utf-8 (stream-external-format sys:*stderr*)) + ;; *tty* can either be an fd-stream, in which case the format is + ;; utf8, or a two-way-stream, in which case it is :default. + (if (typep sys:*tty* 'two-way-stream) + (assert-eql :default (stream-external-format sys:*tty*)) + (assert-eql :utf-8 (stream-external-format sys:*tty*))) + ;; Check that printing to *standard-output* is correctly encoded. + (dribble "test-format.txt") + ;; Print a Greek lower-case alpha character + (princ #\u+3b1) + (dribble) + (with-open-file (s "test-format.txt" :direction :input) + (let ((c (read-char s))) + (assert-equal #\u+3b1 c))))