summaryrefslogtreecommitdiff
path: root/libguile/dynstack.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2017-02-07 09:28:39 +0100
committerAndy Wingo <wingo@pobox.com>2017-02-07 09:57:55 +0100
commit498f3f95684361f3591106a8f9cb9065fd649288 (patch)
tree70a8e33d1ea25c54c273a3cbe347010403dfb07c /libguile/dynstack.c
parent81e9a128c146ccd495846ecbf664b3fd2855baf1 (diff)
downloadguile-498f3f95684361f3591106a8f9cb9065fd649288.tar.gz
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.
Diffstat (limited to 'libguile/dynstack.c')
-rw-r--r--libguile/dynstack.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libguile/dynstack.c b/libguile/dynstack.c
index ff57c430d..652d2b35a 100644
--- a/libguile/dynstack.c
+++ b/libguile/dynstack.c
@@ -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)