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

Re: Problem with menu-completion



"Anonymous bin ich" wrote:
> 1. Type any command which will have multiple completion choices. Press
> TAB for scrolling through them. (ex, for fvwm, type "fvw" and then
> press tab)
> 2. Keep scrolling. To increase the speed, you may want to never leave
> the TAB key.
> 3. The speed of scrolling steadily decreases, while CPU usage steadily
> increases.
> 
> 4. Now delete everything from the command line, and type "xr" (for
> another completion list), and press TAB.
> 5. The problem still exists.
> 6. Delete everything and press enter (or press ^C) for another prompt.
> 7. The problem disappears.

As I guessed, the problem is the use of heap memory.  Here's a partial
fix: the heap is now freed after every completed editor command.  This
should work OK since individual editor commands are expected to be
self-contained (if it's not OK, something is making icky assumptions).
This removes the memory still present at step 5., although actually
it'll happen as soon as you stop the menu selection.

It should be possible to fiddle with menu selection (the big for-loop in
domenuselect() in complist.c) such that it doesn't accumulate heap
memory over iterations and so it can be freed in the same way, so that
you don't pick it up when scrolling.  However, that'll take a little
more thought (I hope not too much more).

(All but the middle two hunks here are cosmetic.)

Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.72
diff -u -r1.72 compresult.c
--- Src/Zle/compresult.c	22 Aug 2007 17:24:10 -0000	1.72
+++ Src/Zle/compresult.c	14 Feb 2008 15:03:15 -0000
@@ -1200,6 +1200,7 @@
 	showinglist = -2;
 	return;
     }
+
     /* Otherwise go to the next match in the array... */
     do {
 	if (!*++(minfo.cur)) {
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.102
diff -u -r1.102 zle_main.c
--- Src/Zle/zle_main.c	18 Dec 2007 10:42:37 -0000	1.102
+++ Src/Zle/zle_main.c	14 Feb 2008 15:03:16 -0000
@@ -1000,6 +1000,8 @@
     FD_ZERO(&foofd);
 #endif
 
+    pushheap();
+
     /*
      * A widget function may decide to exit the shell.
      * We never exit directly from functions, to allow
@@ -1070,7 +1072,11 @@
 #endif
 	    if (!kungetct)
 		zrefresh();
+
+	freeheap();
     }
+
+    popheap();
 }
 
 /* Read a line.  It is returned metafied. */
@@ -1786,12 +1792,19 @@
 
 /**/
 mod_export struct hookdef zlehooks[] = {
+    /* LISTMATCHESHOOK */
     HOOKDEF("list_matches", NULL, 0),
+    /* COMPLETEHOOK */
     HOOKDEF("complete", NULL, 0),
+    /* BEFORECOMPLETEHOOK */
     HOOKDEF("before_complete", NULL, 0),
+    /* AFTERCOMPLETEHOOK */
     HOOKDEF("after_complete", NULL, 0),
+    /* ACCEPTCOMPHOOK */
     HOOKDEF("accept_completion", NULL, 0),
+    /* REVERSEMENUHOOK */
     HOOKDEF("reverse_menu", NULL, 0),
+    /* INVALIDATELISTHOOK */
     HOOKDEF("invalidate_list", NULL, 0),
 };
 
-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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