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

PATCH: Re: BUG: using z parameter expansion flag in a completion function



Felix Rosencrantz wrote:

> There seems to be a bug when using the z parameter expansion flag in
> a completion function:
> host% bindkey -e; autoload -U compinit; compinit -D 
> host% _tst () { compadd --  ${(z)history[1]} }
> host% compdef _tst tst
> host% tst a<TAB>
> 
> Generates many of these error messages:
> 	BUG: attempt to free storage at invalid address

Oops, forgot to save/restore some variables.

The patch moves gotword() into the core, adding functions and
-pointers to save and restore wb/we seemed too silly.

Bye
 Sven

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.5
diff -u -r1.5 hist.c
--- Src/hist.c	2000/05/05 07:42:36	1.5
+++ Src/hist.c	2000/05/23 08:17:59
@@ -2059,6 +2059,7 @@
 bufferwords(LinkList list, char *buf, int *index)
 {
     int num = 0, cur = -1, got = 0, ne = noerrs, ocs = cs;
+    int owb = wb, owe = we, oadx = addedx, ozp = zleparse;
     char *p;
 
     if (!list)
@@ -2131,10 +2132,14 @@
     noaliases = 0;
     strinend();
     inpop();
-    errflag = zleparse = 0;
+    errflag = 0;
+    zleparse = ozp;
     noerrs = ne;
     lexrestore();
     cs = ocs;
+    wb = owb;
+    we = owe;
+    addedx = oadx;
 
     if (index)
 	*index = cur;
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.3
diff -u -r1.3 init.c
--- Src/init.c	2000/04/30 18:51:58	1.3
+++ Src/init.c	2000/05/23 08:17:59
@@ -1025,8 +1025,6 @@
 /**/
 mod_export ZleVoidFn trashzleptr = noop_function;
 /**/
-mod_export ZleVoidFn gotwordptr = noop_function;
-/**/
 mod_export ZleVoidFn refreshptr = noop_function;
 /**/
 mod_export ZleVoidIntFn spaceinlineptr = noop_function_int;
@@ -1036,7 +1034,6 @@
 #else /* !LINKED_XMOD_zshQszle */
 
 mod_export ZleVoidFn trashzleptr = noop_function;
-mod_export ZleVoidFn gotwordptr = noop_function;
 mod_export ZleVoidFn refreshptr = noop_function;
 mod_export ZleVoidIntFn spaceinlineptr = noop_function_int;
 # ifdef UNLINKED_XMOD_zshQszle
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.5
diff -u -r1.5 lex.c
--- Src/lex.c	2000/05/04 10:44:25	1.5
+++ Src/lex.c	2000/05/23 08:18:00
@@ -93,6 +93,11 @@
 /**/
 mod_export int addedx;
 
+/* wb and we hold the beginning/end position of the word we are completing. */
+
+/**/
+mod_export int wb, we;
+
 /* 1 if aliases should not be expanded */
  
 /**/
@@ -1481,6 +1486,19 @@
     }
 #endif
     return 0;
+}
+
+/* Called below to report word positions. */
+
+/**/
+mod_export void
+gotword(void)
+{
+    we = ll + 1 - inbufct + (addedx == 2 ? 1 : 0);
+    if (cs <= we) {
+	wb = ll - wordbeg + addedx;
+	zleparse = 0;
+    }
 }
 
 /* expand aliases and reserved words */
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.9
diff -u -r1.9 zsh.h
--- Src/zsh.h	2000/05/15 18:48:21	1.9
+++ Src/zsh.h	2000/05/23 08:18:00
@@ -30,7 +30,6 @@
 #define trashzle()      trashzleptr()
 #define zleread(X,Y,H)  zlereadptr(X,Y,H)
 #define spaceinline(X)  spaceinlineptr(X)
-#define gotword()       gotwordptr()
 #define zrefresh()      refreshptr()
 
 #define compctlread(N,A,O,R) compctlreadptr(N,A,O,R)
Index: Src/Zle/zle.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle.h,v
retrieving revision 1.1.1.11
diff -u -r1.1.1.11 zle.h
--- Src/Zle/zle.h	1999/11/08 19:39:05	1.1.1.11
+++ Src/Zle/zle.h	2000/05/23 08:18:00
@@ -30,7 +30,6 @@
 #undef trashzle
 #undef zleread
 #undef spaceinline
-#undef gotword
 #undef zrefresh
 
 typedef struct widget *Widget;
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.2
diff -u -r1.2 zle_main.c
--- Src/Zle/zle_main.c	2000/05/02 15:52:44	1.2
+++ Src/Zle/zle_main.c	2000/05/23 08:18:01
@@ -1039,7 +1039,6 @@
 {
     /* Set up editor entry points */
     trashzleptr = trashzle;
-    gotwordptr = gotword;
     refreshptr = zrefresh;
     spaceinlineptr = spaceinline;
     zlereadptr = zleread;
@@ -1116,7 +1115,6 @@
 
     /* editor entry points */
     trashzleptr = noop_function;
-    gotwordptr = noop_function;
     refreshptr = noop_function;
     spaceinlineptr = noop_function_int;
     zlereadptr = fallback_zleread;
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.11
diff -u -r1.11 zle_tricky.c
--- Src/Zle/zle_tricky.c	2000/05/22 14:50:08	1.11
+++ Src/Zle/zle_tricky.c	2000/05/23 08:18:01
@@ -58,11 +58,6 @@
 /**/
 mod_export char **clwords;
 
-/* wb and we hold the beginning/end position of the word we are completing. */
-
-/**/
-mod_export int wb, we;
-
 /* offs is the cursor position within the tokenized *
  * current word after removing nulargs.             */
 
@@ -1690,19 +1685,6 @@
     popheap();
 
     return ret;
-}
-
-/* This is called from the lexer to give us word positions. */
-
-/**/
-void
-gotword(void)
-{
-    we = ll + 1 - inbufct + (addedx == 2 ? 1 : 0);
-    if (cs <= we) {
-	wb = ll - wordbeg + addedx;
-	zleparse = 0;
-    }
 }
 
 /**/

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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