zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayne@clari.net>
To: Bart Schaefer <schaefer@candle.brasslantern.com>
Cc: zsh-workers@sunsite.auc.dk
Subject: Re: History still coredumping after "print -s" during completion
Date: Mon, 29 May 2000 14:30:52 -0700 (PDT)	[thread overview]
Message-ID: <Pine.GSO.4.21.0005291411310.22792-100000@house.clari.net> (raw)
In-Reply-To: <1000506173443.ZM6244@candle.brasslantern.com>

On Sat, 6 May 2000, Bart Schaefer wrote:
> This [crash] is with Wayne's 11171.  Is this just part of "the
> lines are not immediately available yet" or is it a different bug?

It's a different bug, but the two bugs are somewhat related.

Here's what's going on.  First, "print -s" is adding a line to the
history with zle active, and when zle gets control back, it now has
the wrong histline set.  This makes it think that the current edit
buffer is associated with the newly-added history line, and thus
you can ^N down past the current line (which you shouldn't be able
to do in this scenario) and you won't see the real newly-added
history line until the editing is complete.

Combine this with a bug in the code called by Ctrl-N that was failing
to initialize the "curline" structure in some instances, and we have
the crash you found.

The appended patch (which is based on the latest cvs source) changes
a few things:

 + It gets rid of quietgethistent() since the difference between
   quietgethistent() and the regular gethistent() had nothing to do
   with silence.

 + It makes both gethistent() and movehistent() ensure that, if we're
   at the "curline" entry, we have accurate values set (this used to
   only happen when quietgethistent() was called).

 + It tweaks execzlefunc() so that, when it calls a completion
   widget, it ensures that if we were at curline, we're still at
   curline.  This change assumes that completion never causes us to
   change to a different history line.  If this is not true, we'll
   need a different fix.  The easiest might be to add an external zle
   function that allows "print -s" to tweak the value of "histline".

With these changes, your example now works right:

% ls <C-x?><C-n>

This will now fail to move downward (since there's nowhere to go),
and a <C-p> will show you the newly-added history line.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
@@ -853,6 +853,7 @@
 	if (!(he->flags & xflags))
 	    n--;
     }
+    checkcurline(he);
     return he;
 }
 
@@ -880,27 +881,26 @@
 	return NULL;
 
     if (ev - hist_ring->down->histnum < hist_ring->histnum - ev) {
-	for (he = hist_ring->down; he->histnum <= ev; he = he->down) {
-	    if (he->histnum == ev)
-		return he;
-	}
-	if (nearmatch < 0)
-	    return up_histent(he);
-	if (nearmatch > 0)
-	    return he;
+	for (he = hist_ring->down; he->histnum < ev; he = he->down) ;
+	if (nearmatch == 0) {
+	    if (he->histnum != ev)
+		return NULL;
+	}
+	else if (nearmatch < 0 && (he = up_histent(he)) == NULL)
+	    return NULL;
     }
     else {
-	for (he = hist_ring; he->histnum >= ev; he = he->up) {
-	    if (he->histnum == ev)
-		return he;
+	for (he = hist_ring; he->histnum > ev; he = he->up) ;
+	if (nearmatch == 0) {
+	    if (he->histnum != ev)
+		return NULL;
 	}
-	if (nearmatch < 0)
-	    return he;
-	if (nearmatch > 0)
-	    return down_histent(he);
+	else if (nearmatch > 0 && (he = down_histent(he)) == NULL)
+	    return NULL;
     }
 
-    return NULL;
+    checkcurline(he);
+    return he;
 }
 
 /**/
@@ -1452,22 +1452,21 @@
 }
 
 /**/
-mod_export Histent
-quietgethistent(int ev, int nearmatch)
+mod_export void
+checkcurline(Histent he)
 {
-    if (ev == curhist && (histactive & HA_ACTIVE)) {
+    if (he->histnum == curhist && (histactive & HA_ACTIVE)) {
 	curline.text = chline;
 	curline.nwords = chwordpos/2;
 	curline.words = chwords;
     }
-    return gethistent(ev, nearmatch);
 }
 
 /**/
 mod_export Histent
 quietgethist(int ev)
 {
-    return quietgethistent(ev, GETHIST_EXACT);
+    return gethistent(ev, GETHIST_EXACT);
 }
 
 /**/
Index: Src/Modules/parameter.c
@@ -1059,7 +1059,7 @@
 {
     struct param pm;
     int i = addhistnum(curhist, -1, HIST_FOREIGN);
-    Histent he = quietgethistent(i, GETHIST_UPWARD);
+    Histent he = gethistent(i, GETHIST_UPWARD);
     char buf[40];
 
     pm.flags = PM_SCALAR | PM_READONLY;
@@ -1096,7 +1096,7 @@
     LinkList l = newlinklist(), ll;
     LinkNode n;
     int i = addhistnum(curhist, -1, HIST_FOREIGN), iw;
-    Histent he = quietgethistent(i, GETHIST_UPWARD);
+    Histent he = gethistent(i, GETHIST_UPWARD);
 
     ll = bufferwords(NULL, NULL, NULL);
     for (n = firstnode(ll); n; incnode(n))
Index: Src/Zle/compctl.c
@@ -3688,7 +3688,7 @@
 	Patprog pprogc = NULL;
 	char *e, *h, hpatsav;
 	int i = addhistnum(curhist,-1,HIST_FOREIGN), n = cc->hnum;
-	Histent he = quietgethistent(i, GETHIST_UPWARD);
+	Histent he = gethistent(i, GETHIST_UPWARD);
 
 	/* Parse the pattern, if it isn't the null string. */
 	if (*(cc->hpat)) {
Index: Src/Zle/zle_main.c
@@ -641,8 +641,11 @@
 	if(!(wflags & ZLE_LASTCOL))
 	    lastcol = -1;
 	if (wflags & WIDGET_NCOMP) {
+	  int atcurhist = histline == curhist;
 	    compwidget = w;
 	    ret = completecall(args);
+	    if (atcurhist)
+		histline = curhist;
 	} else
 	    ret = w->u.fn(args);
 	if (!(wflags & ZLE_NOTCOMMAND))
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


  reply	other threads:[~2000-05-29 21:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-06 17:34 Bart Schaefer
2000-05-29 21:30 ` Wayne Davison [this message]
2000-05-29 22:47   ` 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=Pine.GSO.4.21.0005291411310.22792-100000@house.clari.net \
    --to=wayne@clari.net \
    --cc=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).