Raymond Toy pushed to branch issue-139-add-alias-local-external-format at cmucl / cmucl
Commits:
-
e7459829
by Raymond Toy at 2022-11-25T15:35:51+00:00
-
88843edc
by Raymond Toy at 2022-11-25T15:35:52+00:00
-
85ff8a6a
by Raymond Toy at 2022-11-25T07:39:38-08:00
-
0ba8661b
by Raymond Toy at 2022-11-25T07:43:51-08:00
3 changed files:
Changes:
... | ... | @@ -290,13 +290,21 @@ |
290 | 290 | (stream-dispatch stream
|
291 | 291 | ;; simple-stream
|
292 | 292 | (stream::%stream-external-format stream)
|
293 | - ;; lisp-stream
|
|
294 | - (typecase stream
|
|
293 | + ;; lisp-stream. For unsupported streams, signal a type error.
|
|
294 | + (etypecase stream
|
|
295 | 295 | #+unicode
|
296 | 296 | (fd-stream (fd-stream-external-format stream))
|
297 | - (synonym-stream (stream-external-format
|
|
298 | - (symbol-value (synonym-stream-symbol stream))))
|
|
299 | - (t :default))
|
|
297 | + (broadcast-stream
|
|
298 | + ;; See http://www.lispworks.com/documentation/HyperSpec/Body/t_broadc.htm
|
|
299 | + (let ((components (broadcast-stream-streams stream)))
|
|
300 | + (if (null components)
|
|
301 | + :default
|
|
302 | + (stream-external-format (car (last components))))))
|
|
303 | + (synonym-stream
|
|
304 | + ;; Not defined by CLHS. What should happen if
|
|
305 | + ;; (synonym-stream-symbol stream) is unbound?
|
|
306 | + (stream-external-format
|
|
307 | + (symbol-value (synonym-stream-symbol stream)))))
|
|
300 | 308 | ;; fundamental-stream
|
301 | 309 | :default))
|
302 | 310 |
... | ... | @@ -60,6 +60,7 @@ public domain. |
60 | 60 | * ~~#134~~ Handle the case of `(expt complex complex-rational)`
|
61 | 61 | * ~~#136~~ `ensure-directories-exist` should return the given pathspec
|
62 | 62 | * #139 `*default-external-format*` defaults to `:utf-8`; add alias for `:locale` external format
|
63 | + * ~~#140~~ External format for streams that are not `file-stream`'s
|
|
63 | 64 | * ~~#141~~ Disallow locales that are pathnames to a localedef file
|
64 | 65 | * ~~#142~~ `(random 0)` signals incorrect error
|
65 | 66 | * ~~#147~~ `stream-line-column` method missing for `fundamental-character-output-stream`
|
... | ... | @@ -750,6 +750,53 @@ |
750 | 750 | ;; Just verify that :locale format exists
|
751 | 751 | (assert-true (stream::find-external-format :locale nil)))
|
752 | 752 | |
753 | +;;; Test stream-external-format for various types of streams.
|
|
754 | + |
|
755 | +(define-test issue.140.two-way-stream
|
|
756 | + (:tag :issues)
|
|
757 | + (with-open-file (in (merge-pathnames "issues.lisp" cmucl-test-runner::*load-path*)
|
|
758 | + :direction :input
|
|
759 | + :external-format :utf-8)
|
|
760 | + (with-open-file (out "/tmp/output.tst"
|
|
761 | + :direction :output
|
|
762 | + :external-format :utf-8
|
|
763 | + :if-exists :supersede)
|
|
764 | + (let ((two-way-stream (make-two-way-stream in out)))
|
|
765 | + (assert-error 'type-error
|
|
766 | + (stream-external-format two-way-stream))))))
|
|
767 | + |
|
768 | +;; Test synonym-stream returns the format of the underlying stream.
|
|
769 | +(define-test issue.140.synonym-stream
|
|
770 | + (:tag :issues)
|
|
771 | + (with-open-file (s (merge-pathnames "issues.lisp" cmucl-test-runner::*load-path*)
|
|
772 | + :direction :input
|
|
773 | + :external-format :iso8859-1)
|
|
774 | + (let ((syn (make-synonym-stream '*syn-stream*)))
|
|
775 | + (setf syn s)
|
|
776 | + (assert-equal :iso8859-1 (stream-external-format syn)))))
|
|
777 | + |
|
778 | +(define-test issue.140.broadcast-stream
|
|
779 | + (:tag :issues)
|
|
780 | + ;; Create 3 output streams. The exact external formats aren't
|
|
781 | + ;; really important here as long as they're different for each file
|
|
782 | + ;; so we can tell if we got the right answer.
|
|
783 | + (with-open-file (s1 "/tmp/broad-1"
|
|
784 | + :direction :output
|
|
785 | + :if-exists :supersede
|
|
786 | + :external-format :latin1)
|
|
787 | + (with-open-file (s2 "/tmp/broad-2"
|
|
788 | + :direction :output
|
|
789 | + :if-exists :supersede
|
|
790 | + :external-format :utf-8)
|
|
791 | + (with-open-file (s3 "/tmp/broad-3"
|
|
792 | + :direction :output
|
|
793 | + :if-exists :supersede
|
|
794 | + :external-format :utf-16)
|
|
795 | + ;; The format must be the value from the last stream.
|
|
796 | + (assert-equal :utf-16
|
|
797 | + (stream-external-format
|
|
798 | + (make-broadcast-stream s1 s2 s3)))))))
|
|
799 | + |
|
753 | 800 | (define-test issue.150
|
754 | 801 | (:tag :issues)
|
755 | 802 | (let ((ext:*gc-verbose* nil)
|