about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-01-21 16:28:40 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-01-21 16:28:40 +0000
commit7c109429799172a7bd606593ecf58b8d49b5790f (patch)
tree7e686d6fde42a876adf503992d5ed4b7fb6aa703 /Src
parentefb93ed6a697d24ac2340b7c10f6ec86ee48d1e2 (diff)
downloadzsh-7c109429799172a7bd606593ecf58b8d49b5790f.tar.gz
zsh-7c109429799172a7bd606593ecf58b8d49b5790f.tar.xz
zsh-7c109429799172a7bd606593ecf58b8d49b5790f.zip
zsh-workers/9401
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/parameter.c44
-rw-r--r--Src/exec.c12
-rw-r--r--Src/zsh.h8
3 files changed, 26 insertions, 38 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 219ad5098..be8b8ad75 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -555,42 +555,25 @@ scanpmdisfunctions(HashTable ht, ScanFunc func, int flags)
 
 /* Functions for the funcstack special parameter. */
 
-static LinkList funcstack;
-
 /**/
 static char **
 funcstackgetfn(Param pm)
 {
+    Funcstack f;
+    int num;
     char **ret, **p;
-    LinkNode node;
 
-    ret = (char **) zhalloc((countlinknodes(funcstack) + 1) * sizeof(char *));
+    for (f = funcstack, num = 0; f; f = f->prev, num++);
+
+    ret = (char **) zhalloc((num + 1) * sizeof(char *));
 
-    for (node = firstnode(funcstack), p = ret; node; incnode(node), p++)
-	*p = (char *) getdata(node);
+    for (f = funcstack, p = ret; f; f = f->prev, p++)
+	*p = f->name;
     *p = NULL;
 
     return ret;
 }
 
-/**/
-static int
-func_wrapper(Eprog prog, FuncWrap w, char *name)
-{
-    PERMALLOC {
-	pushnode(funcstack, ztrdup(name));
-    } LASTALLOC;
-
-    runshfunc(prog, w, name);
-
-    DPUTS(strcmp(name, (char *) getdata(firstnode(funcstack))),
-	  "funcstack wrapper with wrong function");
-
-    zsfree((char *) remnode(funcstack, firstnode(funcstack)));
-
-    return 0;
-}
-
 /* Functions for the builtins special parameter. */
 
 /**/
@@ -1937,10 +1920,6 @@ static struct pardef partab[] = {
     { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
 };
 
-static struct funcwrap wrapper[] = {
-    WRAPDEF(func_wrapper),
-};
-
 /**/
 int
 setup_(Module m)
@@ -1980,12 +1959,6 @@ boot_(Module m)
 	    def->pm->unsetfn = def->unsetfn;
 	}
     }
-    PERMALLOC {
-	funcstack = newlinklist();
-    } LASTALLOC;
-
-    addwrapper(m, wrapper);
-
     return 0;
 }
 
@@ -2005,9 +1978,6 @@ cleanup_(Module m)
 	    unsetparam_pm(pm, 0, 1);
 	}
     }
-    deletewrapper(m, wrapper);
-    freelinklist(funcstack, freestr);
-
     return 0;
 }
 
diff --git a/Src/exec.c b/Src/exec.c
index 6310d5431..6c7892318 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -124,6 +124,11 @@ mod_export int sfcontext;
 /**/
 struct execstack *exstack;
 
+/* Stack with names of functions currently active. */
+
+/**/
+mod_export Funcstack funcstack;
+
 #define execerr() if (!forked) { lastval = 1; return; } else _exit(1)
 
 static LinkList args;
@@ -3107,6 +3112,7 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
     int oldzoptind, oldlastval, oldoptcind;
     char saveopts[OPT_SIZE], *oldscriptname;
     int obreaks = breaks;
+    struct funcstack fstack;
 
     HEAPALLOC {
 	pushheap();
@@ -3152,7 +3158,11 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
 		argzero = ztrdup(argzero);
 	    }
 	}
-	runshfunc(prog, wrappers, dupstring(name));
+	fstack.name = dupstring(name);
+	fstack.prev = funcstack;
+	funcstack = &fstack;
+	runshfunc(prog, wrappers, fstack.name);
+	funcstack = fstack.prev;
 	if (retflag) {
 	    retflag = 0;
 	    breaks = obreaks;
diff --git a/Src/zsh.h b/Src/zsh.h
index 7e22269bd..54141d2b7 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -296,6 +296,7 @@ typedef struct param     *Param;
 typedef struct paramdef  *Paramdef;
 typedef struct cmdnam    *Cmdnam;
 typedef struct shfunc    *Shfunc;
+typedef struct funcstack *Funcstack;
 typedef struct funcwrap  *FuncWrap;
 typedef struct builtin   *Builtin;
 typedef struct nameddir  *Nameddir;
@@ -823,6 +824,13 @@ struct shfunc {
 #define SFC_COMPLETE 5		/* called from completion code */
 #define SFC_CWIDGET  6		/* new style completion widget */
 
+/* node in function stack */
+
+struct funcstack {
+    Funcstack prev;		/* previous in stack */
+    char *name;			/* name of function called */
+};
+
 /* node in list of function call wrappers */
 
 typedef int (*WrapFunc) _((Eprog, FuncWrap, char *));