From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13015 invoked by alias); 13 Feb 2015 21:27:51 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34536 Received: (qmail 23193 invoked from network); 13 Feb 2015 21:27:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.153.127] X-Spam: 0 X-Authority: v=2.1 cv=dY0O3Bne c=1 sm=1 tr=0 a=39NrsSuza2clQiZR/7fYWQ==:117 a=39NrsSuza2clQiZR/7fYWQ==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=hD80L64hAAAA:8 a=rxqB9gNUrnT4354pQ-cA:9 a=0nOcXQl2ScgOluPL:21 a=oKeR757JFoKEL2bq:21 a=CjuIK1q_8ugA:10 Date: Fri, 13 Feb 2015 21:27:42 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: PATCH: PRINT_EXIT_VALUE with anonymous functions, again Message-ID: <20150213212742.0865023b@ntlworld.com> In-Reply-To: <20150213104849.701782fb@pwslap01u.europe.root.pri> References: <20150213104849.701782fb@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 13 Feb 2015 10:48:49 +0000 Peter Stephenson wrote: > Let's stick with an easy, unambiguously effective fix for this. As > this is local there is no change to the simple / complex nature of the > command. Test, based on the original report, fixing matters arising. pws diff --git a/Src/exec.c b/Src/exec.c index 302e2b5..de6b9c5 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2784,9 +2784,14 @@ execcmd(Estate state, int input, int output, int how, int last1) else text = NULL; - /* Set up special parameter $_ */ - - setunderscore((args && nonempty(args)) ? ((char *) getdata(lastnode(args))) : ""); + /* + * Set up special parameter $_ + * For execfuncdef we may need to take account of an + * anonymous function with arguments. + */ + if (type != WC_FUNCDEF) + setunderscore((args && nonempty(args)) ? + ((char *) getdata(lastnode(args))) : ""); /* Warn about "rm *" */ if (type == WC_SIMPLE && interact && unset(RMSTARSILENT) && @@ -4374,7 +4379,7 @@ execfuncdef(Estate state, Eprog redir_prog) Shfunc shf; char *s = NULL; int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0, ret = 0; - int nfunc = 0; + int nfunc = 0, anon_func = 0; Wordcode beg = state->pc, end; Eprog prog; Patprog *pp; @@ -4460,6 +4465,8 @@ execfuncdef(Estate state, Eprog redir_prog) */ LinkList args; + anon_func = 1; + state->pc = end; end += *state->pc++; args = ecgetlist(state, *state->pc++, EC_DUPTOK, &htok); @@ -4515,6 +4522,8 @@ execfuncdef(Estate state, Eprog redir_prog) shfunctab->addnode(shfunctab, ztrdup(s), shf); } } + if (!anon_func) + setunderscore(""); if (!nfunc && redir_prog) { /* For completeness, shouldn't happen */ freeeprog(redir_prog); diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index cf639fa..42c7b4e 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1670,3 +1670,32 @@ print ${(e)param} 0:Alias expansion in command substitution in parameter evaluation >Expanded in substitution + + a=1 b=2 c=3 + : One; + function { + : Two + echo $_ + print -l $argv + } $_ Three + print -l $_ Four; +0:$_ with anonymous function +>Two +>One +>Three +>Three +>Four + + a=1 b=2 c=3 + : One + function { + : Two + echo $_ + print -l $argv + } + print -l "$_" Four +0:$_ with anonymous function without arguments +>Two +> +> +>Four