diff options
author | Andy Wingo <wingo@pobox.com> | 2023-06-07 22:26:05 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2023-06-08 10:26:16 +0200 |
commit | 02dfb6e7767c4946daa2aef1985007128f35351f (patch) | |
tree | c0118ded6b5495fea3c60544955e2a56e11285a5 /libguile/exceptions.c | |
parent | ee18ca9a355ca0d3fdd384a4b8db3bb3909d0c98 (diff) | |
download | guile-02dfb6e7767c4946daa2aef1985007128f35351f.tar.gz |
Fix exn dispatch for exns within pre-unwind handlers
* libguile/exceptions.c (exception_epoch_fluid): Rename from
active_exception_handlers_fluid.
(scm_dynwind_throw_handler): Increment exception epoch instead of
resetting active exception handlers.
(scm_init_exceptions): Update.
* module/ice-9/boot-9.scm (with-exception-handler): Rework to associate
an "epoch" fluid with each exception handler.
(with-throw-handler): Establish a new epoch, during the execution of a
throw handler.
(raise-exception): Rework to avoid capturing a list of exception
handlers, and to use epochs as a way to know which handlers have already
been examined and which are on the dispatch stack.
* test-suite/tests/exceptions.test ("throwing within exception
handlers"): New test.
Diffstat (limited to 'libguile/exceptions.c')
-rw-r--r-- | libguile/exceptions.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libguile/exceptions.c b/libguile/exceptions.c index 1fe281bc5..8b462955f 100644 --- a/libguile/exceptions.c +++ b/libguile/exceptions.c @@ -1,4 +1,4 @@ -/* Copyright 1995-1998,2000-2001,2003-2004,2006,2008,2009-2014,2017-2019 +/* Copyright 1995-1998,2000-2001,2003-2004,2006,2008,2009-2014,2017-2019,2023 Free Software Foundation, Inc. This file is part of Guile. @@ -109,7 +109,7 @@ call_exception_handler (SCM clo, SCM exn) SCM_KEYWORD (kw_unwind_p, "unwind?"); SCM_KEYWORD (kw_unwind_for_type, "unwind-for-type"); static SCM exception_handler_fluid; -static SCM active_exception_handlers_fluid; +static SCM exception_epoch_fluid; static SCM with_exception_handler_var; static SCM raise_exception_var; @@ -257,7 +257,8 @@ exception_has_type (SCM exn, SCM type) void scm_dynwind_throw_handler (void) { - scm_dynwind_fluid (active_exception_handlers_fluid, SCM_BOOL_F); + SCM depth = scm_oneplus (scm_fluid_ref (exception_epoch_fluid)); + scm_dynwind_fluid (exception_epoch_fluid, depth); } @@ -499,11 +500,11 @@ scm_init_exceptions () scm_set_smob_apply (tc16_exception_handler, call_exception_handler, 1, 0, 0); exception_handler_fluid = scm_make_thread_local_fluid (SCM_BOOL_F); - active_exception_handlers_fluid = scm_make_thread_local_fluid (SCM_BOOL_F); + exception_epoch_fluid = scm_make_fluid_with_default (SCM_INUM1); /* These binding are later removed when the Scheme definitions of raise and with-exception-handler are created in boot-9.scm. */ scm_c_define ("%exception-handler", exception_handler_fluid); - scm_c_define ("%active-exception-handlers", active_exception_handlers_fluid); + scm_c_define ("%exception-epoch", exception_epoch_fluid); with_exception_handler_var = scm_c_define ("with-exception-handler", SCM_BOOL_F); |