From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: Crash when capturing command output in completion
Date: Fri, 16 Jan 2015 12:57:12 +0000 [thread overview]
Message-ID: <20150116125712.3ef52e96@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150116094436.7803b467@pwslap01u.europe.root.pri>
Only very lightly tested and so probably partial fix --- however, I'll
commit this because (i) I'm fairly sure it's going in the right
direction (ii) it does work in some cases and hence the shell is less
crash-prone (iii) I get to insert a whiny message about the horrible
interface which always improves my morale.
The first hunk is just a bit of clarity about what belongs to the
lex/zle non-interface for future reference.
I'll remove the ZSH_OLD_SKIPCOMM code when we have a final fix for
this (though it's not actually doing any harm).
pws
diff --git a/Src/lex.c b/Src/lex.c
index b0cd86c..96da1cb 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -90,6 +90,12 @@ int inalmore;
int nocorrect;
/*
+ * TBD: the following exported variables are part of the non-interface
+ * with ZLE for completion. They are poorly named and the whole
+ * scheme is incredibly brittle. One piece of robustness is applied:
+ * the variables are only set if LEXFLAGS_ZLE is set. Improvements
+ * should therefore concentrate on areas with this flag set.
+ *
* Cursor position and line length in zle when the line is
* metafied for access from the main shell.
*/
@@ -113,6 +119,16 @@ mod_export int addedx;
/**/
mod_export int wb, we;
+/**/
+mod_export int wordbeg;
+
+/**/
+mod_export int parbegin;
+
+/**/
+mod_export int parend;
+
+
/* 1 if aliases should not be expanded */
/**/
@@ -134,15 +150,6 @@ mod_export int noaliases;
/**/
mod_export int lexflags;
-/**/
-mod_export int wordbeg;
-
-/**/
-mod_export int parbegin;
-
-/**/
-mod_export int parend;
-
/* don't recognize comments */
/**/
@@ -585,7 +592,8 @@ gettok(void)
if (lexstop)
return (errflag) ? LEXERR : ENDINPUT;
isfirstln = 0;
- wordbeg = inbufct - (qbang && c == bangchar);
+ if ((lexflags & LEXFLAGS_ZLE))
+ wordbeg = inbufct - (qbang && c == bangchar);
hwbegin(-1-(qbang && c == bangchar));
/* word includes the last character read and possibly \ before ! */
if (dbparens) {
@@ -1813,6 +1821,78 @@ zshlex_raw_back(void)
static int
skipcomm(void)
{
+#ifdef ZSH_OLD_SKIPCOMM
+ int pct = 1, c, start = 1;
+
+ cmdpush(CS_CMDSUBST);
+ SETPARBEGIN
+ c = Inpar;
+ do {
+ int iswhite;
+ add(c);
+ c = hgetc();
+ if (itok(c) || lexstop)
+ break;
+ iswhite = inblank(c);
+ switch (c) {
+ case '(':
+ pct++;
+ break;
+ case ')':
+ pct--;
+ break;
+ case '\\':
+ add(c);
+ c = hgetc();
+ break;
+ case '\'': {
+ int strquote = lexbuf.ptr[-1] == '$';
+ add(c);
+ STOPHIST
+ while ((c = hgetc()) != '\'' && !lexstop) {
+ if (c == '\\' && strquote) {
+ add(c);
+ c = hgetc();
+ }
+ add(c);
+ }
+ ALLOWHIST
+ break;
+ }
+ case '\"':
+ add(c);
+ while ((c = hgetc()) != '\"' && !lexstop)
+ if (c == '\\') {
+ add(c);
+ add(hgetc());
+ } else
+ add(c);
+ break;
+ case '`':
+ add(c);
+ while ((c = hgetc()) != '`' && !lexstop)
+ if (c == '\\')
+ add(c), add(hgetc());
+ else
+ add(c);
+ break;
+ case '#':
+ if (start) {
+ add(c);
+ while ((c = hgetc()) != '\n' && !lexstop)
+ add(c);
+ iswhite = 1;
+ }
+ break;
+ }
+ start = iswhite;
+ }
+ while (pct);
+ if (!lexstop)
+ SETPAREND
+ cmdpop();
+ return lexstop;
+#else
char *new_tokstr;
int new_lexstop, new_lex_add_raw;
struct lexbufstate new_lexbuf;
@@ -1860,6 +1940,18 @@ skipcomm(void)
tokstr_raw = new_tokstr;
lexbuf_raw = new_lexbuf;
lex_add_raw = new_lex_add_raw;
+ /*
+ * Don't do any ZLE specials down here: they're only needed
+ * when we return the string from the recursive parse.
+ * (TBD: this probably means we should be initialising lexflags
+ * more consistently.)
+ *
+ * Note that in that case we're still using the ZLE line reading
+ * function at the history layer --- this is consistent with the
+ * intention of maintaining the history and input layers across
+ * the recursive parsing.
+ */
+ lexflags &= ~LEXFLAGS_ZLE;
if (!parse_event(OUTPAR) || tok != OUTPAR)
lexstop = 1;
@@ -1907,4 +1999,5 @@ skipcomm(void)
cmdpop();
return lexstop;
+#endif
}
next prev parent reply other threads:[~2015-01-16 12:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-15 19:34 Vin Shelton
2015-01-15 21:53 ` Bart Schaefer
2015-01-15 23:53 ` Vin Shelton
2015-01-16 0:27 ` Bart Schaefer
2015-01-16 3:11 ` Vin Shelton
2015-01-16 3:17 ` Vin Shelton
2015-01-16 4:43 ` Bart Schaefer
2015-01-16 5:20 ` Bart Schaefer
2015-01-16 9:44 ` Peter Stephenson
2015-01-16 12:57 ` Peter Stephenson [this message]
2015-01-16 16:18 ` Bart Schaefer
2015-01-16 16:25 ` Bart Schaefer
2015-01-16 18:04 ` Peter Stephenson
2015-01-16 18:58 ` Bart Schaefer
2015-01-16 19:16 ` Bart Schaefer
2015-01-16 20:05 ` Peter Stephenson
2015-01-16 19:19 ` Ray Andrews
2015-01-16 6:43 ` Ray Andrews
2015-01-16 7:49 ` Bart Schaefer
2015-01-16 16:21 ` Ray Andrews
2015-01-16 16:34 ` Bart Schaefer
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=20150116125712.3ef52e96@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--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).