~ chicken-core (chicken-5) 822a03ddca4c6faf2a147553977acbc89e5fa7b2
commit 822a03ddca4c6faf2a147553977acbc89e5fa7b2
Author: Moritz Heidkamp <moritz.heidkamp@bevuta.com>
AuthorDate: Fri Apr 14 16:22:39 2017 +0200
Commit: Peter Bex <peter@more-magic.net>
CommitDate: Fri Apr 14 19:30:11 2017 +0200
Fix char-ready? on EOF for string input ports
char-ready? on string input ports would return #f when they've reached
the end of their underlying string. However, char-ready? is supposed
to return #t in this case.
Signed-off-by: Peter Bex <peter@more-magic.net>
diff --git a/NEWS b/NEWS
index df1af55b..b43e851e 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@
- Core Libraries
- Unit "posix": If file-lock, file-lock/blocking or file-unlock are
interrupted by a signal, we now retry (thanks to Joerg Wittenberger).
+ - char-ready? on string ports now also returns #t at EOF, as per R5RS;
+ in other words, it always returns #t (thanks to Moritz Heidkamp)
- Build system
- Fixed broken compilation on NetBSD, due to missing _NETBSD_SOURCE.
diff --git a/library.scm b/library.scm
index 09f9dd15..f7d1e918 100644
--- a/library.scm
+++ b/library.scm
@@ -3548,8 +3548,7 @@ EOF
(##sys#setislot p 10 (fx+ position len)) ) ) )
void ; close
(lambda (p) #f) ; flush-output
- (lambda (p) ; char-ready?
- (fx< (##sys#slot p 10) (##sys#slot p 11)) )
+ (lambda (p) #t) ; char-ready?
(lambda (p n dest start) ; read-string!
(let* ((pos (##sys#slot p 10))
(n2 (fx- (##sys#slot p 11) pos) ) )
diff --git a/tests/port-tests.scm b/tests/port-tests.scm
index 259892cf..28ca2276 100644
--- a/tests/port-tests.scm
+++ b/tests/port-tests.scm
@@ -42,6 +42,8 @@ EOF
(read-line p)))
(assert (= 20 (length (read-lines (open-input-string *text*)))))
+(assert (char-ready? (open-input-string "")))
+
(let ((out (open-output-string)))
(test-equal "Initially, output string is empty"
(get-output-string out) "")
Trap