From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8441 invoked by alias); 12 Nov 2015 14:19:37 -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: 37096 Received: (qmail 28237 invoked from network); 12 Nov 2015 14:19:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-37-56449ff3952d Date: Thu, 12 Nov 2015 14:19:27 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: PATCH: nested ${(P)} (formerly SHWORDSPLIT and leading spaces) Message-id: <20151112141927.294984d9@pwslap01u.europe.root.pri> In-reply-to: <20151112094628.7345465b@pwslap01u.europe.root.pri> References: <87a8qr75za.fsf@gmail.com> <20151106170007.5196bd5e@pwslap01u.europe.root.pri> <20151107174255.74054b28@ntlworld.com> <151107114314.ZM24285@torch.brasslantern.com> <20151108181833.574cf0d6@ntlworld.com> <20151111174911.4384bf73@pwslap01u.europe.root.pri> <20151111215541.4a1fb149@ntlworld.com> <20151112094628.7345465b@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xy7qf57uEGcy4wmVxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mn4s/MNWME2gYs8phwbGb9xdjBwcEgImEq+f+HcxcgKZYhIX 7q1n62Lk4hASWMoosW79PiYIZwaTxP+djVDONkaJh6ca2UFaWARUJW4+3s0MYrMJGEpM3TSb EcQWERCXOLv2PAuILSzgLXH7+G+wOK+AvcS8tXfB6jkFHCS+LO+GGvqZSWJJA0QDv4C+xNW/ n5ggbrKXmHnlDFSzoMSPyffAapgFtCQ2b2tihbDlJTaveQs2VEhAXeLG3d3sExiFZiFpmYWk ZRaSlgWMzKsYRVNLkwuKk9JzDfWKE3OLS/PS9ZLzczcxQoL2yw7GxcesDjEKcDAq8fBOmOkc JsSaWFZcmXuIUYKDWUmENyHNJUyINyWxsiq1KD++qDQntfgQozQHi5I479xd70OEBNITS1Kz U1MLUotgskwcnFINjM48F171H9x0eLHDo2jpXXan5gcaXwzc8UbSIeDK/ssT+6vkH/X+DPm5 +IrJL1/Jo8a1s64Ln96afVNppjjnTTlZbRbjjvx4I1aWY1yKSlW/A+asE/cz/LyxnmVh8H1/ id7srQf9bA+0aDgbmy18/OEc92ehiy/F5rzV92A9srnv30HXNcV/7JVYijMSDbWYi4oTAUkO UttWAgAA On Thu, 12 Nov 2015 09:46:28 +0000 Peter Stephenson wrote: > > + print ${${(P)${(P)${(P)one}}}} > > Well, one thing that isn't natural is that when you're relying on the > new logic you need that extra ${...} wrapper even in the first of the > two cases to trigger the recursive (P). Seems to work via the obvious fix. diff --git a/Src/subst.c b/Src/subst.c index c1369b5..b7f8338 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1741,6 +1741,12 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * simply removed. */ int ms_flags = 0; + /* + * We need to do an extra fetch to honour the (P) flag. + * Complicated by the use of subexpressions that may have + * nested (P) flags. + */ + int fetch_needed; *s++ = '\0'; /* @@ -2325,9 +2331,18 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, s = dyncat(val, s); /* Now behave po-faced as if it was always like that... */ subexp = 0; - } + /* + * If this is a (P) (first test) and at the top level + * (second test) we can't rely on the caller fetching + * the result from the pending aspar. So do it below. + */ + fetch_needed = aspar && !(pf_flags & PREFORK_SUBEXP); + } else + fetch_needed = 0; /* any initial aspar fetch already done */ v = (Value) NULL; - } else if (aspar) { + } else + fetch_needed = aspar; /* aspar fetch still needed */ + if (fetch_needed) { /* * No subexpression, but in any case the value is going * to give us the name of a parameter on which we do diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 6f325d2..210c0d8 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1840,7 +1840,7 @@ local two=three local three=four local -a four=(all these worlds belong to foo) - print ${${(P)${(P)${(P)one}}}} + print ${(P)${(P)${(P)one}}} print ${${(P)${(P)${(P)one}}}[3]} } testfn