Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Memory leak when working with undefined associative array keys & problems with unset
- X-seq: zsh-workers 41722
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Memory leak when working with undefined associative array keys & problems with unset
- Date: Sun, 17 Sep 2017 17:22:14 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=iCR4DvXMTnsHOKZbOMufjuDxC3GDLLP6Mfrwc4wvw+U=; b=q7MG6wd5XH6YxOSX4jyJIpc4tKHsoX0KdzZ4H1Mq7SbhTMBtUH1N+Dxn/g2LNMzRF0 dzGHVW0ovNapvbnuPiA5DK9v28YDlADZfbn3IVKnBwUcevKO9EMQgqutiLhGYORXbWGF KMn4czWsFpMLtOvmFW2UuzAjxWt3qyCpRkwOZjN188PE/ZnKeJdBrfmhjpfob6dVHRwc vzd8NVxbjCNp1Zu8HXcr5OZzLA0eqxFOPUYW/P1L7i8QOebbzMEimX0hXlYKFvXNr0wY 16W4d+Hs0h4ZkkOKPxcLWZ10U6vXL5WtVRloRv8WqPbz8RucZYW50rbVByOvLsN2Kiwu OaaA==
- In-reply-to: <1505690609.1747008.1109155032.651AC839@webmail.messagingengine.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <VI1PR0501MB23514D1D7839FDF243840C91D76D0@VI1PR0501MB2351.eurprd05.prod.outlook.com> <170917161514.ZM21068@torch.brasslantern.com> <1505690609.1747008.1109155032.651AC839@webmail.messagingengine.com>
[Replying to an off-list message w/Daniel's permission]
On Sep 17, 11:23pm, Daniel Shahaf wrote:
}
} Bart Schaefer wrote on Sun, 17 Sep 2017 16:15 -0700:
} > On Sep 16, 8:57pm, Anssi Palin wrote:
} > } $ key='hello * [ world'
} > } $ typeset -A a=("$key" val)
} > } $ unset "a[$key]"
} > } unset: a[hello * [ world]: invalid parameter name
} >
} > Hmm, when examining ${a[$key]} we enter parse_subscript() with $key
} > tokenized, but there's no way to get the tokenized string to reach
} > the same point in the unset builtin
Incidentally ksh93 has this same problem, at least as of 2012:
$ echo $KSH_VERSION
Version AJM 93u+ 2012-08-01
$ unset a["$key"]
ksh: unset: a[hello * [ world]: invalid variable name
$ unset "a[$key]"
ksh: unset: a[hello * [ world]: invalid variable name
$ unset "a['$key']"
ksh: unset: a['hello * [ world']: invalid variable name
This is probably why we've ignored this issue, to date.
} Couldn't we just change the interface and keep it a builtin?
} The point being to pass the subscript separately.
I don't know whether e.g. POSIX would squawk about more options to unset.
There's also this, now that we've added the [key]=val syntax:
torch% a=( ['hello * [ world']=(x y z) )
torch% typeset -p a
typeset -A a=( ['hello * [ world']='(x y z)' )
torch% a=( ['hello * [ world']=() )
zsh: parse error near `()'
Since the empty parens there are currently a parse error, we could make
that work the way it does for plain arrays and unset the key. However,
in ksh note there are no quotes around the parenthesized value (is that
because ksh allows hash elements to be arrays?) and the empty parens
version is permitted:
$ a=(['hello * [ world']=(x y z))
$ typeset -p a
typeset -A a=(['hello * [ world']=(x y z) )
$ a=(['hello * [ world']=() )
$ typeset -p a
typeset -A a=(['hello * [ world']=())
So we may prefer to go with [increased] ksh compatibility here.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author