Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: BUG: $_ empty on null function call
- X-seq: zsh-workers 34493
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: BUG: $_ empty on null function call
- Date: Tue, 10 Feb 2015 10:59:38 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=mesmtp; bh=o2pNqSfHZHu huzhkG8gwbEgvapM=; b=PXruKjl8Nhsahxe3DqyXuYWtiU8YE/t5eFkQFaSFgPF EyEmHFUBbCXTYOCxZlGfq1p2zrXJAphpzFlVcoanTmnubdYDEktD5rT0Bdwihemi gOGQ0OCqDi/PnvrOpVq+Qoic1L9z9Pj6ZW8rhjOn9N7Q9WiXeLqA9Y4ASHDC/CKU =
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=smtpout; bh=o2pNqSfHZH uhuzhkG8gwbEgvapM=; b=FaX6AdjNLKqKP0RZlR25E2LiSB366AiTePbSOM3Epe aysXYRDUasciinlmmoddQIENIVvGR5Qf8qbdHmKGh5Tmdyvu075zBnVIVj0tL+e5 l3FEYPCjZGdN8Wo8sF3CeAiyRCsvK7vpGsoq4213HGJ5NN6P2bh3WLEm4Nz54rFc M=
- In-reply-to: <20150209151340.589909be@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> <20150209141026.GB1833@tarsus.local2> <20150209142507.348fa42a@pwslap01u.europe.root.pri> <20150209151340.589909be@pwslap01u.europe.root.pri>
Peter Stephenson wrote on Mon, Feb 09, 2015 at 15:13:40 +0000:
> On Mon, 9 Feb 2015 14:25:07 +0000
> Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> > On Mon, 9 Feb 2015 14:10:26 +0000
> > Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > > There are some other differences between anonymous functions, e.g., they
> > > don't honor PRINT_EXIT_VALUE:
> > >
> > > Engineering-wise, the ideal solution would be for anonymous and named
> > > functions to share code... though I realize that may be a somewhat
> > > invasive code change.
> >
> > They already do everywhere that doesn't deal with the special argument
> > syntax (Micah's problem) or with immediate execution after a definition.
> > I suspect this may have to do with a different path owing to an
> > optimisation later in the execution path where we make certain
> > assumptions if code is regarded as "simple".
>
> Sigh. It's a combination of that *and* execution immediately after
> definition.
>
> When the code is parsed, we don't know if PRINTEXITVALUE is going to be
> set when it's run. At this point I think we declare "simple" code
> execution for anonymous functions dead in the water. The effect is
> probably small anyway.
>
I was looking at making [[ honor PRINT_EXIT_VALUE; right now it doesn't,
because it uses execlist->execsimple->execcond (and so never passes
through execcmd). I'm mentioning that since it may be relevant, as it
also concerns a simple command wanting to honor PRINT_EXIT_VALUE.
¹ The use-case: I use [[ ]] as a standalone command (not as part of an
if or while) in interactive shells to test its syntax when writing scripts.
> It looks like we can make some code in the lowest level of general
> command execution, execcmd(), run in a few more cases, at least the
> following attempt to move them out of an if block doesn't cause any test
> failures.
>
> This doesn't help with Micah's problem which is due to the *third*
> difference.
>
I'll just point out for anyone who needs $_ with anonymous functions
working "yesterday" that a quick and dirty way to achieve that is via
the attached patch. It might not be a good general solution since it
duplicates code, but it does make invocation of anonymous functions set
$_ and I think it has no harmful effects.
I suppose a better fix would involve extracting the arguments of an
anonymous function up in execcmd() rather than down in execfuncdef(), so
they can reuse the existing setunderscore() call in execcmd()?
> + () { false; }
> +1:PRINT_EXIT_VALUE option for anonymous function
> +?zsh: exit 1
Thanks for fixing this :)
Daniel
diff --git a/Src/exec.c b/Src/exec.c
index 3b0e936..719345e 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4482,6 +4482,11 @@ execfuncdef(Estate state, Eprog redir_prog)
shf->node.nam = "(anon)";
pushnode(args, shf->node.nam);
+ /* Set up special parameter $_ */
+ setunderscore((args && nonempty(args))
+ ? ((char *) getdata(lastnode(args)))
+ : "");
+
execshfunc(shf, args);
ret = lastval;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author