zsh-workers
 help / color / mirror / code / Atom feed
* History still coredumping after "print -s" during completion
@ 2000-05-06 17:34 Bart Schaefer
  2000-05-29 21:30 ` Wayne Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2000-05-06 17:34 UTC (permalink / raw)
  To: zsh-workers

This is with Wayne's 11171.  Is this just part of "the lines are not
immediately available yet" or is it a different bug?

Change the "print -zR" in _complete_debug to "print -sR".  Then:

zagzig<2> ls <C-x?><C-n>
Trace output left in /tmp/zsh6093ls2
Completing file
stamp-h.in      Etc/            Test/           config.status*  Src/          
xtrace.err      Completion/     config.cache    Makefile                      
BUILD           Functions/      config.h        stamp-h                       
xtrace.tmp/     Config/         config.log      Doc/                          
zsh: Segmentation fault (core dumped)

(gdb) where
#0  0x80a02c2 in metadiffer (s=0x0, r=0x811aea0 "ls ", len=3)
    at ../../zsh-3.1.6/Src/utils.c:2552
#1  0x80d9741 in zle_goto_hist (ev=2, n=1, skipdups=1)
    at ../../../zsh-3.1.6/Src/Zle/zle_hist.c:492
#2  0x80d8e75 in downhistory (args=0x8100f24)
    at ../../../zsh-3.1.6/Src/Zle/zle_hist.c:266
#3  0x80d8ce9 in downlineorhistory (args=0x8100f24)
    at ../../../zsh-3.1.6/Src/Zle/zle_hist.c:210
#4  0x80decf4 in execzlefunc (func=0x80fed90, args=0x8100f24)
    at ../../../zsh-3.1.6/Src/Zle/zle_main.c:647
#5  0x80de8bd in zleread (lp=0x811ae80 "%m%(#.#.%1v)%h%(#.#.%2v) ", rp=0x0, 
    flags=3) at ../../../zsh-3.1.6/Src/Zle/zle_main.c:564
#6  0x806d03e in inputline () at ../../zsh-3.1.6/Src/input.c:265
#7  0x806cf31 in ingetc () at ../../zsh-3.1.6/Src/input.c:210
#8  0x80663e8 in ihgetc () at ../../zsh-3.1.6/Src/hist.c:242
#9  0x8071e04 in gettok () at ../../zsh-3.1.6/Src/lex.c:621
#10 0x80715a5 in yylex () at ../../zsh-3.1.6/Src/lex.c:337
#11 0x8084cb4 in parse_event () at ../../zsh-3.1.6/Src/parse.c:421
#12 0x806a71f in loop (toplevel=1, justonce=0)
    at ../../zsh-3.1.6/Src/init.c:121
#13 0x804a660 in main (argc=1, argv=0xbffff6a0)
    at ../../zsh-3.1.6/Src/main.c:86

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: History still coredumping after "print -s" during completion
  2000-05-06 17:34 History still coredumping after "print -s" during completion Bart Schaefer
@ 2000-05-29 21:30 ` Wayne Davison
  2000-05-29 22:47   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Wayne Davison @ 2000-05-29 21:30 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

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---


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: History still coredumping after "print -s" during completion
  2000-05-29 21:30 ` Wayne Davison
@ 2000-05-29 22:47   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2000-05-29 22:47 UTC (permalink / raw)
  To: Wayne Davison; +Cc: zsh-workers

On May 29,  2:30pm, Wayne Davison wrote:
} Subject: Re: History still coredumping after "print -s" during completion
}
}  + 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.

Completion shouldn't ever cause us to change to a different history line,
but an ordinary ZLE widget might.

    foo() {
      zle up-line-or-history
      print -s "Hi there"
      zle down-line-or-history
    }
    zle -N foo
    bindkey ^Xj foo

} 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.

Yay!  Thanks, Wayne.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-05-29 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-06 17:34 History still coredumping after "print -s" during completion Bart Schaefer
2000-05-29 21:30 ` Wayne Davison
2000-05-29 22:47   ` Bart Schaefer

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).