From 7ca2b06501b463641426d009a54b21b89b8ca9ee Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jan 2020 18:02:33 +0000 Subject: 45304: Do execute the always block even when the try/always block itself is the last command. Fixes the test added in the previous commit (workers/45305). --- Src/loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/loop.c') diff --git a/Src/loop.c b/Src/loop.c index 538afb8dc..57858a150 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -742,7 +742,7 @@ exectry(Estate state, int do_exec) /* The :try clause */ ++try_tryflag; - execlist(state, 1, do_exec); + execlist(state, 1, 0); --try_tryflag; /* Don't record errflag here, may be reset. However, */ -- cgit v1.2.3 From 2a9674862ecaf9b7b1b66178782d47e8445df325 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 26 Mar 2020 20:54:37 +0000 Subject: 45616: Remove token from count argument to repeat --- ChangeLog | 5 +++++ Src/loop.c | 4 +++- Test/A01grammar.ztst | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'Src/loop.c') diff --git a/ChangeLog b/ChangeLog index fea7b0f76..0f4c36dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-03-26 Peter Stephenson + + * 45616: Src/loop.c, Test/A01grammar.ztst: Remove tokens + from count to repeat keyword. + 2020-03-25 Daniel Shahaf * 45583/0008: Etc/BUGS, Src/utils.c, Test/B13whence.ztst: diff --git a/Src/loop.c b/Src/loop.c index 95ef48b33..f13c8c4a9 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -499,8 +499,10 @@ execrepeat(Estate state, UNUSED(int do_exec)) lastval = 0; tmp = ecgetstr(state, EC_DUPTOK, &htok); - if (htok) + if (htok) { singsub(&tmp); + untokenize(tmp); + } count = mathevali(tmp); if (errflag) return 1; diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index 0dbf468f6..35a04e7d5 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -557,6 +557,13 @@ >Hip hip hooray >Hip hip hooray + repeat 2*2 print yeah +0:Tokens in repeat argument +>yeah +>yeah +>yeah +>yeah + case bravo { (alpha) print schmalpha ;; -- cgit v1.2.3 From a2a0293d4f1f488e92b11db7b85f28f294384131 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 23 Mar 2020 04:46:24 +0000 Subject: 47296 (+ unposted additional tests and comments): 'repeat' loops: Let the repeat count use $?. It's an arithmetic expression. --- ChangeLog | 4 ++++ Src/loop.c | 2 +- Test/A05execution.ztst | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'Src/loop.c') diff --git a/ChangeLog b/ChangeLog index 9df308c54..54cc37f67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-08-08 Daniel Shahaf + * 47296 (+ unposted additional tests and comments): Src/loop.c, + Test/A05execution.ztst: 'repeat' loops: Let the repeat count + use $?. + * 47300: Src/parse.c, Src/zsh.h: Document the EC_NODUP, EC_DUP, EC_DUPTOK triplet. diff --git a/Src/loop.c b/Src/loop.c index f13c8c4a9..41b2e5627 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -497,7 +497,6 @@ execrepeat(Estate state, UNUSED(int do_exec)) end = state->pc + WC_REPEAT_SKIP(code); - lastval = 0; tmp = ecgetstr(state, EC_DUPTOK, &htok); if (htok) { singsub(&tmp); @@ -506,6 +505,7 @@ execrepeat(Estate state, UNUSED(int do_exec)) count = mathevali(tmp); if (errflag) return 1; + lastval = 0; /* used when the repeat count is zero */ pushheap(); cmdpush(CS_REPEAT); loops++; diff --git a/Test/A05execution.ztst b/Test/A05execution.ztst index 20a594b68..c65642988 100644 --- a/Test/A05execution.ztst +++ b/Test/A05execution.ztst @@ -401,3 +401,17 @@ F:anonymous function, and a descriptor leak when backgrounding a pipeline (( exit 130 ) | { sleep 1; echo hello }) 0:exit code 130 isn't mistaken for a signal (unit test for workers/46060) >hello + + (exit 3); repeat "$?" echo x + (exit 3); repeat '?' echo y +0:'repeat' loop can use lastval in the count +>x +>x +>x +>y +>y +>y + + (exit 4); repeat 0 do done +0:'repeat 0' resets lastval + -- cgit v1.2.3 From 9e38ab81785c4ac755a7e78d2fe7a7db92bdf375 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 6 May 2021 10:03:27 +0100 Subject: 48787: Fix command status after failed if If "if" had a hard error in the condition, and there was no else clause, the command status was incorrectly cleared to zero. Add test. --- ChangeLog | 5 +++++ Src/loop.c | 2 +- Test/A01grammar.ztst | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'Src/loop.c') diff --git a/ChangeLog b/ChangeLog index 7dc9cbc6d..9392e39d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-05-06 Peter Stephenson + + * 48787: Src/loop.c, Test/A01grammar.ztst: status was incorrect + on hard error flagged by condition in "if" without "else". + 2021-05-03 dana * unposted (see 48613): Etc/FAQ.yo: Move section 3.31 to 2.8 diff --git a/Src/loop.c b/Src/loop.c index 41b2e5627..aa733a2cb 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -583,7 +583,7 @@ execif(Estate state, int do_exec) cmdpop(); } else { noerrexit = olderrexit; - if (!retflag) + if (!retflag && !errflag) lastval = 0; } state->pc = end; diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index 35a04e7d5..88fc8606e 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -939,3 +939,8 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci $ZTST_testdir/../Src/zsh -fc '{ ( ) } always { echo foo }' 0:exec last command optimization inhibited for try/always >foo + + a='${' + if : ${(e)a}; then echo x; fi +1:Status on bad substitution in if without else +?(eval):2: bad substitution -- cgit v1.2.3 From cf5c4828d1cdfd79e369a6b3323466bc961851c4 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 16 May 2021 19:51:11 -0700 Subject: 48857: declare "volatile" all globals that may be modified by signal handlers --- ChangeLog | 6 ++++++ Src/builtin.c | 16 +++++++--------- Src/exec.c | 8 +++++--- Src/loop.c | 2 +- Src/makepro.awk | 2 +- Src/params.c | 6 ++++-- Src/signals.c | 16 ++++++++-------- 7 files changed, 32 insertions(+), 24 deletions(-) (limited to 'Src/loop.c') diff --git a/ChangeLog b/ChangeLog index 6f8520db7..89b469c0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-05-16 Bart Schaefer + + * 48857: Src/builtin.c, Src/exec.c, Src/loop.c, Src/makepro.awk, + Src/params.c, Src/signals.c: declare as "volatile" all globals + that may be modified by signal handlers; recognize in makepro.awk + 2021-05-16 Oliver Kiddle * Jörg Sommer: users/26649: Completion/Unix/Command/_rake: diff --git a/Src/builtin.c b/Src/builtin.c index a29eb49e4..a16fddcb7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5635,13 +5635,16 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun */ /**/ -mod_export int -exit_pending; +mod_export volatile int exit_pending; /* Shell level at which we exit if exit_pending */ /**/ -mod_export int -exit_level; +mod_export volatile int exit_level; + +/* we have printed a 'you have stopped (running) jobs.' message */ + +/**/ +mod_export volatile int stopmsg; /* break, bye, continue, exit, logout, return -- most of these take * * one numeric argument, and the other (logout) is related to return. * @@ -5733,11 +5736,6 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func) return 0; } -/* we have printed a 'you have stopped (running) jobs.' message */ - -/**/ -mod_export int stopmsg; - /* check to see if user has jobs running/stopped */ /**/ diff --git a/Src/exec.c b/Src/exec.c index 6f09e0d9f..49ff88b80 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -84,7 +84,7 @@ int nohistsave; /* error flag: bits from enum errflag_bits */ /**/ -mod_export int errflag; +mod_export volatile int errflag; /* * State of trap return value. Value is from enum trap_state. @@ -122,7 +122,7 @@ int subsh; /* != 0 if we have a return pending */ /**/ -mod_export int retflag; +mod_export volatile int retflag; /**/ long lastval2; @@ -1268,7 +1268,9 @@ execsimple(Estate state) } else { int q = queue_signal_level(); dont_queue_signals(); - if (code == WC_FUNCDEF) + if (errflag) + lv = errflag; + else if (code == WC_FUNCDEF) lv = execfuncdef(state, NULL); else lv = (execfuncs[code - WC_CURSH])(state, 0); diff --git a/Src/loop.c b/Src/loop.c index aa733a2cb..db5b3e097 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -43,7 +43,7 @@ mod_export int contflag; /* # of break levels */ /**/ -mod_export int breaks; +mod_export volatile int breaks; /**/ int diff --git a/Src/makepro.awk b/Src/makepro.awk index 226d3f96b..f69660531 100644 --- a/Src/makepro.awk +++ b/Src/makepro.awk @@ -79,7 +79,7 @@ BEGIN { break } sub(/^ */, "", line) - match(line, /^((const|enum|mod_export|static|struct|union) +)*([_0-9A-Za-z]+ +|((char|double|float|int|long|short|unsigned|void) +)+)((const|static) +)*/) + match(line, /^((const|enum|mod_export|static|struct|union|volatile) +)*([_0-9A-Za-z]+ +|((char|double|float|int|long|short|unsigned|void) +)+)((const|static) +)*/) dtype = substr(line, 1, RLENGTH) sub(/ *$/, "", dtype) if(" " dtype " " ~ / static /) diff --git a/Src/params.c b/Src/params.c index 20dfb5b5f..4f6b361f9 100644 --- a/Src/params.c +++ b/Src/params.c @@ -98,8 +98,10 @@ char *ifs, /* $IFS */ *pwd; /* $PWD */ /**/ -mod_export -zlong lastval, /* $? */ +mod_export volatile zlong + lastval; /* $? */ +/**/ +mod_export zlong mypid, /* $$ */ lastpid, /* $! */ zterm_columns, /* $COLUMNS */ diff --git a/Src/signals.c b/Src/signals.c index 4adf03202..2c540f38f 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -53,7 +53,7 @@ mod_export Eprog siglists[VSIGCOUNT]; /* Total count of trapped signals */ /**/ -mod_export int nsigtrapped; +mod_export volatile int nsigtrapped; /* Running an exit trap? */ @@ -72,20 +72,20 @@ static int exit_trap_posix; /* Variables used by signal queueing */ /**/ -mod_export int queueing_enabled, queue_front, queue_rear; +mod_export volatile int queueing_enabled, queue_front, queue_rear; /**/ mod_export int signal_queue[MAX_QUEUE_SIZE]; /**/ mod_export sigset_t signal_mask_queue[MAX_QUEUE_SIZE]; #ifdef DEBUG /**/ -mod_export int queue_in; +mod_export volatile int queue_in; #endif /* Variables used by trap queueing */ /**/ -mod_export int trap_queueing_enabled, trap_queue_front, trap_queue_rear; +mod_export volatile int trap_queueing_enabled, trap_queue_front, trap_queue_rear; /**/ mod_export int trap_queue[MAX_QUEUE_SIZE]; @@ -672,9 +672,9 @@ zhandler(int sig) if ((isset(PRIVILEGED) || isset(RESTRICTED)) && isset(INTERACTIVE) && (noerrexit & NOERREXIT_SIGNAL)) zexit(SIGINT, ZEXIT_SIGNAL); + errflag |= ERRFLAG_INT; if (list_pipe || chline || simple_pline) { breaks = loops; - errflag |= ERRFLAG_INT; inerrflush(); check_cursh_sig(SIGINT); } @@ -1266,19 +1266,19 @@ unqueue_traps(void) /* Are we already executing a trap? */ /**/ -int intrap; +volatile int intrap; /* Is the current trap a function? */ /**/ -int trapisfunc; +volatile int trapisfunc; /* * If the current trap is not a function, at what function depth * did the trap get called? */ /**/ -int traplocallevel; +volatile int traplocallevel; /* * sig is the signal number. -- cgit v1.2.3