zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list),
	"Anonymous bin ich" <ichbinanon@gmail.com>
Subject: Re: Problem with menu-completion
Date: Thu, 14 Feb 2008 15:09:58 +0000	[thread overview]
Message-ID: <200802141509.m1EF9wdm019318@news01.csr.com> (raw)
In-Reply-To: <82839db60801291122n6db4ae54r2218310f2244ed5f@mail.gmail.com>

"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@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


       reply	other threads:[~2008-02-14 15:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <82839db60801291122n6db4ae54r2218310f2244ed5f@mail.gmail.com>
2008-02-14 15:09 ` Peter Stephenson [this message]
2008-02-15 21:54   ` Peter Stephenson

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=200802141509.m1EF9wdm019318@news01.csr.com \
    --to=pws@csr.com \
    --cc=ichbinanon@gmail.com \
    --cc=zsh-workers@sunsite.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).