summaryrefslogtreecommitdiff
path: root/scsh-process.scm
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2017-06-29 20:20:54 +0200
committerPeter Bex <peter@more-magic.net>2017-06-29 20:20:54 +0200
commita3623a95addad8d6486c05482f71ed3e6d3877db (patch)
tree07a8be6d6c9bc82079fe6ac4a7e7d325aa16e32e /scsh-process.scm
parent2f5dbc451171a1a2988fc40b10c1497874cae9af (diff)
downloadscsh-process-a3623a95addad8d6486c05482f71ed3e6d3877db.tar.gz
Ensure ports are closed after reading in run/...* procedures (thanks to Jörg F. Wittenberger)
Diffstat (limited to 'scsh-process.scm')
-rw-r--r--scsh-process.scm19
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 ;;