mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
Avoid stacks in dynamically-bound values
* libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_find_old_fluid_value): New function. * libguile/fluids.c (saved_dynamic_state_ref): New helper. (scm_fluid_ref): Fix docstring. (scm_fluid_ref_star): New function allowing access to previous values for a fluid. (scm_dynamic_state_ref): New internal function. * libguile/fluids.h: Add scm_fluid_ref_star and scm_dynamic_state_ref. * libguile/stacks.c (scm_stack_id): Adapt to %stacks not being a chain. * libguile/throw.c (catch, throw_without_pre_unwind): Adapt to %exception-handlers not being a chain. * module/ice-9/boot-9.scm (catch, dispatch-exception): Instead of having %exception-handlers be a chain, use fluid-ref* to access the chain that is in place at the time the exception is thrown. Prevents unintended undelimited capture of the current exception handler stack by a delimited "catch". (%start-stack): Similarly, don't be a chain. * module/system/repl/debug.scm (frame->stack-vector): * module/system/repl/error-handling.scm (call-with-error-handling): * module/ice-9/save-stack.scm (save-stack): Adapt to %stacks not being a chain. * test-suite/tests/exceptions.test ("delimited exception handlers"): Add tests. * doc/ref/api-control.texi (Fluids and Dynamic States): Add docs.
This commit is contained in:
parent
81e9a128c1
commit
498f3f9568
12 changed files with 219 additions and 65 deletions
|
@ -504,6 +504,55 @@ scm_dynstack_find_prompt (scm_t_dynstack *dynstack, SCM key,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_dynstack_find_old_fluid_value (scm_t_dynstack *dynstack, SCM fluid,
|
||||
size_t depth, SCM dflt)
|
||||
{
|
||||
scm_t_bits *walk;
|
||||
|
||||
for (walk = SCM_DYNSTACK_PREV (dynstack->top); walk;
|
||||
walk = SCM_DYNSTACK_PREV (walk))
|
||||
{
|
||||
scm_t_bits tag = SCM_DYNSTACK_TAG (walk);
|
||||
|
||||
switch (SCM_DYNSTACK_TAG_TYPE (tag))
|
||||
{
|
||||
case SCM_DYNSTACK_TYPE_WITH_FLUID:
|
||||
{
|
||||
if (scm_is_eq (WITH_FLUID_FLUID (walk), fluid))
|
||||
{
|
||||
if (depth == 0)
|
||||
return SCM_VARIABLE_REF (WITH_FLUID_VALUE_BOX (walk));
|
||||
else
|
||||
depth--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCM_DYNSTACK_TYPE_DYNAMIC_STATE:
|
||||
{
|
||||
SCM state, val;
|
||||
|
||||
/* The previous dynamic state may or may not have
|
||||
established a binding for this fluid. */
|
||||
state = scm_variable_ref (DYNAMIC_STATE_STATE_BOX (walk));
|
||||
val = scm_dynamic_state_ref (state, fluid, SCM_UNDEFINED);
|
||||
if (!SCM_UNBNDP (val))
|
||||
{
|
||||
if (depth == 0)
|
||||
return val;
|
||||
else
|
||||
depth--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return dflt;
|
||||
}
|
||||
|
||||
void
|
||||
scm_dynstack_wind_prompt (scm_t_dynstack *dynstack, scm_t_bits *item,
|
||||
scm_t_ptrdiff reloc, scm_i_jmp_buf *registers)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue