zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>,
	zsh-workers@math.gatech.edu
Subject: PATCH: 3.1.5 - Re: BUG with associative arrays
Date: Mon, 16 Nov 1998 09:56:47 -0800	[thread overview]
Message-ID: <981116095647.ZM1502@candle.brasslantern.com> (raw)
In-Reply-To: <199811161320.OAA11155@beta.informatik.hu-berlin.de>

On Nov 16,  2:20pm, Sven Wischnowsky wrote:
} Subject: BUG with associative arrays
} 
} Try:
} 
}   % foo[a]=a
}   % typeset -A foo
}   % foo[a]=a
}   % echo $foo      # or: $foo[(r)?]

It was worse than that:

    % foo=8
    % typeset -A foo
    % foo[a]=a
    segmentation fault

Here's the fix.  Note that typeset accepts the syntax

    % typeset -A foo=12

but simply throws away the value being assigned, because setsparam() does
nothing when handed an associative array.

Index: Src/builtin.c
===================================================================
--- builtin.c	1998/11/12 09:21:34	1.8
+++ builtin.c	1998/11/16 17:45:40
@@ -1501,6 +1501,8 @@
 	off |= PM_LOWER;
     if (on & PM_LOWER)
 	off |= PM_UPPER;
+    if (on & PM_HASHED)
+	off |= PM_ARRAY;
     on &= ~off;
 
     /* Given no arguments, list whatever the options specify. */
@@ -1543,6 +1545,12 @@
 			    if (PM_TYPE(pm->flags) == PM_ARRAY && (on & PM_UNIQUE) &&
 				!(pm->flags & PM_READONLY & ~off))
 				uniqarray((*pm->gets.afn) (pm));
+			    if ((on & ~pm->flags) & PM_HASHED) {
+				char *nam = ztrdup(pm->nam);
+				unsetparam(nam);
+				pm = createparam(nam, on & ~PM_READONLY);
+				DPUTS(!pm, "BUG: parameter not created");
+			    }
 			    pm->flags = (pm->flags | on) & ~off;
 			    if (PM_TYPE(pm->flags) != PM_ARRAY &&
 				PM_TYPE(pm->flags) != PM_HASHED) {
@@ -1594,7 +1602,8 @@
 	    (((pm->flags & PM_SPECIAL) && pm->level == locallevel) ||
 	     (!(pm->flags & PM_UNSET) &&
 	      ((locallevel == pm->level) || func == BIN_EXPORT) &&
-	      !(bit = ((off & pm->flags) | (on & ~pm->flags)) & PM_INTEGER)))) {
+	      !(bit = (((off & pm->flags) | (on & ~pm->flags)) &
+		       (PM_INTEGER|PM_HASHED)))))) {
 	    /* if no flags or values are given, just print this parameter */
 	    if (!on && !roff && !asg->value) {
 		paramtab->printnode((HashNode) pm, 0);

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


      reply	other threads:[~1998-11-16 18:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-16 13:20 Sven Wischnowsky
1998-11-16 17:56 ` Bart Schaefer [this message]

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=981116095647.ZM1502@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).