cs: auto-flush stdout/stderr only when terminals

Match BC's long-standing behavior of only flushing the original output
and error ports on input from the original input port when the output
and/or error port is a terminal port.
This commit is contained in:
Matthew Flatt 2021-04-27 11:55:59 -06:00
parent a385788971
commit 2f9cd5446b
3 changed files with 17 additions and 8 deletions

View File

@ -43,10 +43,12 @@ one byte is read for @racket[read-bytes-avail!*],
buffered bytes, but no further bytes are read. buffered bytes, but no further bytes are read.
In addition, the initial current output and error ports are In addition, the initial current output and error ports are
automatically flushed when @racket[read], @racket[read-line], automatically flushed when they are terminal ports (see
@racket[terminal-port?]) and when @racket[read], @racket[read-line],
@racket[read-bytes], @racket[read-string], etc., are performed on the @racket[read-bytes], @racket[read-string], etc., are performed on the
initial standard input port; more precisely, flushing is performed by initial standard input port. (More precisely, instead of
the default port read handler (see @racket[port-read-handler]). @racket[read], flushing is performed by the default port read handler;
see @racket[port-read-handler].)
@defproc[(flush-output [out output-port? (current-output-port)]) void?]{ @defproc[(flush-output [out output-port? (current-output-port)]) void?]{

View File

@ -11890,8 +11890,12 @@
(lambda (in_0) (lambda (in_0)
(if (eq? in_0 (unsafe-place-local-ref cell.1$9)) (if (eq? in_0 (unsafe-place-local-ref cell.1$9))
(begin (begin
(1/flush-output (unsafe-place-local-ref cell.2$2)) (if (1/terminal-port? (unsafe-place-local-ref cell.2$2))
(1/flush-output (unsafe-place-local-ref cell.3))) (1/flush-output (unsafe-place-local-ref cell.2$2))
(void))
(if (1/terminal-port? (unsafe-place-local-ref cell.3))
(1/flush-output (unsafe-place-local-ref cell.3))
(void)))
(void)))) (void))))
(define do-read-bytes! (define do-read-bytes!
(lambda (who_0 in_0 bstr_0 start_0 end_0) (lambda (who_0 in_0 bstr_0 start_0 end_0)

View File

@ -6,7 +6,8 @@
"port.rkt" "port.rkt"
"output-port.rkt" "output-port.rkt"
"pipe.rkt" "pipe.rkt"
"check.rkt") "check.rkt"
"fd-port.rkt")
(provide flush-output (provide flush-output
maybe-flush-stdout) maybe-flush-stdout)
@ -37,5 +38,7 @@
(define (maybe-flush-stdout in) (define (maybe-flush-stdout in)
(when (eq? in orig-input-port) (when (eq? in orig-input-port)
(flush-output orig-output-port) (when (terminal-port? orig-output-port)
(flush-output orig-error-port))) (flush-output orig-output-port))
(when (terminal-port? orig-error-port)
(flush-output orig-error-port))))