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

Re: _complete_debug crashes in zsh_directory_name



On Wed, 3 Aug 2011 16:53:40 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 3 August 2011 11:10, Peter Stephenson <Peter.Stephenson@xxxxxxx> wrote:
> > On Wed, 3 Aug 2011 05:26:53 +0200
> > Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> >> Any ideas? It doesn't crash if I don't have the zsh_directory_name function.
> >
> > This seems to depend on your set-up, so there's nothing I can do without
> > more clues.  I'm wondering if the wrapper function is getting called at
> > multiple levels in a way that's confusing it, but that's pure guess.
> > It appears to have something to do with some prompt but simply putting
> > %~ in all my prompts and letting that call the zsh_directory_name hooks
> > didn't seem to do anything.
> 
> This is enough to reproduce the crash for me:
> % zsh -f
> localhost% PS1=%~
> ~autoload -U compinit
> ~compinit -D
> ~zsh_directory_name() { }
> ~<press C-x?>
> _complete_debug:9: failed to close file descriptor 3: bad file descriptor
> zsh:1: failed to close file descriptor 3: bad file descriptor
> zsh: segmentation fault  zsh -f

I did manage to get this, though as it dumps me into the uncommented
completion code with it's well-known attitudes to code encapsulation and
variable modularity it's not very enlightening.

I wonder if we should simply be turning off completion nastiness for
hook functions, which are run isolated from the general function
environment.  This could just be working around a problem rather than
fixing it, but we'll probably never know.

Hmm... the tidied-up function doesn't use a trap, that may be
significant.  So turning it off for traps might be a good idea, too.
Having two nested levels of functions that aren't part of the normal
call sequence might have been the trigger.

I think the wrapper stuff is just to do magic things with completion
parameters on change of function level, isn't it?  I've never really got
my head round it.

Possibly this could be better done with use of sfcontext in the
completion code but, again, I don't suppose anyone's ever going to find
out.

Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.62
diff -p -u -r1.62 signals.c
--- Src/signals.c	15 Jun 2011 15:38:14 -0000	1.62
+++ Src/signals.c	3 Aug 2011 15:31:16 -0000
@@ -1184,7 +1184,7 @@ dotrapargs(int sig, int *sigtr, void *si
     traplocallevel = locallevel;
     runhookdef(BEFORETRAPHOOK, NULL);
     if (*sigtr & ZSIG_FUNC) {
-	int osc = sfcontext;
+	int osc = sfcontext, old_incompfunc = incompfunc;
 	HashNode hn = gettrapnode(sig, 0);
 
 	args = znewlinklist();
@@ -1210,8 +1210,10 @@ dotrapargs(int sig, int *sigtr, void *si
 	trapisfunc = isfunc = 1;
 
 	sfcontext = SFC_SIGNAL;
+	incompfunc = 0;
 	doshfunc((Shfunc)sigfn, args, 1);
 	sfcontext = osc;
+	incompfunc= old_incompfunc;
 	freelinklist(args, (FreeFunc) NULL);
 	zsfree(name);
     } else {
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.260
diff -p -u -r1.260 utils.c
--- Src/utils.c	25 Jul 2011 10:20:09 -0000	1.260
+++ Src/utils.c	3 Aug 2011 15:31:16 -0000
@@ -40,6 +40,11 @@ mod_export char *scriptname;     /* is s
 /**/
 mod_export char *scriptfilename;
 
+/* != 0 if we are in a new style completion function */
+
+/**/
+mod_export int incompfunc;
+
 #ifdef MULTIBYTE_SUPPORT
 struct widechar_array {
     wchar_t *chars;
@@ -1232,8 +1237,10 @@ callhookfunc(char *name, LinkList lnklst
 	 * to a list of jobs generated in a hook.
 	 */
     int osc = sfcontext, osm = stopmsg, stat = 1, ret = 0;
+    int old_incompfunc = incompfunc;
 
     sfcontext = SFC_HOOK;
+    incompfunc = 0;
 
     if ((shfunc = getshfunc(name))) {
 	ret = doshfunc(shfunc, lnklst, 1);
@@ -1262,6 +1269,7 @@ callhookfunc(char *name, LinkList lnklst
 
     sfcontext = osc;
     stopmsg = osm;
+    incompfunc = old_incompfunc;
 
     if (retval)
 	*retval = ret;
@@ -3216,7 +3224,7 @@ getshfunc(char *nam)
 char **
 subst_string_by_func(Shfunc func, char *arg1, char *orig)
 {
-    int osc = sfcontext, osm = stopmsg;
+    int osc = sfcontext, osm = stopmsg, old_incompfunc = incompfunc;
     LinkList l = newlinklist();
     char **ret;
 
@@ -3225,6 +3233,7 @@ subst_string_by_func(Shfunc func, char *
 	addlinknode(l, arg1);
     addlinknode(l, orig);
     sfcontext = SFC_SUBST;
+    incompfunc = 0;
 
     if (doshfunc(func, l, 1))
 	ret = NULL;
@@ -3233,6 +3242,7 @@ subst_string_by_func(Shfunc func, char *
 
     sfcontext = osc;
     stopmsg = osm;
+    incompfunc = old_incompfunc;
     return ret;
 }
 
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.129
diff -p -u -r1.129 zle_main.c
--- Src/Zle/zle_main.c	12 Jul 2011 08:37:11 -0000	1.129
+++ Src/Zle/zle_main.c	3 Aug 2011 15:31:16 -0000
@@ -53,11 +53,6 @@ mod_export int zlecs, zlell;
 /**/
 mod_export int incompctlfunc;
 
-/* != 0 if we are in a new style completion function */
-
-/**/
-mod_export int incompfunc;
-
 /* != 0 if completion module is loaded */
 
 /**/

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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