From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: zsh-workers@zsh.org
Subject: Re: BUG: $_ empty on null function call
Date: Tue, 10 Feb 2015 10:59:38 +0000 [thread overview]
Message-ID: <20150210105938.GD1834@tarsus.local2> (raw)
In-Reply-To: <20150209151340.589909be@pwslap01u.europe.root.pri>
[-- Attachment #1: Type: text/plain, Size: 2609 bytes --]
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@samsung.com> wrote:
> > On Mon, 9 Feb 2015 14:10:26 +0000
> > Daniel Shahaf <d.s@daniel.shahaf.name> 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
[-- Attachment #2: anonfunc-dollarunderscore.diff --]
[-- Type: text/x-patch, Size: 434 bytes --]
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;
next prev parent reply other threads:[~2015-02-10 10:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 11:38 Micah Waddoups
2015-02-09 11:44 ` Micah Waddoups
2015-02-09 12:20 ` Peter Stephenson
2015-02-09 14:10 ` Daniel Shahaf
2015-02-09 14:25 ` Peter Stephenson
2015-02-09 15:13 ` Peter Stephenson
2015-02-09 16:11 ` Bart Schaefer
2015-02-10 10:59 ` Daniel Shahaf [this message]
2015-02-10 10:54 ` Daniel Shahaf
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=20150210105938.GD1834@tarsus.local2 \
--to=d.s@daniel.shahaf.name \
--cc=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/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).