1.0.37.3: make *STANDARD-INPUT*, *STANDARD-OUTPUT*, and *ERROR-OUTPUT* bivalent
authorNikodemus Siivola <nikodemus@random-state.net>
Sun, 28 Mar 2010 10:44:04 +0000 (10:44 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Sun, 28 Mar 2010 10:44:04 +0000 (10:44 +0000)
 * Also allow bivalent output streams to use :LINE buffering: take it
   to mean :FULL for binary output.

NEWS
src/code/fd-stream.lisp
tests/stream.test.sh [new file with mode: 0644]
version.lisp-expr

diff --git a/NEWS b/NEWS
index 78c2c54..c59c33b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
 changes relative to sbcl-1.0.36:
+  * enhancement: *STANDARD-OUTPUT*, *STANDARD-INPUT*, and *ERROR-OUTPUT* are
+    now bivalent.
   * bug fix: correct restart text for the continuable error in MAKE-PACKAGE.
 
 changes in sbcl-1.0.37 relative to sbcl-1.0.36:
index d2acaee..d98bf4a 100644 (file)
       (when (or (not character-stream-p) bivalent-stream-p)
         (multiple-value-setq (bout-routine bout-type bout-size output-bytes
                                            normalized-external-format)
-          (pick-output-routine (if bivalent-stream-p
-                                   '(unsigned-byte 8)
-                                   target-type)
-                               (fd-stream-buffering fd-stream)
-                               external-format))
+          (let ((buffering (fd-stream-buffering fd-stream)))
+            (if bivalent-stream-p
+                (pick-output-routine '(unsigned-byte 8)
+                                     (if (eq :line buffering)
+                                         :full
+                                         buffering)
+                                     external-format)
+                (pick-output-routine target-type buffering external-format))))
         (unless bout-routine
           (error "could not find any output routine for ~S buffered ~S"
                  (fd-stream-buffering fd-stream)
   (with-output-to-string (*error-output*)
     (setf *stdin*
           (make-fd-stream 0 :name "standard input" :input t :buffering :line
-                            :external-format (stdstream-external-format nil)))
+                          :element-type :default
+                          :external-format (stdstream-external-format nil)))
     (setf *stdout*
           (make-fd-stream 1 :name "standard output" :output t :buffering :line
-                            :external-format (stdstream-external-format t)))
+                          :element-type :default
+                          :external-format (stdstream-external-format t)))
     (setf *stderr*
           (make-fd-stream 2 :name "standard error" :output t :buffering :line
-                            :external-format (stdstream-external-format t)))
+                          :element-type :default
+                          :external-format (stdstream-external-format t)))
     (let* ((ttyname #.(coerce "/dev/tty" 'simple-base-string))
            (tty (sb!unix:unix-open ttyname sb!unix:o_rdwr #o666)))
       (if tty
diff --git a/tests/stream.test.sh b/tests/stream.test.sh
new file mode 100644 (file)
index 0000000..3c5e38e
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# This software is part of the SBCL system. See the README file for
+# more information.
+#
+# While most of SBCL is derived from the CMU CL system, the test
+# files (like this one) were written from scratch after the fork
+# from CMU CL.
+#
+# This software is in the public domain and is provided with
+# absolutely no warranty. See the COPYING and CREDITS files for
+# more information.
+
+. ./subr.sh
+
+use_test_subdirectory
+
+tmpfilename="$TEST_FILESTEM.lisp"
+
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (if (equal (concatenate 'string "Bivalent *STANDARD-INPUT*" (string #\newline))
+               (with-output-to-string (s)
+                 (loop for byte = (read-byte *standard-input* nil)
+                       while byte do (write-char (code-char byte) s))))
+        (quit :unix-status $EXIT_LISP_WIN)
+        (quit :unix-status $EXIT_LOSE))
+EOF
+run_sbcl --disable-debugger --load $tmpfilename <<EOF
+Bivalent *STANDARD-INPUT*
+EOF
+check_status_maybe_lose bivalent-standard-input $?
+
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (loop for char across "Bivalent *STANDARD-OUTPUT*"
+          do (write-byte (char-code char) *standard-output*))
+    (terpri *standard-output*)
+    (quit :unix-status $EXIT_LISP_WIN)
+EOF
+run_sbcl --disable-debugger --load $tmpfilename > $tmpfilename.out
+check_status_maybe_lose bivalent-standard-output $?
+test_output=$(cat $tmpfilename.out)
+rm -f $tmpfilename.out
+if [ 'Bivalent *STANDARD-OUTPUT*' != "$test_output" ]; then
+    echo "bad test output: '$test_output'"
+    exit $EXIT_LOSE
+fi
+
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (loop for char across "Bivalent *ERROR-OUTPUT*"
+          do (write-byte (char-code char) *error-output*))
+    (terpri *error-output*)
+    (quit :unix-status $EXIT_LISP_WIN)
+EOF
+run_sbcl --disable-debugger --load $tmpfilename 2> $tmpfilename.out
+check_status_maybe_lose bivalent-error-output $?
+test_output=$(cat $tmpfilename.out)
+rm -f $tmpfilename.out
+if [ 'Bivalent *ERROR-OUTPUT*' != "$test_output" ]; then
+    echo "bad test output: '$test_output'"
+    exit $EXIT_LOSE
+fi
+
+# success
+exit $EXIT_TEST_WIN
index ce76924..6424f02 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".)
-"1.0.37.2"
+"1.0.37.3"