about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-11-03 13:59:07 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-11-03 13:59:07 +0000
commite78648891926d9efb9e06fed253120c6ec2e6bb8 (patch)
treede2966852c103954b8d764b9ba16d82aed01cb9d
parent40dcdf68a2368b0e889a6be5d7b6323101fcbe9f (diff)
downloadzsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.gz
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.xz
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.zip
19216: save and restore $pipestatus.
19218: extend 19216 to zle widgets
-rw-r--r--ChangeLog8
-rw-r--r--Src/Zle/zle_main.c6
-rw-r--r--Src/exec.c36
3 files changed, 39 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 958b52f19..4d82c0ae6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-11-03  Peter Stephenson  <pws@csr.com>
+
+	* 19218: Src/exec.c, Src/Zle/zle_main.c: extend 19216 to
+	fix similar probably when calling zle widgets.
+
+	* 19216: Src/exec.c: save and restore $pipestatus on functions
+	when noreturnval flag is set.  Remove unnecessary debugging output.
+
 2003-10-28  Peter Stephenson  <pws@csr.com>
 
 	* 19209: Src/builtin.c, Src/exec.c, Src/hashtable.c, Src/hist.c,
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 6156b40d0..c5225ccdb 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -684,7 +684,7 @@ execzlefunc(Thingy func, char **args)
 	    zsfree(msg);
 	    ret = 1;
 	} else {
-	    int osc = sfcontext, osi = movefd(0), olv = lastval;
+	    int osc = sfcontext, osi = movefd(0);
 	    LinkList largs = NULL;
 
 	    if (*args) {
@@ -696,9 +696,7 @@ execzlefunc(Thingy func, char **args)
 	    startparamscope();
 	    makezleparams(0);
 	    sfcontext = SFC_WIDGET;
-	    doshfunc(w->u.fnnam, prog, largs, 0, 0);
-	    ret = lastval;
-	    lastval = olv;
+	    ret = doshfunc(w->u.fnnam, prog, largs, 0, 1);
 	    sfcontext = osc;
 	    endparamscope();
 	    lastcmd = 0;
diff --git a/Src/exec.c b/Src/exec.c
index 81c6ac641..77b657c18 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3310,17 +3310,23 @@ loadautofn(Shfunc shf, int fksh, int autol)
     return shf;
 }
 
-/* execute a shell function */
+/*
+ * execute a shell function
+ *
+ * If noreturnval is nonzero, then reset the current return
+ * value (lastval) to its value before the shell function
+ * was executed.  However, in any case return the status value
+ * from the function (i.e. if noreturnval is not set, this
+ * will be the same as lastval).
+ */
 
 /**/
-mod_export void
+mod_export int
 doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
-/* If noreturnval is nonzero, then reset the current return *
- * value (lastval) to its value before the shell function   *
- * was executed.                                            */
 {
     char **tab, **x, *oargv0;
-    int oldzoptind, oldlastval, oldoptcind;
+    int oldzoptind, oldlastval, oldoptcind, oldnumpipestats, ret;
+    int *oldpipestats = NULL;
     char saveopts[OPT_SIZE], *oldscriptname = scriptname, *fname = dupstring(name);
     int obreaks;
     struct funcstack fstack;
@@ -3335,6 +3341,16 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
     if (trapreturn < 0)
 	trapreturn--;
     oldlastval = lastval;
+    oldnumpipestats = numpipestats;
+    if (noreturnval) {
+	/*
+	 * Easiest to use the heap here since we're bracketed
+	 * immediately by a pushheap/popheap pair.
+	 */
+	size_t bytes = sizeof(int)*numpipestats;
+	oldpipestats = (int *)zhalloc(bytes);
+	memcpy(oldpipestats, pipestats, bytes);
+    }
 
     starttrapscope();
 
@@ -3440,9 +3456,15 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
 
     if (trapreturn < -1)
 	trapreturn++;
-    if (noreturnval)
+    ret = lastval;
+    if (noreturnval) {
 	lastval = oldlastval;
+	numpipestats = oldnumpipestats;
+	memcpy(pipestats, oldpipestats, sizeof(int)*numpipestats);
+    }
     popheap();
+
+    return ret;
 }
 
 /* This finally executes a shell function and any function wrappers     *