Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $pipestatus broken



Oliver Kiddle wrote:
> As it happens, I don't have a precmd function defined. Peter's patch
> didn't help: it seems the problem for my setup is down to zle widgets. In
> particular, I have one defined for the enter key as a wrapper around
> accept-line. $status seems unaffected so it looks like we need to be
> saving pipestats somewhere else too.

Is this any good?  I haven't properly tested it since you're more in a
position to see if it fixes things.

The widget code wasn't using the save-return-values facilities of
doshfunc because it wanted the status.  I've made doshfunc pass that
back separately.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.55
diff -u -r1.55 exec.c
--- Src/exec.c	3 Nov 2003 11:33:46 -0000	1.55
+++ Src/exec.c	3 Nov 2003 13:01:25 -0000
@@ -3436,17 +3436,22 @@
     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, oldnumpipestats;
+    int oldzoptind, oldlastval, oldoptcind, oldnumpipestats, ret;
     int *oldpipestats = NULL;
     char saveopts[OPT_SIZE], *oldscriptname = scriptname, *fname = dupstring(name);
     int obreaks;
@@ -3577,6 +3582,7 @@
 
     if (trapreturn < -1)
 	trapreturn++;
+    ret = lastval;
     if (noreturnval) {
 	lastval = oldlastval;
 	numpipestats = oldnumpipestats;
@@ -3599,6 +3605,8 @@
 	    zexit(exit_pending >> 1, 0);
 	}
     }
+
+    return ret;
 }
 
 /* This finally executes a shell function and any function wrappers     *
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.36
diff -u -r1.36 zle_main.c
--- Src/Zle/zle_main.c	29 Oct 2003 19:17:48 -0000	1.36
+++ Src/Zle/zle_main.c	3 Nov 2003 13:01:25 -0000
@@ -910,7 +910,7 @@
 	    zsfree(msg);
 	    ret = 1;
 	} else {
-	    int osc = sfcontext, osi = movefd(0), olv = lastval;
+	    int osc = sfcontext, osi = movefd(0);
 	    int oxt = isset(XTRACE);
 	    LinkList largs = NULL;
 
@@ -924,10 +924,8 @@
 	    makezleparams(0);
 	    sfcontext = SFC_WIDGET;
 	    opts[XTRACE] = 0;
-	    doshfunc(w->u.fnnam, prog, largs, shf->flags, 0);
+	    ret = doshfunc(w->u.fnnam, prog, largs, shf->flags, 1);
 	    opts[XTRACE] = oxt;
-	    ret = lastval;
-	    lastval = olv;
 	    sfcontext = osc;
 	    endparamscope();
 	    lastcmd = 0;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author