Skip to content

Commit

Permalink
Don't negate exit status of return (#46224)
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/yash/yash/trunk@4223 048f04df-13f5-43d7-8114-9f9ceecaec24
  • Loading branch information
magicant committed Dec 9, 2022
1 parent 7241b5e commit ba43abb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Yash 2.54 (Unreleased)
when the operand names a symbolic link to a non-existing file.
* The exported value of the $DIRSTACK variable was not being
updated correctly in the "pushd" and "popd" built-ins.
* The effect of "!" no longer applies to the exit status of the
"break", "continue", and "return" built-ins.

----------------------------------------------------------------------
Yash 2.53 (2022-08-23)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.ja
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Yash 2.54 (未リリース)
リンクを ">" リダイレクトで開こうとすると無限ループしていた
* $DIRSTACK 変数がエクスポートされているとき、"pushd" および "popd"
組込みで $DIRSTACK 変数の値が正しく更新されていなかった
* "break", "continue", "return" 組込みの終了ステータスが "!" で反転
されていた

----------------------------------------------------------------------
Yash 2.53 (2022-08-23)
Expand Down
12 changes: 7 additions & 5 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ void exec_and_or_lists(const and_or_T *a, bool finally_exit)
/* Executes the pipelines. */
void exec_pipelines(const pipeline_T *p, bool finally_exit)
{
for (bool first = true;
p != NULL && !need_break();
p = p->next, first = false) {
for (bool first = true; p != NULL; p = p->next, first = false) {
if (!first && p->pl_cond == (laststatus != Exit_SUCCESS))
continue;

Expand All @@ -335,14 +333,18 @@ void exec_pipelines(const pipeline_T *p, bool finally_exit)

bool self = finally_exit && !p->next && !p->pl_neg;
exec_commands(p->pl_commands, self ? E_SELF : E_NORMAL);

suppresserrexit = savesee, suppresserrreturn = saveser;

if (need_break())
break;

if (p->pl_neg) {
if (laststatus == Exit_SUCCESS)
laststatus = Exit_FAILURE;
else
laststatus = Exit_SUCCESS;
}

suppresserrexit = savesee, suppresserrreturn = saveser;
}
if (finally_exit)
exit_shell();
Expand Down
5 changes: 5 additions & 0 deletions tests/pipeline-y.tst
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# pipeline-y.tst: yash-specific test of pipeline

test_OE -e 42 '! with return'
f() { ! return 42; }
f
__IN__

test_Oe -e 2 'no command before |'
| echo foo
__IN__
Expand Down

0 comments on commit ba43abb

Please sign in to comment.