mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-20 06:56:05 +02:00
users/20203: nested functions in always blocks when exit pending
This commit is contained in:
parent
9c3aeef99a
commit
ec57c91b58
|
@ -1,3 +1,8 @@
|
|||
2015-05-13 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* users/20203: Src/builtin., Src/exec.c, Test/A01grammar.ztst:
|
||||
nested function in always traps after exit didn't work.
|
||||
|
||||
2015-05-12 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||
|
||||
* 35086: Doc/Zsh/expn.yo: reapply 35067 (with 35071) which
|
||||
|
|
|
@ -4788,6 +4788,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
|
|||
mod_export int
|
||||
exit_pending;
|
||||
|
||||
/* Shell level at which we exit if exit_pending */
|
||||
/**/
|
||||
mod_export int
|
||||
exit_level;
|
||||
|
||||
/* break, bye, continue, exit, logout, return -- most of these take *
|
||||
* one numeric argument, and the other (logout) is related to return. *
|
||||
* (return is treated as a logout when in a login shell.) */
|
||||
|
@ -4865,6 +4870,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
|
|||
retflag = 1;
|
||||
breaks = loops;
|
||||
exit_pending = (num << 1) | 1;
|
||||
exit_level = locallevel;
|
||||
}
|
||||
} else
|
||||
zexit(num, 0);
|
||||
|
|
10
Src/exec.c
10
Src/exec.c
|
@ -5101,7 +5101,15 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
|
|||
}
|
||||
popheap();
|
||||
|
||||
if (exit_pending) {
|
||||
/*
|
||||
* Exit with a tidy up.
|
||||
* Only leave if we're at the end of the appropriate function ---
|
||||
* not a nested function. As we usually skip the function body,
|
||||
* the only likely case where we need that second test is
|
||||
* when we have an "always" block. The endparamscope() has
|
||||
* already happened, hence the "+1" here.
|
||||
*/
|
||||
if (exit_pending && exit_level == locallevel+1) {
|
||||
if (locallevel > forklevel) {
|
||||
/* Still functions to return: force them to do so. */
|
||||
retflag = 1;
|
||||
|
|
|
@ -589,3 +589,25 @@
|
|||
>success2
|
||||
>read it
|
||||
>read it
|
||||
|
||||
(
|
||||
mywrap() { echo BEGIN; true; echo END }
|
||||
mytest() { { exit 3 } always { mywrap }; print Exited before this }
|
||||
mytest
|
||||
print Exited before this, too
|
||||
)
|
||||
3:Exit and always block with functions: simple
|
||||
>BEGIN
|
||||
>END
|
||||
|
||||
(
|
||||
mytrue() { echo mytrue; return 0 }
|
||||
mywrap() { echo BEGIN; mytrue; echo END }
|
||||
mytest() { { exit 4 } always { mywrap }; print Exited before this }
|
||||
mytest
|
||||
print Exited before this, too
|
||||
)
|
||||
4:Exit and always block with functions: nested
|
||||
>BEGIN
|
||||
>mytrue
|
||||
>END
|
||||
|
|
Loading…
Reference in New Issue