zsh-workers
 help / color / mirror / code / Atom feed
* BUG with associative arrays
@ 1998-11-16 13:20 Sven Wischnowsky
  1998-11-16 17:56 ` PATCH: 3.1.5 - " Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Sven Wischnowsky @ 1998-11-16 13:20 UTC (permalink / raw)
  To: zsh-workers


Try:

  % foo[a]=a
  % typeset -A foo
  % foo[a]=a
  % echo $foo      # or: $foo[(r)?]

The first line seems to be the one triggering the bug, but I don't
have the time to investigate any further now.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* PATCH: 3.1.5 - Re: BUG with associative arrays
  1998-11-16 13:20 BUG with associative arrays Sven Wischnowsky
@ 1998-11-16 17:56 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1998-11-16 17:56 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

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


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

end of thread, other threads:[~1998-11-16 18:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-16 13:20 BUG with associative arrays Sven Wischnowsky
1998-11-16 17:56 ` PATCH: 3.1.5 - " 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).