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

Re: 'while do done' hangs interactive zsh



On Sun, May 16, 2021 at 11:25 AM Martijn Dekker <martijn@xxxxxxxx> wrote:
>
> Op 16-05-21 om 19:47 schreef Bart Schaefer:
> > Let's try the attached, then?
>
> Interactive zsh with that patch still locks up on 'while do done'

So this is MacOS:

% TRAPINT() { print Got INT }
% while do done
^CGot INT
^CGot INT
^CGot INT
^CGot INT
^CGot INT

That's exactly what also happens on Ubuntu.  But if I change that to:

% TRAPINT() { print Got INT; break }

Then on Ubuntu a ^C stops the loop, but on MacOS it does not.  This
implies that the value of the global "breaks" is not propagating into
execwhile() when set from the signal handler.  This may be an
optimization problem with clang?   Some random fiddling indicates that
the value of "errflag" may not be propagating out of the signal
handler either.

Indeed, this seems to fix it for MacOS:

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

Do we need to worry about compilers that don't accept "volatile"?  I'd
suggest throwing "volatile" into the computed definition of
"mod_export" except I've forgotten whether there is such a thing as
declaring a function to be volatile.




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