From 6be845ff30ed5f7cbd4fe1d99b0d6357a8275fce Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 20 May 2014 17:19:09 -0500 Subject: [PATCH] do a better job of keeping the err/out ports IO in the right order ... in the case that IO happens during the 'first-opened' method, e.g., during teachpack running in an empty REPL --- .../drracket/drracket/private/rep.rkt | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/pkgs/drracket-pkgs/drracket/drracket/private/rep.rkt b/pkgs/drracket-pkgs/drracket/drracket/private/rep.rkt index 9f0c0d5a4e..b9bf71eeb6 100644 --- a/pkgs/drracket-pkgs/drracket/drracket/private/rep.rkt +++ b/pkgs/drracket-pkgs/drracket/drracket/private/rep.rkt @@ -1767,16 +1767,29 @@ TODO (cond [(null? ports) (channel-put io-chan io)] [else - (apply sync - (map (λ (port) (handle-evt - port - (λ (_) - (define byte/special (read-byte-or-special port)) - (if (eof-object? byte/special) - (loop (remq port ports) io) - (loop ports (cons (cons port byte/special) - io)))))) - ports))])))) + (apply + sync + (for/list ([port (in-list ports)]) + (handle-evt + port + (λ (_) + (define-values (the-bytes/specials eof?) + (let b-loop ([bytes '()]) + (cond + [(byte-ready? port) + (define b (read-byte-or-special port)) + (cond + [(eof-object? b) (values bytes #t)] + [else (b-loop (cons b bytes))])] + [else (values bytes #f)]))) + (define new-io + (if (null? bytes) + io + (cons (cons port (reverse the-bytes/specials)) + io))) + (if eof? + (loop (remq port ports) new-io) + (loop ports new-io))))))])))) (run-in-evaluation-thread (λ () @@ -1808,13 +1821,15 @@ TODO ;; duplicate it over to the user's ports, now that there is ;; no danger of deadlock (for ([i (in-list (reverse (channel-get io-chan)))]) - (define obj (cdr i)) - - ((if (byte? obj) write-byte write-special) - obj - (if (eq? (car i) sp-err-other-end) - (get-err-port) - (get-out-port)))) + (define objs (cdr i)) + (define port + (if (equal? (car i) sp-err-other-end) + (get-err-port) + (get-out-port))) + (for ([obj (in-list objs)]) + ((if (byte? obj) write-byte write-special) + obj + port))) (flush-output (get-err-port)) (flush-output (get-out-port)))