From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26619 invoked by alias); 14 Nov 2016 12:32:27 -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: 39937 Received: (qmail 25635 invoked from network); 14 Nov 2016 12:32:27 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-expgw.biglobe.ne.jp by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(133.208.98.3):SA:0(-2.9/5.0):. Processed in 1.08481 secs); 14 Nov 2016 12:32:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spf01.biglobe.ne.jp designates 133.208.98.3 as permitted sender) X-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: [PATCH] Optimization of getarrvalue() From: "Jun T." In-Reply-To: <161109080328.ZM6075@torch.brasslantern.com> Date: Mon, 14 Nov 2016 21:32:19 +0900 Content-Transfer-Encoding: 7bit Message-Id: References: <1478635899.1897979.781551353.05792438@webmail.messagingengine.com> <20161109114207.6b929440@pwslap01u.europe.root.pri> <161109080328.ZM6075@torch.brasslantern.com> To: "zsh-workers@zsh.org" X-Mailer: Apple Mail (2.1510) X-Biglobe-Spnum: 51458 After the following commit commit a1633e09a761b9135a0a7084d2489d359a004e5a Author: Peter Stephenson Date: Wed Nov 9 11:54:57 2016 +0000 39886 based on 39877: Optimise arrdup to arrdup_max. I'm having a problem with (some of) the completions which use _sequence. For example, the following will produce bogus output: zsh% ps -p zsh% mount -t The problem comes from the last line of _sequence: "${(@)argv[1,minus-1]}" .... "${(@)argv[minus+1,-1]}" In the case of 'ps -p ', argv=( _pids ) and minus=2. We expect that, since it has a (@) flag, "${(@)argv[3,-1]}" is entirely removed from the command line. This is indeed the case before the commit: zsh% a=( foo ) zsh% nargs () { print $#@ } zsh% nargs "${a[3,-1]}" 1 zsh% nargs "${(@)a[3,-1]}" 0 But after the commit a1633e0, both output 1. This means an empty string '' is passed to _pids and then down to compadd. I still don't understand why compadd is confused by '' in its arguments. The patch below seems to make it work as before the commit a1633e0; 'ps -p ' etc. works again. BUT: The original (before a1633e0) behavior is already quite confusing to me. For example, zsh% nargs "${(@)a[i]}" will output 0 only for i=0. On the other hand zsh% nargs "${(@)a[i,i]}" will output 0 for i=0 and 2. If I replace arrlen_lt(s, v->start) by arrlen_le(s, v->start) (which may look reasonable since the array s[] is 0-based) then nargs "${(@)a[i,i]}" will output 0 only for i=0. But then "make check" fails in two tests (D04parameter and Y01completion). diff --git a/Src/params.c b/Src/params.c index 6f587a3..eee1cb8 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2292,10 +2292,11 @@ getarrvalue(Value v) v->end += arrlen(s) + 1; /* Null if 1) array too short, 2) index still negative */ - if (arrlen_lt(s, v->start) || v->start < 0) { - s = arrdup_max(nular, 1); - } else if (v->end <= v->start) { + if (v->end <= v->start) { s = arrdup_max(nular, 0); + } + else if (arrlen_lt(s, v->start) || v->start < 0) { + s = arrdup_max(nular, 1); } else { /* Copy to a point before the end of the source array: * arrdup_max will copy at most v->end - v->start elements,