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

Re: assoc array assignment problem.



I wrote:
> Two comments:

This is supposed to take care of the first and the third.  Now the
following works:

typeset -A assoc
foo=random
arg='$foo'
assoc[$arg]=bar
print ${(kv)assoc}
$foo bar

and the restricted mode crash should go, too.  I don't think either of
these should have adverse effects.

The other issue --- tokenization and retokenization of the subscript ---
turns out to be more complicated.  In an expression like "$foo[(r)b*]", you
would indeed need to tokenize what you have already.  Perhaps that could be
done by paramsubst(), which knows if it's in quotes, but as the code that
uses this is buried in fetchvalue() it's hard to be sure.  Alternatively,
it could be given a flag that it was in double quotes and so needed (with
certain flags only) to retokenize the expression.  Alternatively, it could
be left as it is with consequent inefficiency.

I discovered another problem.

foo=
assoc[$foo]=rod
print ${(kv)assoc}
 rod $foo bar
unset assoc[$foo] assoc[] "assoc[$foo]" "assoc[]"
print ${(kv)assoc}
 rod $foo bar

I haven't found anything which gets rid of it.

--- Src/exec.c.subst	Tue Sep 28 13:58:30 1999
+++ Src/exec.c	Tue Sep 28 14:37:08 1999
@@ -1336,9 +1336,6 @@
     for (n = firstnode(l); n; incnode(n)) {
 	v = (Varasg) getdata(n);
 	name = dupstring(v->name);
-	singsub(&name);
-	if (errflag)
-	    return;
 	untokenize(name);
 	if (xtr)
 	    fprintf(stderr, "%s=", name);
@@ -1370,15 +1367,13 @@
 	    }
 	    if (xtr)
 		fprintf(stderr, "%s ", val);
-	    if (export) {
-		if (export < 0) {
-		    /* We are going to fork so do not bother freeing this */
-		    pm = (Param) paramtab->removenode(paramtab, name);
-		    if (isset(RESTRICTED) && (pm->flags & PM_RESTRICTED)) {
-			zerr("%s: restricted", pm->nam, 0);
-			zsfree(val);
-			return;
-		    }
+	    if (export && !strchr(name, '[')) {
+		if (export < 0 && isset(RESTRICTED) &&
+		    (pm = (Param) paramtab->removenode(paramtab, name)) &&
+		    (pm->flags & PM_RESTRICTED)) {
+		    zerr("%s: restricted", pm->nam, 0);
+		    zsfree(val);
+		    return;
 		}
 		allexp = opts[ALLEXPORT];
 		opts[ALLEXPORT] = 1;

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



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