summaryrefslogtreecommitdiff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@ipost.com>2021-09-06 14:00:36 -0700
committerBart Schaefer <schaefer@ipost.com>2021-09-06 14:02:20 -0700
commit988688d23d44bd83b292e2ae61293214bd259862 (patch)
treec089dcaef4dbcbecd95034b03b38b6a6c89742e2 /Src/utils.c
parentd165d408a088a432cae04b86c5bc312de3cc3acb (diff)
downloadzsh-988688d23d44bd83b292e2ae61293214bd259862.tar.gz
zsh-988688d23d44bd83b292e2ae61293214bd259862.zip
49282: set $0 correctly when calling functions from hooks
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Src/utils.c b/Src/utils.c
index 5a9222919..c32741ca7 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1498,7 +1498,7 @@ time_t lastwatch;
/*
* Call a function given by "name" with optional arguments
- * "lnklist". If these are present the first argument is the function name.
+ * "lnklst". If these are present the first argument is the function name.
*
* If "arrayp" is not zero, we also look through
* the array "name"_functions and execute functions found there.
@@ -1527,6 +1527,10 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval)
incompfunc = 0;
if ((shfunc = getshfunc(name))) {
+ if (!lnklst) {
+ lnklst = newlinklist();
+ addlinknode(lnklst, name);
+ }
ret = doshfunc(shfunc, lnklst, 1);
stat = 0;
}
@@ -1539,10 +1543,16 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval)
memcpy(arrnam + namlen, HOOK_SUFFIX, HOOK_SUFFIX_LEN);
if ((arrptr = getaparam(arrnam))) {
+ char **argarr = lnklst ? hlinklist2array(lnklst, 0) : NULL;
arrptr = arrdup(arrptr);
for (; *arrptr; arrptr++) {
if ((shfunc = getshfunc(*arrptr))) {
- int newret = doshfunc(shfunc, lnklst, 1);
+ int newret, i = 1;
+ LinkList arg0 = newlinklist();
+ addlinknode(arg0, *arrptr);
+ while (argarr && argarr[i])
+ addlinknode(arg0, argarr[i++]);
+ newret = doshfunc(shfunc, arg0, 1);
if (!ret)
ret = newret;
stat = 0;