~ chicken-core (chicken-5) 9508c87607b69dbe5026ea7227e1c1ff9ce1ef22
commit 9508c87607b69dbe5026ea7227e1c1ff9ce1ef22 Author: Peter Bex <peter@more-magic.net> AuthorDate: Sun Jul 29 17:33:27 2018 +0200 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Mon Jul 30 09:57:13 2018 +0200 Restore read-string semantics when reading 0 bytes by not attempting to peek We accidentally changed this behaviour when we changed read-string to return #!eof on EOF. The code was slightly restructured under the assumption that calling peek-char will never hurt, and then return "" when asking for zero bytes. Logically, this is correct, but in some cases the FD might not be ready. In those cases you may run into a read timeout, but reading zero bytes should arguably always succeed immediately, regardless of port/FD state. Signed-off-by: felix <felix@call-with-current-continuation.org> diff --git a/extras.scm b/extras.scm index bc04f161..ec504fc6 100644 --- a/extras.scm +++ b/extras.scm @@ -153,8 +153,8 @@ (define read-string/port (lambda (n p) - (cond ((eof-object? (##sys#peek-char-0 p)) - (if (eq? n 0) "" #!eof)) + (cond ((eq? n 0) "") ; Don't attempt to peek (fd might not be ready) + ((eof-object? (##sys#peek-char-0 p)) #!eof) (n (let* ((str (##sys#make-string n)) (n2 (read-string!/port n str p 0))) (if (eq? n n2)Trap