zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: PATCH: skip command from debug trap
Date: Wed, 6 Aug 2008 16:34:10 +0100	[thread overview]
Message-ID: <20080806163410.0ce3cacd@news01> (raw)
In-Reply-To: <20080806145917.GE5197@sc.homeunix.net>

On Wed, 6 Aug 2008 15:59:17 +0100
Stephane Chazelas <Stephane_Chazelas@yahoo.fr> wrote:
> On Wed, Aug 06, 2008 at 07:22:36AM -0700, Bart Schaefer wrote:
> [...]
> > 	x=3
> > 	return --x
> > 
> > returns "2".  How are you going to make any kind of option parsing for
> > return behave compatibly with that? 

Grrrr.  All the control commands do that, and all for the sake of making
the command line less clear by omitting the $((...)).

However, return has never taken more than one argument up to now, so
there's nothing to stop us only evaluating the final argument
mathematically and require "return -s 0" to skip a statement and behave as
if it returned 0.  We have a choice of rule: (i) with more than one
argument, option and argument parsing becomes like other commands (so you
need a -- if there's possibly a negative expression at the end but
otherwise if it doesn't look like an option you still get math processing)
(ii) with more than one argument, the last argument is always a value.  I
think (i) is probably slightly clearer.

"return --" has always been an error; I don't see why it shouldn't be made
to do what it does in other shells in all modes.  Generally we've taken the
attitude that anything previously an error is fair game for use as
extensions.

> BTW, is this:
> 
> $ zsh -c '(){echo test;return 1}; echo $?'
> test
> 0
> 
> the expected output?

That's a bug.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.136
diff -u -r1.136 exec.c
--- Src/exec.c	1 Aug 2008 13:53:44 -0000	1.136
+++ Src/exec.c	6 Aug 2008 15:18:27 -0000
@@ -3870,7 +3870,7 @@
 {
     Shfunc shf;
     char *s = NULL;
-    int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0;
+    int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0, ret = 0;
     Wordcode beg = state->pc, end;
     Eprog prog;
     Patprog *pp;
@@ -3941,6 +3941,7 @@
 	    addlinknode(args, shf->node.nam);
 
 	    execshfunc(shf, args);
+	    ret = lastval;
 	    break;
 	} else {
 	    /* is this shell function a signal trap? */
@@ -3963,7 +3964,7 @@
 	}
     }
     state->pc = end;
-    return 0;
+    return ret;
 }
 
 /* Main entry point to execute a shell function. */


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


  reply	other threads:[~2008-08-06 15:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-05 14:27 Peter Stephenson
2008-08-05 15:50 ` Stephane Chazelas
2008-08-05 23:47 ` Rocky Bernstein
2008-08-06  9:47   ` Peter Stephenson
2008-08-06 14:22     ` Bart Schaefer
2008-08-06 14:30       ` Rocky Bernstein
2008-08-06 14:59       ` Stephane Chazelas
2008-08-06 15:34         ` Peter Stephenson [this message]
2008-08-06 17:00     ` Rocky Bernstein
2008-08-06 17:54       ` Peter Stephenson
2008-08-06 19:09         ` Rocky Bernstein
2008-08-06 19:49           ` Peter Stephenson
2008-08-07  1:00             ` Bart Schaefer
2008-08-07 10:11               ` Peter Stephenson
2008-08-07 14:52                 ` Bart Schaefer

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=20080806163410.0ce3cacd@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).