summaryrefslogtreecommitdiff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-01-25 16:23:16 +0000
committerPeter Stephenson <pws@zsh.org>2016-01-25 16:23:16 +0000
commit7c59c953f28026559325473ba53be0dd3a661109 (patch)
treee0eceda45c1f9a7dbfecad87883c9c93ccdaa0db /Src/builtin.c
parentbe32864e6ff6a872d63314b4baedbfbf2eed54bd (diff)
downloadzsh-7c59c953f28026559325473ba53be0dd3a661109.tar.gz
zsh-7c59c953f28026559325473ba53be0dd3a661109.zip
37765: Use FS_FUNC on fucstack to find autoload -X target.
This is better than scriptname which can be updated due to e.g. intervening "eval".
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 98ecb09e8..63f964d3d 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3142,15 +3142,33 @@ bin_functions(char *name, char **argv, Options ops, int func)
queue_signals();
if (OPT_MINUS(ops,'X')) {
- if ((shf = (Shfunc) shfunctab->getnode(shfunctab, scriptname))) {
- DPUTS(!shf->funcdef,
- "BUG: Calling autoload from empty function");
+ Funcstack fs;
+ char *funcname = NULL;
+ for (fs = funcstack; fs; fs = fs->prev) {
+ if (fs->tp == FS_FUNC) {
+ /*
+ * dupstring here is paranoia but unlikely to be
+ * problematic
+ */
+ funcname = dupstring(fs->name);
+ break;
+ }
+ }
+ if (!funcname)
+ {
+ zerrnam(name, "bad autoload");
+ ret = 1;
} else {
- shf = (Shfunc) zshcalloc(sizeof *shf);
- shfunctab->addnode(shfunctab, ztrdup(scriptname), shf);
+ if ((shf = (Shfunc) shfunctab->getnode(shfunctab, funcname))) {
+ DPUTS(!shf->funcdef,
+ "BUG: Calling autoload from empty function");
+ } else {
+ shf = (Shfunc) zshcalloc(sizeof *shf);
+ shfunctab->addnode(shfunctab, ztrdup(funcname), shf);
+ }
+ shf->node.flags = on;
+ ret = eval_autoload(shf, funcname, ops, func);
}
- shf->node.flags = on;
- ret = eval_autoload(shf, scriptname, ops, func);
} else {
if (OPT_ISSET(ops,'U') && !OPT_ISSET(ops,'u'))
on &= ~PM_UNDEFINED;