* Re: question about posixbuiltins
[not found] ` <CAH+w=7agsP-OrgOU3FUE01fn5J-9apd2V9FgmCpWR1rf12VoNQ@mail.gmail.com>
@ 2015-04-14 14:58 ` Peter Stephenson
2015-04-15 2:43 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2015-04-14 14:58 UTC (permalink / raw)
To: Zsh Hackers' List
On Mon, 13 Apr 2015 14:44:52 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Apr 12, 2015 4:03 PM, "Han Pingtian" <hanpt@linux.vnet.ibm.com> wrote:
> > POSIX_BUILTINS <K> <S>
> > [...] Parameter assignments specified
> > before shell functions and special builtins are kept after the
> > command completes unless the special builtin is prefixed with
> > the command builtin.
> > [...]
> > But looks like the parameter assignment before "command special-builtin"
> > is kept even though POSIX_BUILTINS has been set
>
> Indeed I can confirm, it appears this either was never working or has been
> broken by some recent change.
(Moved to zsh-workers.)
I can believe it was never working --- the logic is horrifically
tortuous. I've rewritten it to try to make sense of it. The compiler
will be grateful for a variable to optimise out and perhaps therefore
indulgent enough to ignore remaining mistakes.
I don't really understand the non-POSIX_BUILTINS case, but unless my
brain has totally failed to cope it's the same logic it's always been.
pws
diff --git a/Src/exec.c b/Src/exec.c
index 1a6149a..2ee37d0 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3384,14 +3384,28 @@ execcmd(Estate state, int input, int output, int how, int last1)
LinkList restorelist = 0, removelist = 0;
/* builtin or shell function */
- if (!forked && ((cflags & BINF_COMMAND) ||
- (unset(POSIXBUILTINS) && !assign) ||
- (isset(POSIXBUILTINS) && !is_shfunc &&
- !(hn->flags & BINF_PSPECIAL)))) {
- if (varspc)
+ if (!forked && varspc) {
+ int do_save = 0;
+ if (isset(POSIXBUILTINS)) {
+ /*
+ * If it's a function or special builtin --- save
+ * if it's got "command" in front.
+ * If it's a normal command --- save.
+ */
+ if (is_shfunc || (hn->flags & BINF_PSPECIAL))
+ do_save = (orig_cflags & BINF_COMMAND);
+ else
+ do_save = 1;
+ } else {
+ /*
+ * Save if it's got "command" in front or it's
+ * not a magic-equals assignment.
+ */
+ if ((cflags & BINF_COMMAND) || !assign)
+ do_save = 1;
+ }
+ if (do_save)
save_params(state, varspc, &restorelist, &removelist);
- else
- restorelist = removelist = NULL;
}
if (varspc) {
/* Export this if the command is a shell function,
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 3213534..5c453c8 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -783,6 +783,19 @@
>print is a shell builtin
?(eval):8: command not found: print
+ # With non-special command: original value restored
+ # With special builtin: new value kept
+ # With special builtin preceeded by "command": original value restored.
+ (setopt posixbuiltins
+ FOO=val0
+ FOO=val1 true; echo $FOO
+ FOO=val2 times 1>/dev/null 2>&1; echo $FOO
+ FOO=val3 command times 1>/dev/null 2>&1; echo $FOO)
+0:POSIX_BUILTINS and restoring variables
+>val0
+>val2
+>val2
+
# PRINTEXITVALUE only works if shell input is coming from standard input.
# Goodness only knows why.
$ZTST_testdir/../Src/zsh -f <<<'
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: question about posixbuiltins
2015-04-14 14:58 ` question about posixbuiltins Peter Stephenson
@ 2015-04-15 2:43 ` Bart Schaefer
2015-04-15 8:35 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-04-15 2:43 UTC (permalink / raw)
To: Zsh Hackers' List
On Apr 14, 3:58pm, Peter Stephenson wrote:
}
} I can believe it was never working --- the logic is horrifically
} tortuous. I've rewritten it to try to make sense of it.
Does this make it easier or harder to address Jun T's questions in
workers/34862 and workers/34856 ?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: question about posixbuiltins
2015-04-15 2:43 ` Bart Schaefer
@ 2015-04-15 8:35 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2015-04-15 8:35 UTC (permalink / raw)
To: Zsh Hackers' List
On Tue, 14 Apr 2015 19:43:10 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Apr 14, 3:58pm, Peter Stephenson wrote:
> }
> } I can believe it was never working --- the logic is horrifically
> } tortuous. I've rewritten it to try to make sense of it.
>
> Does this make it easier or harder to address Jun T's questions in
> workers/34862 and workers/34856 ?
I don't see how it can make it any harder; if they're related it should
be easier. However, they're not prima facie closely related as the
specialness of exec happens elsewhere.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-15 8:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20150412134049.GB2759@localhost.localdomain>
[not found] ` <CAH+w=7agsP-OrgOU3FUE01fn5J-9apd2V9FgmCpWR1rf12VoNQ@mail.gmail.com>
2015-04-14 14:58 ` question about posixbuiltins Peter Stephenson
2015-04-15 2:43 ` Bart Schaefer
2015-04-15 8:35 ` Peter Stephenson
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).