From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3675 invoked from network); 16 Nov 1998 18:13:55 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 16 Nov 1998 18:13:55 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id MAA22020; Mon, 16 Nov 1998 12:58:38 -0500 (EST) Resent-Date: Mon, 16 Nov 1998 12:58:38 -0500 (EST) From: "Bart Schaefer" Message-Id: <981116095647.ZM1502@candle.brasslantern.com> Date: Mon, 16 Nov 1998 09:56:47 -0800 In-Reply-To: <199811161320.OAA11155@beta.informatik.hu-berlin.de> Comments: In reply to Sven Wischnowsky "BUG with associative arrays" (Nov 16, 2:20pm) References: <199811161320.OAA11155@beta.informatik.hu-berlin.de> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sven Wischnowsky , zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5 - Re: BUG with associative arrays MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"dIZms2.0.uN5.DV6Ks"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4654 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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