about summary refs log tree commit diff
path: root/Src/init.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-11-08 10:38:05 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-11-08 10:38:05 +0000
commitaba936b17cca86ee0742341f23f0f96795a23275 (patch)
tree9ddbe362d29bf5ca63ba0808e06efb7388b2e38f /Src/init.c
parentf367a90505811cf2125549e4d376c33f691bde57 (diff)
downloadzsh-aba936b17cca86ee0742341f23f0f96795a23275.tar.gz
zsh-aba936b17cca86ee0742341f23f0f96795a23275.tar.xz
zsh-aba936b17cca86ee0742341f23f0f96795a23275.zip
22981: Zvi Har'el: bad call from 22952
22980: add hook array for special functions
Diffstat (limited to 'Src/init.c')
-rw-r--r--Src/init.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/Src/init.c b/Src/init.c
index 7645af6b2..fad36bf0f 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -137,29 +137,33 @@ loop(int toplevel, int justonce)
 	}
 	if (hend(prog)) {
 	    int toksav = tok;
-	    Eprog preprog;
 
-	    if (toplevel && (preprog = getshfunc("preexec")) != &dummy_eprog) {
+	    if (toplevel &&
+		(getshfunc("preexec") != &dummy_eprog ||
+		 paramtab->getnode(paramtab, "preexec_functions"))) {
 		LinkList args;
-		int osc = sfcontext;
 		char *cmdstr;
 
-		args = znewlinklist();
-		zaddlinknode(args, "preexec");
+		/*
+		 * As we're about to freeheap() or popheap()
+		 * anyway, there's no gain in using permanent
+		 * storage here.
+		 */
+		args = newlinklist();
+		addlinknode(args, "preexec");
 		/* If curline got dumped from the history, we don't know
 		 * what the user typed. */
 		if (hist_ring && curline.histnum == curhist)
-		    zaddlinknode(args, hist_ring->node.nam);
+		    addlinknode(args, hist_ring->node.nam);
 		else
-		    zaddlinknode(args, "");
-		zaddlinknode(args, getjobtext(prog, NULL));
-		zaddlinknode(args, cmdstr = getpermtext(prog, NULL));
+		    addlinknode(args, "");
+		addlinknode(args, dupstring(getjobtext(prog, NULL)));
+		addlinknode(args, cmdstr = getpermtext(prog, NULL));
+
+		callhookfunc("preexec", args, 1);
 
-		sfcontext = SFC_HOOK;
-		doshfunc("preexec", preprog, args, 0, 1);
-		sfcontext = osc;
+		/* The only permanent storage is from getpermtext() */
 		zsfree(cmdstr);
-		freelinklist(args, (FreeFunc) NULL);
 		errflag = 0;
 	    }
 	    if (stopmsg)	/* unset 'you have stopped jobs' flag */