From f7286183368205e6488316bee3242f0344c33588 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 20 Dec 2022 21:44:27 -0500 Subject: [PATCH] Issue #498 - read-line can read 1022+ byte lines Previously the function would only read up to the first 1022 bytes. We now remove that restriction --- CHANGELOG.md | 1 + scheme/base.sld | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f39c1f7..5d7f90ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Bug Fixes +- Fix `read-line` to read entire lines that consist of more than 1022 bytes. Previously the function would only return partial data up to this limit. Thanks to Robby Zambito for the bug report. - `(include "body.scm")` inside a file `path/to/lib.sld` will look for `path/to/body.scm`, then fallback to the legacy behavior, and look for `$(pwd)/body.scm`. - Pass append and prepend directories when compiling dependent libraries of a program. This prevents issues where the directories are not made available to any `include` directives within such libraries. diff --git a/scheme/base.sld b/scheme/base.sld index b4ec756b..13631ec7 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -695,9 +695,26 @@ (Cyc-read-char (current-input-port)) (Cyc-read-char (car port)))) (define (read-line . port) - (if (null? port) - (Cyc-read-line (current-input-port)) - (Cyc-read-line (car port)))) + (let* ((p (if (null? port) + (current-input-port) + (car port))) + (str (Cyc-read-line p))) + (cond + ((eof-object? str) str) + ((< (string-length str) 1022) str) + (else (_read-line str p))))) + ;; Helper function to handle case where a line is too + ;; long to be read by a single runtime I/O call + (define (_read-line str port) + (let loop ((lis (list str)) + (str (Cyc-read-line port))) + (cond + ((eof-object? str) + (apply string-append (reverse lis))) + ((< (string-length str) 1022) + (apply string-append (reverse (cons str lis)))) + (else + (loop (cons str lis) (Cyc-read-line port)))))) (define (read-string k . opts) (let ((port (if (null? opts) (current-input-port)