>From c3e4536beee8cf1099a5bc669f5fa9fb2eb6809b Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 29 Sep 2013 13:17:58 +0200 Subject: [PATCH 4/4] Fix read-string! behaviour after peeking at EOF & add regression test. Slot 6 does not store the peeked character (anymore?), but whether the port is in an EOF state. Peeking goes via ungetc on FILE * ports, and via custom logic in other port types. --- extras.scm | 3 --- tests/port-tests.scm | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/extras.scm b/extras.scm index 613edee..36b6bc9 100644 --- a/extras.scm +++ b/extras.scm @@ -148,9 +148,6 @@ (define (##sys#read-string! n dest port start) (cond ((eq? n 0) 0) (else - (when (##sys#slot port 6) ; peeked? - (##core#inline "C_setsubchar" dest start (##sys#read-char-0 port)) - (set! start (fx+ start 1)) ) (let ((rdstring (##sys#slot (##sys#slot port 2) 7))) (if rdstring (let loop ((start start) (n n) (m 0)) diff --git a/tests/port-tests.scm b/tests/port-tests.scm index bd7c858..ebba350 100644 --- a/tests/port-tests.scm +++ b/tests/port-tests.scm @@ -300,6 +300,9 @@ EOF (test-group "read-string!" (let ((in (open-input-string "1234567890")) (buf (make-string 5))) + (test-equal "peek-char won't influence the result of read-string!" + (peek-char in) + #\1) (test-equal "read-string! won't read past buffer if given #f" (read-string! #f buf in) 5) @@ -317,6 +320,11 @@ EOF 3) (test-equal "read-string! leaves the buffer's tail intact" buf + "89067") + (test-equal "after peek-char at EOF, read-string! doesn't mutate the buffer" + (begin (peek-char in) + (read-string! #f buf in) + buf) "89067")) (let ((in (open-input-string "1234567890")) (buf (make-string 5))) @@ -337,6 +345,12 @@ EOF 3) (test-equal "read-string! leaves the buffer's tail intact" buf + "89067") + (test-equal "read-string! at EOF reads nothing" + (read-string! 10 buf in) + 0) + (test-equal "read-string! at EOF doesn't mutate the buffer" + buf "89067"))) ;; Disabled because it requires `echo -n` for -- 1.8.3.4