zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: Re: Help me track down a tough bug? (probably funcfiletrace, subshells and possibly I/O redirection)
Date: Wed, 1 Oct 2008 12:31:07 +0100	[thread overview]
Message-ID: <20081001123107.1113468f@news01> (raw)
In-Reply-To: <6cd6de210809301059o64216c18wfb69491c5ff7b049@mail.gmail.com>

On Tue, 30 Sep 2008 13:59:43 -0400
"Rocky Bernstein" <rocky.bernstein@gmail.com> wrote:
> My mistake. You are correct. This bug was introduced in paring down
> the program and removing an initial truncate output (leaving the
> subsequent append outputs). And I now see the answer to why output was
> disappearing in the subshell which was my initial concern.

OK, so it seems there's currently nothing for me to look at here.

> Any thoughts on marking subshell level inside one of the stack traces
> or having return inside trap DEBUG with a negative number cause an
> immediate return?

You can already force a return from the enclosing function from trap '...'
DEBUG just by executing "return".  You can use return from within enclosing
functions to trigger this, e.g.

  fn() {
    return 3
  }
  trap 'fn || return $?' DEBUG

(if you need to return status 0, offset the status return value from fn by
1 and use 'fn || return $(( $? - 1 ))').  For example

  foo() {
    emulate -L zsh
    trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 1' DEBUG
    echo foo
    echo bar
  }

when executed (with DEBUG_BEFORE_CMD assumed set by default) prints "foo"
but not "bar" and should return status 1 from foo.  However --- Surprise!
--- there's a bug and although it does return from foo the status gets
lost.  The fix is below.

Let us know either if this isn't working properly or you need something
more specific.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.158
diff -u -r1.158 exec.c
--- Src/exec.c	29 Sep 2008 21:46:58 -0000	1.158
+++ Src/exec.c	1 Oct 2008 11:24:43 -0000
@@ -1091,7 +1091,8 @@
 	    exiting = donetrap;
 	    ret = lastval;
 	    dotrap(SIGDEBUG);
-	    lastval = ret;
+	    if (!retflag)
+		lastval = ret;
 	    donetrap = exiting;
 	    noerrexit = oldnoerrexit;
 	    /*
@@ -1230,7 +1231,8 @@
 	    exiting = donetrap;
 	    ret = lastval;
 	    dotrap(SIGDEBUG);
-	    lastval = ret;
+	    if (!retflag)
+		lastval = ret;
 	    donetrap = exiting;
 	    noerrexit = oldnoerrexit;
 	    opts[ERREXIT] = oerrexit_opt;
Index: Test/C05debug.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C05debug.ztst,v
retrieving revision 1.2
diff -u -r1.2 C05debug.ztst
--- Test/C05debug.ztst	5 Sep 2008 09:05:23 -0000	1.2
+++ Test/C05debug.ztst	1 Oct 2008 11:24:43 -0000
@@ -137,3 +137,13 @@
 >9: 'fn2'
 >0: 'echo wow'
 >wow
+
+  foo() {
+    emulate -L zsh; setopt debugbeforecmd
+    trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 2' DEBUG
+    echo foo
+    echo bar
+  }
+  foo
+2:Status of forced return from eval-style DEBUG trap
+>foo


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


  parent reply	other threads:[~2008-10-01 11:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6cd6de210809281219i4bf1ed18mefa45b967fa835a6@mail.gmail.com>
     [not found] ` <20080928221651.6ee7f671@pws-pc>
2008-09-29  2:32   ` Rocky Bernstein
2008-09-29  8:52     ` Peter Stephenson
2008-09-29 11:11       ` Rocky Bernstein
2008-09-29 11:25         ` Peter Stephenson
2008-09-29 14:11           ` Rocky Bernstein
2008-09-29 14:25             ` Peter Stephenson
2008-09-29 21:42               ` Peter Stephenson
2008-09-30  0:18                 ` Rocky Bernstein
2008-09-30 16:53                   ` Peter Stephenson
2008-09-30 17:59                     ` Rocky Bernstein
2008-09-30 18:01                       ` Rocky Bernstein
2008-10-01 11:31                       ` Peter Stephenson [this message]
2008-10-01 15:45                         ` Rocky Bernstein

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=20081001123107.1113468f@news01 \
    --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).