zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: question about posixbuiltins
Date: Tue, 14 Apr 2015 15:58:30 +0100	[thread overview]
Message-ID: <20150414155830.029eb84e@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAH+w=7agsP-OrgOU3FUE01fn5J-9apd2V9FgmCpWR1rf12VoNQ@mail.gmail.com>

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


       reply	other threads:[~2015-04-14 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150412134049.GB2759@localhost.localdomain>
     [not found] ` <CAH+w=7agsP-OrgOU3FUE01fn5J-9apd2V9FgmCpWR1rf12VoNQ@mail.gmail.com>
2015-04-14 14:58   ` Peter Stephenson [this message]
2015-04-15  2:43     ` Bart Schaefer
2015-04-15  8:35       ` Peter Stephenson

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=20150414155830.029eb84e@pwslap01u.europe.root.pri \
    --to=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).