zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk
Subject: Re: assoc array assignment problem.
Date: Tue, 28 Sep 1999 15:04:48 +0200	[thread overview]
Message-ID: <9909281304.AA18217@ibmth.df.unipi.it> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Tue, 28 Sep 1999 14:15:43 DFT." <9909281215.AA16286@ibmth.df.unipi.it>

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


  reply	other threads:[~1999-09-28 13:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-21  1:37 Tanaka Akira
1999-09-21  4:59 ` Bart Schaefer
1999-09-28 12:15   ` Peter Stephenson
1999-09-28 13:04     ` Peter Stephenson [this message]
1999-09-30 16:58       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9909281304.AA18217@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).