zsh-workers
 help / color / mirror / code / Atom feed
* Bug in recursive function calls, source and exit
@ 2005-12-02 22:09 Vincent Lefevre
  2005-12-03  0:09 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Lefevre @ 2005-12-02 22:09 UTC (permalink / raw)
  To: zsh-workers

Hi,

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. Here's a way to reproduce it:

dixsept:~> zsh-beta -f
dixsept% echo $ZSH_VERSION 
4.3.0-dev-1
dixsept% echo false > ./file
dixsept% f() {
function> echo $[++i]
function> cat file
function> sleep 1
function> . ./file || echo exit > ./file
function> f
function> }
dixsept% which f
f () {
        echo $[++i]
        cat file
        sleep 1
        . ./file || echo exit > ./file
        f
}
dixsept% f
1
false
2
exit
3
exit
4
exit
5
exit
6
exit
[Ctrl-C]
dixsept:~>

FYI, bash doesn't have this problem:

[...]
vlefevre@dixsept:~$ f
1
false
2
exit
dixsept:~>

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug in recursive function calls, source and exit
  2005-12-02 22:09 Bug in recursive function calls, source and exit Vincent Lefevre
@ 2005-12-03  0:09 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2005-12-03  0:09 UTC (permalink / raw)
  To: zsh-workers

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/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-12-03  0:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-02 22:09 Bug in recursive function calls, source and exit Vincent Lefevre
2005-12-03  0:09 ` Peter Stephenson

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).