zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: 3.1.5-pws-8: setting duplicate elements of assoc array
@ 1999-02-18 17:17 Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1999-02-18 17:17 UTC (permalink / raw)
  To: Zsh hackers list

I just discovered:

% typeset -A newhash
% newhash=(a 1 a 2)
<SPLAT!>

This is because createparam() now returns NULL when the parameter already
exists.  The easiest fix is to allow the later value to override the
former.

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>

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.

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


--- Src/params.c.uass	Thu Feb 18 11:57:31 1999
+++ Src/params.c	Thu Feb 18 17:49:26 1999
@@ -1837,6 +1837,12 @@
     while (*aptr) {
 	/* The parameter name is ztrdup'd... */
 	v->pm = createparam(*aptr, PM_SCALAR|PM_UNSET);
+	/*
+	 * createparam() doesn't return anything if the parameter
+	 * already existed.
+	 */
+	if (!v->pm)
+	    v->pm = (Param) paramtab->getnode(paramtab, *aptr);
 	zsfree(*aptr++);
 	/* ...but we can use the value without copying. */
 	setstrvalue(v, *aptr++);

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: 3.1.5-pws-8: setting duplicate elements of assoc array
  1999-02-19  8:58 Sven Wischnowsky
@ 1999-02-19 23:59 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1999-02-19 23:59 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-workers

Sven Wischnowsky writes:
 > 
 > 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()...

So don't.  The argument would be the same for almost every existing
instance of tokenize(), right?  Do it this way (no 3.1.5 source code
handy, pardon the psuedo-code):

static void
full_tokenize(char *s, int extra_arg)	/* choose more appropriate name */
{
   /* combined guts of tokenize() and ctokenize() here */
}

/**/
void
tokenize(char *s)
{
   full_tokenize(s, something);
}

/**/
void
ctokenize(char *s)
{
   full_tokenize(s, otherthing);
}

Then change only the calls that actually need the new argument, to
call the new full_tokenize() function.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: 3.1.5-pws-8: setting duplicate elements of assoc array
@ 1999-02-19  8:58 Sven Wischnowsky
  1999-02-19 23:59 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 1999-02-19  8:58 UTC (permalink / raw)
  To: zsh-workers


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@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-02-20 11:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-18 17:17 PATCH: 3.1.5-pws-8: setting duplicate elements of assoc array Peter Stephenson
1999-02-19  8:58 Sven Wischnowsky
1999-02-19 23:59 ` Bart Schaefer

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).