From da9a05d500741cd2ad6b49356d0f2c978935daff Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Fri, 7 Jun 2019 20:13:17 -0400 Subject: [PATCH] Do not use 'with-continuation-barrier'. It turns out that 'with-continuation-barrier' allows delimited continuations (i.e., prompts) to get through. * gash/shell.scm (%subshell): Replace 'with-continuation-barrier' with 'dynamic-wind', making sure to preserve exit statuses that were leaked through before. * tests/unit/shell.scm (call-with-temporary-directory): Replace 'with-continuation-barrier' with 'dynamic-wind'. * tests/spec/oil.scm: Enable previously failing tests. --- gash/shell.scm | 21 ++++++++++++++------- tests/spec/oil.scm | 3 --- tests/unit/shell.scm | 13 +++++++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gash/shell.scm b/gash/shell.scm index 1aefe86..b2703c3 100644 --- a/gash/shell.scm +++ b/gash/shell.scm @@ -247,13 +247,20 @@ process." ;; duplicate output. (flush-all-ports) (match (primitive-fork) - (0 (with-continuation-barrier - (lambda () - (restore-signals) - (set-atexit! #f) - (thunk) - (primitive-exit (get-status)))) - (primitive-exit 1)) + (0 (dynamic-wind + (lambda () #t) + (lambda () + (restore-signals) + (set-atexit! #f) + ;; We need to preserve the status given to 'exit', so we + ;; catch the 'quit' key here. + (catch 'quit + thunk + (lambda (_ status) + (primitive-exit status))) + (primitive-exit (get-status))) + (lambda () + (primitive-exit 1)))) (pid pid))) (define (sh:subshell thunk) diff --git a/tests/spec/oil.scm b/tests/spec/oil.scm index dc91d65..b8793c2 100644 --- a/tests/spec/oil.scm +++ b/tests/spec/oil.scm @@ -158,9 +158,6 @@ ("\\$\\(\\(i\\+1\\)\\)" "$(expr $i + 1)")) ("while in pipe with subshell" ("\\$\\(\\(i\\+1\\)\\)" "$(expr $i + 1)")) - ;; Gash needs to be fixed to pass these tests. - ("continue in subshell") - ("continue in subshell aborts with errexit") ;; The Oil shell handles this statically. We ;; will treat it as a fatal run-time error (for ;; now). diff --git a/tests/unit/shell.scm b/tests/unit/shell.scm index 7dedfb4..e45f7f2 100644 --- a/tests/unit/shell.scm +++ b/tests/unit/shell.scm @@ -58,12 +58,13 @@ (file-system-fold enter? leaf down up skip error #f path)) (define (call-with-temporary-directory proc) - (let* ((directory (make-temporary-directory)) - (result (with-continuation-barrier - (lambda () - (proc directory))))) - (delete-recursively directory) - result)) + (let* ((directory (make-temporary-directory))) + (dynamic-wind + (lambda () #t) + (lambda () + (proc directory)) + (lambda () + (delete-recursively directory))))) (define (%make-script object . forms) (define (write-script port)