~ chicken-core (chicken-5) f815158289343a4021eb739694462289853ccce1
commit f815158289343a4021eb739694462289853ccce1
Author: Evan Hanson <evhan@foldling.org>
AuthorDate: Tue Apr 5 20:33:15 2016 +1200
Commit: Evan Hanson <evhan@foldling.org>
CommitDate: Tue Apr 5 20:35:25 2016 +1200
Return #!eof on end-of-file in read-u8vector
This change is for uniformity with read-string, and fixes an invalid
memory access in read-u8vector's use of `##sys#read-string/port`, which
didn't check for #!eof.
diff --git a/manual/Unit srfi-4 b/manual/Unit srfi-4
index dfc42345..8043dd96 100644
--- a/manual/Unit srfi-4
+++ b/manual/Unit srfi-4
@@ -87,10 +87,12 @@ not including {{TO}}.
<procedure>(read-u8vector [LENGTH [PORT]])</procedure>
Reads {{LENGTH}} bytes from the {{PORT}} and returns a fresh
-{{u8vector}} or less if end-of-file is encountered. {{PORT}} defaults to the
-value of {{(current-input-port)}}.
+{{u8vector}}, or as many as are available before end-of-file is
+encountered. {{PORT}} defaults to the value of {{(current-input-port)}}.
+If no bytes are available before the end-of-file, {{#!eof}} is returned.
-If {{LENGTH}} is {{#f}}, the vector will be filled completely until end-of-file is reached.
+If {{LENGTH}} is {{#f}}, the vector will be filled completely until
+end-of-file is reached.
<procedure>(read-u8vector! LENGTH U8VECTOR [PORT [START]])</procedure>
diff --git a/srfi-4.scm b/srfi-4.scm
index 6403f3f4..25a15cd4 100644
--- a/srfi-4.scm
+++ b/srfi-4.scm
@@ -816,7 +816,9 @@ EOF
(define (read-u8vector #!optional n (p ##sys#standard-input))
(let ((str (##sys#read-string/port n p)))
- (##core#inline "C_string_to_bytevector" str)
- (##sys#make-structure 'u8vector str)))
+ (cond ((eof-object? str) str)
+ (else
+ (##core#inline "C_string_to_bytevector" str)
+ (##sys#make-structure 'u8vector str)))))
(register-feature! 'srfi-4))
Trap