zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: (2) test for trap EXIT fix.
Date: Wed, 03 Oct 2001 16:18:15 +0100	[thread overview]
Message-ID: <19164.1002122295@csr.com> (raw)
In-Reply-To: "Bart Schaefer"'s message of "Tue, 02 Oct 2001 16:03:28 -0000." <1011002160329.ZM24847@candle.brasslantern.com>

Bart Schaefer wrote:
> } The 4.0 behaviour is that only the explicit exit produces a trap; falling
> } off the end of the subshell in `( true )' doesn't.  I would guess this is
> } wrong and they should be equivalent.  That may require more special
> } handling.
> 
> Hrm.
> 
> zagzig% echo $ZSH_VERSION
> 3.0.8
> zagzig% TRAPEXIT() { print exiting }
> zagzig% (true)
> zagzig% (exit)
> exiting
> zagzig% fn() { ( true ) ; ( exit ); }
> zagzig% fn
> zagzig% exit
> exiting

Are you saying this is correct and the inconsistency between falling off
the end and exiting is the intended behaviour?  The following might do we
what you want.  Maybe you'd better try it and then complain further.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.54
diff -u -r1.54 builtin.c
--- Src/builtin.c	2001/09/24 10:12:51	1.54
+++ Src/builtin.c	2001/10/03 15:13:54
@@ -3255,12 +3255,16 @@
 	}
 	/*FALLTHROUGH*/
     case BIN_EXIT:
-	if (locallevel) {
+	if (locallevel > forklevel) {
 	    /*
 	     * We don't exit directly from functions to allow tidying
 	     * up, in particular EXIT traps.  We still need to perform
 	     * the usual interactive tests to see if we can exit at
 	     * all, however.
+	     *
+	     * The forklevel test means we *do* exit from a subshell
+	     * inside a function when we reach the level of the
+	     * function itself.
 	     */
 	    if (stopmsg || (zexit(0,2), !stopmsg)) {
 		retflag = 1;
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.37
diff -u -r1.37 exec.c
--- Src/exec.c	2001/09/24 10:12:51	1.37
+++ Src/exec.c	2001/10/03 15:13:54
@@ -2490,6 +2490,10 @@
 }
 
 /**/
+int
+forklevel;
+
+/**/
 static void
 entersubsh(int how, int cl, int fake)
 {
@@ -2557,6 +2561,7 @@
     if (cl)
 	clearjobtab();
     times(&shtms);
+    forklevel = locallevel;
 }
 
 /* close internal shell fds */


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


  reply	other threads:[~2001-10-03 15:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-01 12:01 PATCH: " Peter Stephenson
2001-10-01 16:01 ` Bart Schaefer
2001-10-02 10:23   ` Peter Stephenson
2001-10-02 14:19     ` Bart Schaefer
2001-10-02 14:39       ` Peter Stephenson
2001-10-02 15:19         ` Bart Schaefer
2001-10-02 15:32           ` Peter Stephenson
2001-10-02 16:03             ` Bart Schaefer
2001-10-03 15:18               ` Peter Stephenson [this message]
2001-10-03 16:16                 ` PATCH: (2) " Bart Schaefer
2001-10-08  8:10                 ` Peter Stephenson
2001-10-08  9:56                   ` Bart Schaefer
2001-10-08 10:32                     ` Peter Stephenson

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=19164.1002122295@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).