zsh-workers
 help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT)
Date: Wed, 16 Nov 2022 07:31:52 +0100	[thread overview]
Message-ID: <CAGdYchv1ZxH1OituhcW37StAG+b9RjK3oUgUTiPA3fsMeYB4DA@mail.gmail.com> (raw)
In-Reply-To: <68e48647-7713-4b77-b719-d836d2671b06@app.fastmail.com>

[-- Attachment #1: Type: text/plain, Size: 2885 bytes --]

>
> Here are two additional cases that your patch does not cover.  They
> are not regressions, as stable zsh 5.9 is also affected.


Interesting! And the symptoms are exactly the same as they were with
function calls:

- If you replace "echo done" with "echo done $?" you can see that the
"source" and "eval" statements return the right exit status. They "just"
fail to trigger ERR_EXIT.
- When you drop the "if" statement and only keep "false && true", then
ERR_EXIT is correctly triggered.

It looks like another case where saving and restoring this_noerrexit is
missing. And, indeed, if save and restore this_noerrexit are added just
before and after this execlist
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/exec.c#L1221>
in execode, then your examples work and all tests still pass. The function
execode
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/exec.c#L1193>
is
called from builtin.c in the eval
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/builtin.c#L6067>
function. In that context the saving and restoring looks warranted. But
there are multiple other calls, mainly in exec.c. Although for most it
looks right to save and restore, I can't say confidently that it's indeed
the case for all of them. I also wonder whether other elements of the
execution stack should be saved and restored. For function calls, there are
many more things that are saved and restored.

I also noticed that zsh.h declares a structure execstack
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/zsh.h#L1132>,
which is used in exec.c to implement execsave
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/exec.c#L6325>,
which saves the state of the execution stack, and execrestore
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/exec.c#L6357>,
which restores it. Surprisingly these two methods are only used once in
signals.c (here
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/signals.c#L1339>
and. here
<https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/signals.c#L1391>).
And even more surprisingly, even though plenty of variables are saved,
including this_noerrexit, the variable noerrexit is NOT saved, which looks
very suspicious to me.

How should we proceed? I'm 99% sure that my current patch (without the
changes mentioned above) is correct (i.e., it fixes a number of problems
and doesn't introduce new ones). At the moment, I'm much less confident
about changing execode as described above or about adding noerrexit
to execstack. Would it make sense to submit my pacth (once I have fixed
Changlelog and 1-2 other things) and try to solve the other problems in
follow-up patches?

Philippe

[-- Attachment #2: Type: text/html, Size: 3429 bytes --]

  reply	other threads:[~2022-11-16  6:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 22:16 Philippe Altherr
2022-11-13  3:59 ` Philippe Altherr
2022-11-13  4:11   ` Bart Schaefer
2022-11-13 13:55     ` Philippe Altherr
2022-11-13 14:24       ` Philippe Altherr
2022-11-13 15:45         ` Philippe Altherr
2022-11-13 16:52           ` Bart Schaefer
2022-11-13 16:45       ` Bart Schaefer
2022-11-13 16:53         ` Bart Schaefer
2022-11-13 18:37           ` Philippe Altherr
2022-11-13 20:55             ` Philippe Altherr
2022-11-13 22:27               ` Bart Schaefer
2022-11-13 23:10               ` Lawrence Velázquez
2022-11-13 22:12             ` Bart Schaefer
2022-11-15  1:11         ` Bart Schaefer
2022-11-15  7:01           ` [PATCH] Even more ERR_EXIT (was Re: More ERR_EXIT " Bart Schaefer
2022-11-15  7:30             ` Philippe Altherr
2022-11-15 19:50               ` Philippe Altherr
2022-11-15  7:26           ` [PATCH] More ERR_EXIT (was " Philippe Altherr
2022-11-15 19:18             ` Philippe Altherr
2022-11-15 21:08               ` Bart Schaefer
2022-11-16  2:41               ` Lawrence Velázquez
2022-11-16  6:31                 ` Philippe Altherr [this message]
2022-11-16  5:51               ` Bart Schaefer
2022-11-16  7:56                 ` Philippe Altherr
2022-11-16 14:21                   ` Philippe Altherr
  -- strict thread matches above, loose matches on Subject: below --
2022-11-09  5:29 Tests RE behavior of ERR_EXIT Bart Schaefer
2022-11-10  5:22 ` [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT) Bart Schaefer
2022-11-10  5:47   ` 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=CAGdYchv1ZxH1OituhcW37StAG+b9RjK3oUgUTiPA3fsMeYB4DA@mail.gmail.com \
    --to=philippe.altherr@gmail.com \
    --cc=larryv@zsh.org \
    --cc=schaefer@brasslantern.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).