From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org
X-Spam-Level:
X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID,
DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY
autolearn=ham autolearn_force=no version=3.4.4
Received: (qmail 27826 invoked from network); 19 Apr 2022 18:56:14 -0000
Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368)
by inbox.vuxu.org with ESMTPUTF8; 19 Apr 2022 18:56:14 -0000
ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1650394574;
b=RStJYZNlg/f6PVF8/i6TPggrUgktumCCd076xujjD9Lww7dn+6FaO56WbyXxso9SRlVZ2n//7N
kfhM61wqsiTZ8sThsyuxLe1UEXRT9n2rf+3CcS6+BrS+El/HjeGq5Ny4BGI5v7y3dYC4nF6kSC
yXRzj6J6xemEIFoII12LC8RDoTGlb9G7iOX6zpiKabqD+elHrf5aspEu2nbg/wJB+RxSSNmicW
y5tVkK7iM+TX41+ArBUvnD9IktvR9XWGUi6uiZVXeO06dzrrXC+fBFIG6Pad2jkmY91DWWkryw
+QOerbrkVSsvdSODaQ0EKzPlSvdu0GuT5MHE4A//yplJXQ==;
ARC-Authentication-Results: i=1; zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1650394574;
bh=jgClJzAYg/WnFzZn683Fbpw5Fgpm8HniTltepqZWTzs=;
h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help:
List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Content-Type:
References:In-Reply-To:Date:To:From:Subject:Message-ID:DKIM-Signature:
DKIM-Signature;
b=IynSmlBDaISfkIhCJ2qtXaOLdpyVaMd2PBMaqFP7PbuA8Au7OdRfwvlkNlu6wWpk/eL01k4zrk
ogN5Bn/0icrxRMqgkMQuCb1TNj4vpdLkLtgblNu/N+4pUKTrbKuAQPWpO2qC1kWUXZowix7Dj1
DMzsdW3rp2U87lQFyk8oxzJvtpD0KvCO5PBKQHJyAuwBwx95Pjpx7NYC2/iAhGGWS/ZpTl5Mmf
UJTMIbzvy03FYpe+nNzb22TKyD5FQlzwIJVbGWa9T2kkDpiDas/6P1gs48QodIRsC+LBW1jOxc
xCg65rj+Wt3eFe6KCFqS4dBxjIHvA0eeW5DSpVSjCvV+sQ==;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org;
s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:
List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding:
Mime-Version:Content-Type:References:In-Reply-To:Date:To:From:Subject:
Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From
:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=Jdaz14QqouOfuolC7YP1fwq4RricgeVT5UEyGfKhDsk=; b=YT7YxdUTMJQQBh0I908lOdC8bl
lydFVXsMgBR07uaQBngsjmJzg5itNB2RfGUe33M0g79ugfE2cE4dnpzwxndbbCYrh/Z0Px2aDiOZF
x1rSDQqPrZCznx+vInuwbG6defDi3ZCcPmaXX9jogM9qDmFBoX5MktkiGG4u4Yur233p0vonS0Agf
FZeXzZsVgfOq0jqoGb2cId1NGVAyj3Fvc2L0OsrzL+e0kxF1wBZB1oBHALmT8Bd72+KyQ1lpBXiAv
q++YoidNbRpSBHHqgPoMmLfIb/5ZAaTlLcGuEjsLKLCSE9NKlleyBfJnsI+VGgQ/JbfOtcU53C8X3
UETo+dvw==;
Received: from authenticated user by zero.zsh.org with local
id 1ngt1J-000O2w-Px;
Tue, 19 Apr 2022 18:56:13 +0000
Authentication-Results: zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:60478)
by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256)
id 1ngt0X-000NiV-E1;
Tue, 19 Apr 2022 18:55:26 +0000
Received: from [212.54.57.108] (helo=csmtp4.tb.ukmail.iss.as9143.net)
by smtpq2.tb.ukmail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1)
(envelope-from
)
id 1ngt0X-0007BH-9a
for zsh-workers@zsh.org; Tue, 19 Apr 2022 20:55:25 +0200
Received: from pws-Zeus ([82.1.229.179])
by cmsmtp with ESMTPA
id gt0XnCzp3uYlrgt0XnsdZ4; Tue, 19 Apr 2022 20:55:25 +0200
X-SourceIP: 82.1.229.179
X-Authenticated-Sender: p.w.stephenson@ntlworld.com
X-Spam: 0
X-Authority: v=2.4 cv=RoXWkQqK c=1 sm=1 tr=0 ts=625f059d cx=a_exe
a=W4rGJ7PGCSRRUvufKHO8Dg==:117 a=W4rGJ7PGCSRRUvufKHO8Dg==:17
a=IkcTkHD0fZMA:10 a=z0gMJWrwH1QA:10 a=q2GGsy2AAAAA:8 a=VLzyyttLE4AXApAkMsoA:9
a=QEXdDO2ut3YA:10 a=z9dJwno5l634igLiVhy-:22
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com;
s=meg.feb2017; t=1650394525;
bh=Jdaz14QqouOfuolC7YP1fwq4RricgeVT5UEyGfKhDsk=;
h=Subject:From:To:Date:In-Reply-To:References;
b=uPaiJOSN9eFPghvhjMDja9IRSPEdgCqqFOC75YnU1V1h8E3d87B1amSpHcobwpuJ9
y1EoNjNUpm9/QkyOsTY8UwJ96uMjeI3lYXdGYy7lP0+d3vXbRrHpM4nB85Q0ml6OGV
HmrElFSWjzcPhKYRd1cGnmDTJpwrK/2IEb7Iel9nlPJW64a03xvNoHNz7ovrB+tSFn
+RPgQ8l9U30U2qdqtz2aZNLUqFXXfB4qIdp5zd40lWBNB0Sb7hSH8uuKwIh9hZj2/7
VTKCPgmCmf+AwfSgclPnd3v6/F+q2Oo8BrL8LU1dwptNUpP07k5SpzhmANIBgsbCCs
QYLVI9Qb+1K7Q==
Message-ID: <477f4f5b54230f5896896112b31ef45e7c495e72.camel@ntlworld.com>
Subject: Re: using trap function to cleanup and exit?
From: Peter Stephenson
To: zsh-workers@zsh.org
Date: Tue, 19 Apr 2022 19:55:24 +0100
In-Reply-To: <220ac31e9aa5262cc93fbd7c37da76154a80d09b.camel@ntlworld.com>
References: <25170.64465.301441.247673@lwm.klanderman.net>
<87fsmk2a03.fsf@lwm.klanderman.net> <87czho2967.fsf@lwm.klanderman.net>
<871qy0yzp4.fsf@lwm.klanderman.net>
<220ac31e9aa5262cc93fbd7c37da76154a80d09b.camel@ntlworld.com>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
X-CMAE-Envelope: MS4xfKFBfap3au59XMa6Pod0rCOR/jgP+XyW3bdbT3t5p+iork18OIyF1e1+yANGhWMxZgXt524Fqxml0cDryMA8Oqcu2GiMuRuqB1DW9X9fSvZQ8JJaeVl/
RWMzh89B8EytxO15159WOmuyiFgrAtVi2+pjh8+QwC53NeKvbAYosQ18b7ocudoJtm0jzytUDdZSwA==
X-Seq: 50083
Archived-At:
X-Loop: zsh-workers@zsh.org
Errors-To: zsh-workers-owner@zsh.org
Precedence: list
Precedence: bulk
Sender: zsh-workers-request@zsh.org
X-no-archive: yes
List-Id:
List-Help:
List-Subscribe:
List-Unsubscribe:
List-Post:
List-Owner:
List-Archive:
On Tue, 2022-04-19 at 19:42 +0100, Peter Stephenson wrote:
> On Fri, 2022-04-15 at 15:27 -0700, Bart Schaefer wrote:
> > On Thu, Apr 14, 2022 at 2:29 PM Bart Schaefer wrote:
> > >
> > > [I] would prefer that another set of eyes review
> > > the code change.
> >
> > To expand on that a bit ...
> >
> > The BIN_RETURN branch checks that (trap_return == -2) which is a
> > pretty specific number. exec.c says:
> > * This is only active if we are inside a trap, else its value
> > * is irrelevant. It is initialised to -1 for a function trap and
> > * -2 for a non-function trap and if negative is decremented as
> > * we go deeper into functions and incremented as we come back up.
> > * The value is used to decide if an explicit "return" should cause
> > * a return from the caller of the trap; it does this by setting
> > * trap_return to a status (i.e. a non-negative value).
> >
> > My interpretation is that, since we are in an explicit "exit" rather
> > than an explicit "return", we don't really care how trap_return is
> > set; we're going to force the caller to return, period.
>
> I just got back and looked, and it's hard to see how this could make
> anything worse.
Very minor comment (entirely cosmetic): it would probably be good
practice to check trap_state != TRAP_STATE_INACTIVE rather than just
trap_state. Does the following look reasonable? In fact, it might
be even more logical just to check for PRIMED.
With hindsight, "primed" isn't a great choice of word, it doesn't
indicate what state we are actually at in trap processing, but without
following this all through in more detail I wouldn't like to suggest
another. (And the resulting
TRAP_STATE_WE_DID_THIS_BUT_WE_HAVENT_YET_DONE_THIS_BECAUSE_WERE_WAITING_FOR_THIS
might not be any better...)
pws
diff --git a/Src/builtin.c b/Src/builtin.c
index b93466ba5..88d69e070 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5720,7 +5720,11 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
* a bad job.
*/
if (stopmsg || (zexit(0, ZEXIT_DEFERRED), !stopmsg)) {
- if (trap_state)
+ /*
+ * If the trap is primed but we've hit an explicit exit,
+ * we should skip any further handling and bail out now.
+ */
+ if (trap_state != TRAP_STATE_INACTIVE)
trap_state = TRAP_STATE_FORCE_RETURN;
retflag = 1;
breaks = loops;