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

Re: PATCH: 3.1.5-pws-8: setting duplicate elements of assoc array



Peter Stephenson wrote:

> While doing this, I discovered two other bugs which I haven't fixed:
> 
> 1)
> % __foo() { local list; list=(a b); complist -y '$list' -k list; }
> % defcomp __foo foo
> % foo ^D
> <random junk printed>

The problem was (of course) that the code used the array returned by
get*param() directly without copying it.

> I don't know if it's supposed to work when list is about to go out of
> scope, and there's an easy workaround `-y "($list)"' (provided $list
> doesn't have spaces or commas --- which it actually does in the case I was
> trying, so I seem to be stuck), but it shouldn't print what it did.

I think we should make it work, and it's simple.

> 2)
> % print ${foo%% 
>                 ^ cursor here after space, hit tab, gives
> % print ${foo%% BUG: inbrace == '{' in paramsubst()
> BUG: inbrace == '{' in paramsubst()
> % print ${foo%% 

I forgot to tokenize the '{' and '}'. This makes me think that the
ctokenize() function should be joined with tokenize() even more,
giving tokenize() an extra argument. But I'm reluctant to change every 
call to tokenize()...

I also changed the test in getreal() so that the string returned by
prefork() is not used if it is empty (which was the case in such
situations). This is an incompatible change but previously the
`${foo%% ' disappeared and one got normal completion for an empty
prefix. Now the string typed so far is kept and completion is tried
with it as a prefix.

Bye
 Sven

--- os/Zle/zle_tricky.c	Thu Feb 18 15:57:34 1999
+++ Src/Zle/zle_tricky.c	Fri Feb 19 09:40:22 1999
@@ -4559,7 +4559,8 @@
     addlinknode(l, dupstring(str));
     prefork(l, 0);
     noerrs = ne;
-    if (!errflag && nonempty(l))
+    if (!errflag && nonempty(l) &&
+	((char *) peekfirst(l)) && ((char *) peekfirst(l))[0])
 	return dupstring(peekfirst(l));
     errflag = 0;
 
@@ -4991,11 +4991,13 @@
 	if (*p == '\\')
 	    bslash = 1;
 	else {
-	    if (*p == '$' || *p == '=') {
+	    if (*p == '$' || *p == '=' || *p == '{' || *p == '}') {
 		if (bslash)
 		    p[-1] = Bnull;
 		else
-		    *p = (*p == '$' ? String : Equals);
+		    *p = (*p == '$' ? String :
+			  (*p == '=' ? Equals :
+			   (*p == '{' ? Inbrace : Outbrace)));
 	    }
 	    bslash = 0;
 	}
@@ -6484,15 +6486,17 @@
     } else {
 	/* Otherwise it should be a parameter name. */
 	char **arr = NULL, *val;
-	if (!(arr = getaparam(nam)) && !(arr = gethparam(nam)) &&
-	    (val = getsparam(nam))) {
+
+	if ((arr = getaparam(nam)) || (arr = gethparam(nam)))
+	    return (incompfunc ? arrdup(arr) : arr);
+
+	if ((val = getsparam(nam))) {
 	    arr = (char **)ncalloc(2*sizeof(char *));
 	    arr[0] = val;
 	    arr[1] = NULL;
 	}
 	return arr;
     }
-
 }
 
 /* This is strcmp with ignoring backslashes. */

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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