zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk
Subject: Re: Bug in recursive function calls, source and exit
Date: Sat, 3 Dec 2005 00:09:49 +0000	[thread overview]
Message-ID: <20051203000949.4ddf2529.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <20051202220921.GR8445@ay.vinc17.org>

On Fri, 2 Dec 2005 23:09:21 +0100
Vincent Lefevre <vincent@vinc17.org> wrote:
> In a French mailing-list, I've just heard of a bug related to
> recursive function calls, source and exit; I don't think it has
> been reported yet.

Thanks for passing it on.  You can see the bug more simply with:

echo exit >file
zsh -fc 'fn() { . ./file; echo Didn\'\''t exit; }; fn'

The problem is that we don't exit immediately from functions to allow
EXIT traps to run (zsh has more handling for these than other shells),
instead we force the function to return immediately.  However, the code
for "." was resetting the flag to return from the function.

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.60
diff -u -r1.60 init.c
--- Src/init.c	15 Nov 2005 08:44:21 -0000	1.60
+++ Src/init.c	3 Dec 2005 00:03:30 -0000
@@ -1085,7 +1085,8 @@
     loops = oloops;                  /* the # of nested loops we are in      */
     dosetopt(SHINSTDIN, oldshst, 1); /* SHINSTDIN option                     */
     errflag = 0;
-    retflag = 0;
+    if (!exit_pending)
+	retflag = 0;
     scriptname = old_scriptname;
     free(cmdstack);
     cmdstack = ocs;

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page still at http://www.pwstephenson.fsnet.co.uk/


      reply	other threads:[~2005-12-03  0:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-02 22:09 Vincent Lefevre
2005-12-03  0:09 ` Peter Stephenson [this message]

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=20051203000949.4ddf2529.p.w.stephenson@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).