diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-26 06:50:00 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-26 06:50:00 -0700 |
commit | bdf889cb57c44254ea0f2d3b7a06aac3b77b5edb (patch) | |
tree | 648061499ae52fec7f5ee63db449bc487f8e56be /eval.c | |
parent | 3d894ee5b065483f749eb7d174daf0d242c54404 (diff) | |
download | txr-bdf889cb57c44254ea0f2d3b7a06aac3b77b5edb.tar.gz txr-bdf889cb57c44254ea0f2d3b7a06aac3b77b5edb.tar.bz2 txr-bdf889cb57c44254ea0f2d3b7a06aac3b77b5edb.zip |
func-get-name: fix bogus return for nil argument.
* eval.c (func_get_name): when func_get_name has a nil
function argument and nil env, it falls back on method_name,
which naively searches its space and finds some static slots
with a nil value which is then returned as a method name.
Let's put in a type check that the argument must be a
function. Also, let's drop the recursion in the nested
environment search and switch to iteration, so we don't do
these wasteful sanity checks on multiple re-entries of the
function.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -571,22 +571,27 @@ val lookup_fun(val env, val sym) val func_get_name(val fun, val env) { + val self = lit("func-get-name"); env = default_null_arg(env); + type_check(self, fun, FUN); + if (env) { - type_check(lit("func-get-name"), env, ENV); + type_check(self, env, ENV); { val iter; - for (iter = env->e.fbindings; iter; iter = cdr(iter)) { - val binding = car(iter); - if (cdr(binding) == fun) - return car(binding); + for (; env; env = env->e.up_env) { + for (iter = env->e.fbindings; iter; iter = cdr(iter)) { + val binding = car(iter); + if (cdr(binding) == fun) + return car(binding); + } } - - return func_get_name(fun, env->e.up_env); } - } else { + } + + { val name; if ((name = hash_revget(top_fb, fun, eq_f, cdr_f))) @@ -600,9 +605,9 @@ val func_get_name(val fun, val env) if (interp_fun_p(fun)) return func_get_form(fun); - - return nil; } + + return nil; } static val lookup_mac(val menv, val sym) |