Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: skip command from debug trap
- X-seq: zsh-workers 25405
- From: Peter Stephenson <pws@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: PATCH: skip command from debug trap
- Date: Wed, 6 Aug 2008 16:34:10 +0100
- In-reply-to: <20080806145917.GE5197@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <27237.1217946438@xxxxxxx> <6cd6de210808051647k17f14902nce840ca3edd6ddb@xxxxxxxxxxxxxx> <20080806104716.44647a75@news01> <080806072236.ZM14655@xxxxxxxxxxxxxxxxxxxxxx> <20080806145917.GE5197@xxxxxxxxxxxxxxx>
On Wed, 6 Aug 2008 15:59:17 +0100
Stephane Chazelas <Stephane_Chazelas@xxxxxxxx> 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@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author