summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-09-03 07:28:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-09-03 07:28:46 -0700
commite5d7d45d81f1529886867e4331c73b8d64df3463 (patch)
tree60f9cc1c6f97f3ec0a305244fbc847f4d25f18f6 /eval.c
parente55cc6a24144875732b16ff526ed7b6faea7c67a (diff)
downloadtxr-e5d7d45d81f1529886867e4331c73b8d64df3463.tar.gz
txr-e5d7d45d81f1529886867e4331c73b8d64df3463.tar.bz2
txr-e5d7d45d81f1529886867e4331c73b8d64df3463.zip
load: scope change for load hooks.
* eval.c (run_load_hooks): Install the given environment as dyn_env temporarily, and don't restore it until after calling the hooks. Thus the specified environment is now in effect when running the hooks. Also, pass nil to lookup_var, in the spirit of the previous commit. The fact that load_dyn_env had to be passed to lookup_var previously, which is an anti-pattern, tells us that this scoping rule was a code smell. If the *load-hooks* value comes from a given dynamic environment, then those functions should be executed in exactly that environment. * txr.1: Documentation updated.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/eval.c b/eval.c
index e1580641..3dbbbf03 100644
--- a/eval.c
+++ b/eval.c
@@ -4600,7 +4600,8 @@ static val me_pop_after_load(val form, val menv)
void run_load_hooks(val load_dyn_env)
{
- val hooks_binding = lookup_var(load_dyn_env, load_hooks_s);
+ val saved_de = set_dyn_env(load_dyn_env);
+ val hooks_binding = lookup_var(nil, load_hooks_s);
val hooks = cdr(hooks_binding);
if (hooks) {
@@ -4608,6 +4609,8 @@ void run_load_hooks(val load_dyn_env)
funcall(car(hooks));
rplacd(hooks_binding, nil);
}
+
+ set_dyn_env(saved_de);
}
static void run_load_hooks_atexit(void)