zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: Re: Interrupting globs (Re: Something rotten in tar completion)
Date: Sun, 7 Dec 2014 20:20:02 +0000	[thread overview]
Message-ID: <20141207202002.29def040@pws-pc.ntlworld.com> (raw)
In-Reply-To: <201412071859.sB7Ix5Xq005917@pws-pc.ntlworld.com>

On Sun, 07 Dec 2014 18:59:04 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> > In particular with respect to always-blocks, there should be some way
> > for TRY_BLOCK_ERROR to clear interrupts as well as (maybe even instead
> > of?  TRY_BLOCK_INTERRUPT?) internal errors.  A trap that returns zero
> > only clears interrupt if there isn't another trap in a deeper scope.
> 
> Yes, probably.  I realised we'd better not do that with bits in the shell
> code as the documentation suggests setting TRY_BLOCK_ERROR to 0 clears
> errors.  We'd want clearing interrupts to be a separate explicit action.

I think this is a mechanical addition of a parallel variable, in as much
as anything is mechanical here...  Not entirely sure when we'd want to
use it, but it would get us out of jail free if the new interrupt_abort
code is riding roughshod over some shell code where we need to ensure
the state gets fully restored, so is probably worth having.

I suppose, theoretically, this means we can fix up any problems in the
new C code within shell code.  (It's now a decade and a half since I
gave up theoretical physics, but I still interpret the word
"theoretically" as meaning "I get paid to do this whatever happens in
the real world".  As I don't get paid to do this, the meaning is even
stronger.)

pws


diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 5833d6b..8da0c64 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -754,6 +754,14 @@ It may be reset, clearing the error condition.  See
 ifzman(em(Complex Commands) in zmanref(zshmisc))\
 ifnzman(noderef(Complex Commands))
 )
