Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Removing aliases from history, 2015 style



On Fri, 27 Mar 2015 10:06:48 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 25 Mar 2015 19:42:22 +0100
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > FWIW, I don't use !-expansion at all, but who knows, maybe that'll
> > make it more likely I find the corner case.
> 
> You do use HISTLEXWORDS, however, so you might notice the following:
> it looks like I've managed to make that work less well when
> interrupted.  If I ^C during the history read I get
> 
> 
> ^CWarning: backing up wrong character.
>...
>  hist.c:3524: bad wordsplit reading history: ((print foo); print bar)
>...

Various changes here.  Backing  up the wrong character is because
sometimes we "goto brk" when there's an error; if there is, it looks
benign to return LEXERR at that point.  Note we do this from lots of
places and generally set "peek = LEXERR" but don't worry about fixing up
"c" --- but clearly "c" has become irrelevant.  So I didn't try to muck
around fixing up "c" in the case in question, which I think is a return
from cmd_or_math_sub() where we don't have a useful character.

In history, if there was an error buffering words, don't try to do the
word split.

Those two seem to fix the specific problems above.  In both cases as we
were in an inner loop and depended on the previous processing being
successful it seemed reasonable to be sensitive to both bits of
errflag.

The other two are in the history reading code.  They make it more
sensitive to interruption by stopping loops over words and lines in that
case.  Here it's specific to the interruption rather than any error.

diff --git a/Src/hist.c b/Src/hist.c
index 990e609..185d0a0 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2604,6 +2604,8 @@ readhistfile(char *fn, int err, int readflags)
 	     */
 	    if (uselex || remeta)
 		freeheap();
+	    if (errflag & ERRFLAG_INT)
+		break;
 	}
 	if (start && readflags & HFILE_USE_OPTIONS) {
 	    zsfree(lasthist.text);
@@ -3331,7 +3333,7 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
 	    got = 1;
 	    cur = num - 1;
 	}
-    } while (tok != ENDINPUT && tok != LEXERR);
+    } while (tok != ENDINPUT && tok != LEXERR && !(errflag & ERRFLAG_INT));
     if (buf && tok == LEXERR && tokstr && *tokstr) {
 	int plen;
 	untokenize((p = dupstring(tokstr)));
@@ -3408,6 +3410,8 @@ histsplitwords(char *lineptr, short **wordsp, int *nwordsp, int *nwordposp,
 
 	wordlist = bufferwords(NULL, lineptr, NULL,
 			       LEXFLAGS_COMMENTS_KEEP);
+	if (errflag)
+	    return;
 	nwords_max = 2 * countlinknodes(wordlist);
 	if (nwords_max > nwords) {
 	    *nwordsp = nwords = nwords_max;
diff --git a/Src/lex.c b/Src/lex.c
index 5fed2be..184a54b 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1345,6 +1345,8 @@ gettokstr(int c, int sub)
 	    break;
     }
   brk:
+    if (errflag)
+	return LEXERR;
     hungetc(c);
     if (unmatched)
 	zerr("unmatched %c", unmatched);



Messages sorted by: Reverse Date, Date, Thread, Author