Hi everyone,

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. The attached patch fixes this and adds a
corresponding regression test. It applies to both master and chicken-5.

Cheers
Moritz
>From 0fb9dd6eb4f9380e6ef44cf4ee2030e1f11ef412 Mon Sep 17 00:00:00 2001
From: Moritz Heidkamp <moritz.heidk...@bevuta.com>
Date: Fri, 14 Apr 2017 16:22:39 +0200
Subject: [PATCH] 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.
---
 library.scm          | 3 +--
 tests/port-tests.scm | 2 ++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/library.scm b/library.scm
index 3caba429..51d6793b 100644
--- a/library.scm
+++ b/library.scm
@@ -4255,8 +4255,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 ec6a323b..463e31e6 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) "")
-- 
2.12.0

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to