From 70e5aa14a367cd8197b5821be284dec05476dbab Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Fri, 13 Oct 2023 16:37:39 +1100 Subject: [PATCH] Unwind before exit --- lib/scheme/process-context.sld | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/scheme/process-context.sld b/lib/scheme/process-context.sld index 3639b596..4e61d7eb 100644 --- a/lib/scheme/process-context.sld +++ b/lib/scheme/process-context.sld @@ -1,9 +1,18 @@ (define-library (scheme process-context) (import (chibi) (srfi 98)) - (cond-expand (windows (import (only (chibi win32 process-win32) exit))) - (else (import (only (chibi process) exit)))) + (cond-expand (windows (import (rename (only (chibi win32 process-win32) exit) (exit emergency-exit)))) + (else (import (rename (only (chibi process) exit) (exit emergency-exit))))) (export get-environment-variable get-environment-variables command-line exit emergency-exit) - ;; TODO: Make exit unwind and finalize properly. - (begin (define emergency-exit exit))) + + (begin + (define unwind #f) + + ((call/cc + (lambda (continuation) + (set! unwind continuation) + (lambda () #f)))) + + (define (exit . rest) + (unwind (lambda () (apply emergency-exit rest))))))