From a3623a95addad8d6486c05482f71ed3e6d3877db Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Thu, 29 Jun 2017 20:20:54 +0200 Subject: Ensure ports are closed after reading in run/...* procedures (thanks to Jörg F. Wittenberger) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scsh-process.scm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scsh-process.scm b/scsh-process.scm index a5d3df6..e2be39c 100644 --- a/scsh-process.scm +++ b/scsh-process.scm @@ -312,17 +312,22 @@ (with-output-to-port (open-output-file* 1) thunk))))) temp-file)) +(define (call-with-run/port* thunk consumer) + (let ((in (run/port* thunk))) + ;; This is really more like unwind-protect + (dynamic-wind + void + (lambda () (consumer in)) + (lambda () (close-input-port in))))) + (define (run/string* thunk) - (read-string #f (run/port* thunk))) + (call-with-run/port* thunk (lambda (in) (read-string #f in)))) (define (run/strings* thunk) - (read-lines (run/port* thunk))) + (call-with-run/port* thunk read-lines)) (define (run/sexp* thunk) - (let* ((p (run/port* thunk)) - (res (read p))) - (close-input-port p) - res)) + (call-with-run/port* thunk read)) (define (run/sexps* thunk) - (read-file (run/port* thunk))) + (call-with-run/port* thunk read-file)) ;;;;;;;;;;;; ;; Syntax ;; -- cgit v1.2.3