zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH] Optimization of getarrvalue()
Date: Mon, 14 Nov 2016 21:32:19 +0900	[thread overview]
Message-ID: <D5F098D6-752E-4CEC-92F6-6303BD9B2348@kba.biglobe.ne.jp> (raw)
In-Reply-To: <161109080328.ZM6075@torch.brasslantern.com>

After the following commit

commit a1633e09a761b9135a0a7084d2489d359a004e5a
Author: Peter Stephenson <pws@zsh.org>
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 <TAB>
zsh% mount -t <TAB>

The problem comes from the last line of _sequence:

"${(@)argv[1,minus-1]}" .... "${(@)argv[minus+1,-1]}"

In the case of 'ps -p <TAB>', 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 <TAB>' 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,






  reply	other threads:[~2016-11-14 12:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161108201233epcas1p1e2900e2d67af8b8558ebdb70eb7ad480@epcas1p1.samsung.com>
2016-11-08 20:11 ` Sebastian Gniazdowski
2016-11-08 21:58   ` Bart Schaefer
2016-11-09  7:11   ` Bart Schaefer
2016-11-09 11:42   ` Peter Stephenson
2016-11-09 16:03     ` Bart Schaefer
2016-11-14 12:32       ` Jun T. [this message]
2016-11-14 13:15         ` Jun T.
2016-11-14 13:57         ` Peter Stephenson
2016-11-14 15:35           ` Jun T.
2016-11-14 17:10           ` Bart Schaefer
2016-11-16  7:55             ` Sebastian Gniazdowski
2016-11-15 12:28         ` Peter Stephenson
2016-11-15 19:57         ` Peter Stephenson
2016-11-15 21:11           ` Bart Schaefer
2016-11-16 14:06           ` Jun T.
2016-11-16 16:14             ` Jun T.
2016-11-16 18:50             ` Bart Schaefer
2016-11-21 12:30               ` Jun T.
2016-11-24  0:55                 ` Bart Schaefer
2016-11-24 11:49                   ` Jun T.
2016-11-29  6:11                     ` Array slices that don't exist [was Optimization of getarrvalue()] Bart Schaefer
2016-11-29  9:34                       ` 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=D5F098D6-752E-4CEC-92F6-6303BD9B2348@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).