+vinde(TRY_BLOCK_INTERRUPT)
+item(tt(TRY_BLOCK_INTERRUPT) <S>)(
+This variable works in a similar way to tt(TRY_BLOCK_ERROR), but
+represents the status of an interrupt from the keyboard, typically
+by the user typing tt(^C).  If set to 0, any such interrupt will
+be reset; otherwise, the interrupt is propagated after the tt(always)
+block.
+)
 vindex(TTY)
 item(tt(TTY))(
 The name of the tty associated with the shell, if any.
diff --git a/Src/loop.c b/Src/loop.c
index 9b0a8d7..4daa605 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -633,6 +633,14 @@ execcase(Estate state, int do_exec)
 zlong
 try_errflag = -1;
 
+/**
+ * Corrresponding interrupt error status form `try' block.
+ */
+
+/**/
+zlong
+try_interrupt = -1;
+
 /**/
 zlong
 try_tryflag = 0;
@@ -643,8 +651,8 @@ exectry(Estate state, int do_exec)
 {
     Wordcode end, always;
     int endval;
-    int save_retflag, save_breaks, save_contflag, try_interrupt;
-    zlong save_try_errflag, save_try_tryflag;
+    int save_retflag, save_breaks, save_contflag;
+    zlong save_try_errflag, save_try_tryflag, save_try_interrupt;
 
     end = state->pc + WC_TRY_SKIP(state->pc[-1]);
     always = state->pc + 1 + WC_TRY_SKIP(*state->pc);
@@ -671,8 +679,9 @@ exectry(Estate state, int do_exec)
 
     /* The always clause. */
     save_try_errflag = try_errflag;
+    save_try_interrupt = try_interrupt;
     try_errflag = (zlong)(errflag & ERRFLAG_ERROR);
-    try_interrupt = errflag & ERRFLAG_INT;
+    try_interrupt = (zlong)((errflag & ERRFLAG_INT) ? 1 : 0);
     /* We need to reset all errors to allow the block to execute */
     errflag = 0;
     save_retflag = retflag;
@@ -689,18 +698,12 @@ exectry(Estate state, int do_exec)
 	errflag |= ERRFLAG_ERROR;
     else
 	errflag &= ~ERRFLAG_ERROR;
-    /*
-     * TODO: currently, we always restore the interrupt
-     * error status.  We should have a way of clearing it.
-     * Doing this with try_errflag (the shell variable TRY_BLOCK_ERROR)
-     * is probably not a good idea since currently that's documented
-     * such that setting it to 0 clears errors, and we don't want
-     * to clear interrupts as a side effect.  So it probably needs
-     * a different variable.
-     */
     if (try_interrupt)
 	errflag |= ERRFLAG_INT;
+    else
+	errflag &= ~ERRFLAG_INT;
     try_errflag = save_try_errflag;
+    try_interrupt = save_try_interrupt;
     if (!retflag)
 	retflag = save_retflag;
     if (!breaks)
diff --git a/Src/params.c b/Src/params.c
index bdace79..79088d1 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -331,6 +331,7 @@ IPDEF5("SHLVL", &shlvl, varinteger_gsu),
 #define IPDEF6(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL|PM_DONTIMPORT},BR((void *)B),GSU(F),10,0,NULL,NULL,NULL,0}
 IPDEF6("OPTIND", &zoptind, varinteger_gsu),
 IPDEF6("TRY_BLOCK_ERROR", &try_errflag, varinteger_gsu),
+IPDEF6("TRY_BLOCK_INTERRUPT", &try_interrupt, varinteger_gsu),
 
 #define IPDEF7(A,B) {{NULL,A,PM_SCALAR|PM_SPECIAL},BR((void *)B),GSU(varscalar_gsu),0,0,NULL,NULL,NULL,0}
 #define IPDEF7U(A,B) {{NULL,A,PM_SCALAR|PM_SPECIAL|PM_UNSET},BR((void *)B),GSU(varscalar_gsu),0,0,NULL,NULL,NULL,0}


  parent reply	other threads:[~2014-12-07 20:20 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 15:54 Something rotten in tar completion Peter Stephenson
2014-12-02 16:48 ` Bart Schaefer
2014-12-02 17:26   ` Peter Stephenson
2014-12-04 16:56     ` Bart Schaefer
2014-12-04 17:12       ` Peter Stephenson
2014-12-05  8:20         ` Interrupting globs (Re: Something rotten in tar completion) Bart Schaefer
2014-12-05 14:17           ` Jérémie Roquet
2014-12-06 21:50             ` Bart Schaefer
2014-12-06 22:15               ` Bart Schaefer
2014-12-05 14:50           ` Peter Stephenson
2014-12-05 15:14             ` Jérémie Roquet
     [not found]             ` <22084.1417791853@thecus.kiddle.eu>
2014-12-05 15:29               ` Peter Stephenson
2014-12-05 17:03                 ` Peter Stephenson
2014-12-05 17:53             ` Peter Stephenson
2014-12-05 18:06             ` Bart Schaefer
2014-12-05 18:13               ` Peter Stephenson
2014-12-05 20:34                 ` Peter Stephenson
2014-12-05 22:07                   ` Peter Stephenson
2014-12-06  0:32                     ` Ray Andrews
2014-12-06 22:27                       ` Bart Schaefer
2014-12-06 22:57                         ` Ray Andrews
2014-12-06  0:36                     ` Mikael Magnusson
2014-12-06  0:40                       ` Mikael Magnusson
2014-12-06 22:31                         ` Bart Schaefer
2014-12-06  0:52                       ` Mikael Magnusson
2014-12-06 11:49                         ` Mikael Magnusson
2014-12-06 17:48                           ` Bart Schaefer
2014-12-07  1:42                             ` Mikael Magnusson
2014-12-07  4:45                               ` Bart Schaefer
2014-12-07  5:04                                 ` Bart Schaefer
2014-12-07 17:39                           ` Peter Stephenson
2014-12-07 22:59                             ` Mikael Magnusson
2014-12-07  5:18                     ` Bart Schaefer
2014-12-07 17:07                       ` Peter Stephenson
2014-12-07 17:19                         ` Peter Stephenson
2014-12-08 11:18                           ` Peter Stephenson
2014-12-08 12:43                             ` Mikael Magnusson
2014-12-08 13:03                               ` Peter Stephenson
2014-12-08 15:51                                 ` Mikael Magnusson
2014-12-08 16:41                                 ` Bart Schaefer
2014-12-07 17:37                         ` Oliver Kiddle
2014-12-07 18:18                           ` Peter Stephenson
2014-12-07 18:34                         ` Bart Schaefer
2014-12-07 18:59                           ` Peter Stephenson
2014-12-07 19:58                             ` Bart Schaefer
2014-12-08 10:01                               ` Peter Stephenson
2014-12-07 20:20                             ` Peter Stephenson [this message]
2014-12-07 20:54                               ` Bart Schaefer
2014-12-07 20:03                       ` Peter Stephenson
2014-12-07  5:59                   ` Bart Schaefer
2014-12-07  7:15                     ` Mikael Magnusson
2014-12-07 16:21                     ` Peter Stephenson
2014-12-07 23:01                       ` Interrupts in completion, traps in _main_complete Bart Schaefer
2014-12-08 20:27                         ` Peter Stephenson
2014-12-09  4:43                           ` Bart Schaefer
2014-12-09 11:26                             ` Peter Stephenson
2014-12-09 11:50                               ` Peter Stephenson
2014-12-09 21:09                                 ` Peter Stephenson
2014-12-10 10:02                               ` interrupt_abort incorporation Peter Stephenson
2014-12-11 10:00                                 ` Peter Stephenson
2014-12-04 17:24       ` Something rotten in tar completion Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141207202002.29def040@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).