diff options
author | Peter Bex <peter@more-magic.net> | 2017-06-29 20:20:54 +0200 |
---|---|---|
committer | Peter Bex <peter@more-magic.net> | 2017-06-29 20:20:54 +0200 |
commit | a3623a95addad8d6486c05482f71ed3e6d3877db (patch) | |
tree | 07a8be6d6c9bc82079fe6ac4a7e7d325aa16e32e | |
parent | 2f5dbc451171a1a2988fc40b10c1497874cae9af (diff) | |
download | scsh-process-a3623a95addad8d6486c05482f71ed3e6d3877db.tar.gz |
Ensure ports are closed after reading in run/...* procedures (thanks to Jörg F. Wittenberger)
-rw-r--r-- | scsh-process.scm | 19 |
1 files 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 ;; |