diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2003-11-03 13:59:07 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2003-11-03 13:59:07 +0000 |
commit | e78648891926d9efb9e06fed253120c6ec2e6bb8 (patch) | |
tree | de2966852c103954b8d764b9ba16d82aed01cb9d /Src/exec.c | |
parent | 40dcdf68a2368b0e889a6be5d7b6323101fcbe9f (diff) | |
download | zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.gz zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.xz zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.zip |
19216: save and restore $pipestatus.
19218: extend 19216 to zle widgets
Diffstat (limited to 'Src/exec.c')
-rw-r--r-- | Src/exec.c | 36 |
1 files changed, 29 insertions, 7 deletions
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 * |