~ chicken-core (chicken-5) df10e8ae06e98d27f045463949b8acaef765c6e7
commit df10e8ae06e98d27f045463949b8acaef765c6e7
Author: Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Sun Sep 29 13:17:58 2013 +0200
Commit: Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Wed Oct 2 14:26:55 2013 +0200
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.
Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>
diff --git a/extras.scm b/extras.scm
index 613edeef..36b6bc99 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 bd7c8586..ebba3503 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)))
@@ -336,6 +344,12 @@ EOF
(read-string! 10 buf in)
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")))
Trap