From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2935 invoked by alias); 21 May 2018 16:48:58 -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: List-Unsubscribe: X-Seq: 42809 Received: (qmail 28573 invoked by uid 1010); 21 May 2018 16:48:58 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-mqugw.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.100.4):SA:0(-2.6/5.0):. Processed in 1.181558 secs); 21 May 2018 16:48:58 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham 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: | X-Biglobe-Sender: From: "Jun T." Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] (slightly) improve "compset -q" Message-Id: Date: Tue, 22 May 2018 01:08:21 +0900 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) X-Biglobe-Spnum: 60185 The patch below addresses two problems. [1] the 1st hunk. zsh% sh -c 'for (( _sh:1: maximum nested function level reached; increase FUNCNEST? The string passed to the lexer is " for ((x", and the last "x" stands = for the cursor. After finding two tokens "for" and "((", ctxtlex() (line = 1619) returns LEXERR with tokstr=3D"x". Then the execution exits from the 'do = ... while' loop by 'break' at line 1641. This means the block if (!got && !lexflags) {...} (line 1667) is not executed, and this seems to be causing the trouble. In the patch below, the 'break' is simply removed. I *hope* this has no = bad side effects. [2] 2nd and 3rd hunks; I think these are OK. Original problem: users/22958: sh -c '. foo; Current master: workers/42180 (by dana) dana's patch seems to work; my patch just fixes the problem more = cleanly. > 2017/12/28 16:47, dana wrote: >=20 > The problem seems related to the fact that set_comp_sep() (which is = called via > `compset -q` in _cmdstring) removes semi-colons and other = meta-characters from > compwords (the user-land words array), but doesn't decrement = compcurrent (the > user-land CURRENT integer) accordingly. Yes. And what is causing this mismatch is the following: A word is added to the array 'foo' only if there is a tokstr (line = 1663). But the counter 'i' is incremented for every token in the string (line = 1680), so it is not the "number of words before cursor" but the number of = tokens (including separators like SEMI). The patch below fixes this by using countlinknodes(foo). With this fix, I *think* compcurrent will never exceed the number of = words, but I added a DUPTS warning in case something still goes wrong. # I'm preparing another patch for "compset -q", but it is far more = subtle and will # be posted separately, after the 1st hunk is found to be OK. diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index c3b971e0d..f733e0ee5 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1638,7 +1638,7 @@ set_comp_sep(void) p[-1] =3D '\0'; } } - if (tok =3D=3D ENDINPUT || tok =3D=3D LEXERR) + if (tok =3D=3D ENDINPUT) break; if (tokstr && *tokstr) { for (p =3D tokstr; dq && *p; p++) { @@ -1667,7 +1667,7 @@ set_comp_sep(void) if (!got && !lexflags) { DPUTS(!p, "no current word in substr"); got =3D 1; - cur =3D i; + cur =3D countlinknodes(foo) - 1; /* cur is 0 offset */ swb =3D wb - 1 - dq - sq - dolq; swe =3D we - 1 - dq - sq - dolq; sqq =3D lsq; @@ -1902,7 +1902,10 @@ set_comp_sep(void) untokenize(p); } /* The current position shouldn't exceed the new word count */ - compcurrent =3D cur + 1 > i ? i : cur + 1; + if ((compcurrent =3D cur + 1) > i) { + DPUTS2(1, "compcurrent=3D%d > number_of_words=3D%d", = compcurrent, i); + compcurrent =3D i; + } compwords[i] =3D NULL; } instring =3D ois;