From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Memory leak when working with undefined associative array keys & problems with unset
Date: Sun, 17 Sep 2017 17:22:14 -0700 [thread overview]
Message-ID: <170917172214.ZM21321@torch.brasslantern.com> (raw)
In-Reply-To: <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.
next prev parent reply other threads:[~2017-09-18 0:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-16 20:57 Anssi Palin
2017-09-17 23:15 ` Bart Schaefer
[not found] ` <1505690609.1747008.1109155032.651AC839@webmail.messagingengine.com>
2017-09-18 0:22 ` Bart Schaefer [this message]
2017-09-23 17:59 ` Peter Stephenson
2017-09-24 1:48 ` Bart Schaefer
2017-09-24 11:37 ` Daniel Shahaf
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=170917172214.ZM21321@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/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).