From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9950 invoked by alias); 18 Sep 2017 00:22:10 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41722 Received: (qmail 26820 invoked by uid 1010); 18 Sep 2017 00:22:10 -0000 X-Qmail-Scanner-Diagnostics: from mail-pf0-f180.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.192.180):SA:0(-4.7/5.0):. Processed in 1.195892 secs); 18 Sep 2017 00:22:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=iCR4DvXMTnsHOKZbOMufjuDxC3GDLLP6Mfrwc4wvw+U=; b=rHNgFzw46ygLbd56f6TFaD0tG7WR+Z1nyFu5AEjT/RgtWcCKtauuHDw7hiI8GATOC9 jUVzPKiWxl0BCZImwmA81M8IUGfI1EDJyKWHJ/D8dFZK58peRrwXuXF5nw2rAumeUq4j tTZ2Su0Ry6MUZKND9sOabIQ99QQn4DYRE/djhEKgqDhGYRYk3VUvLX2z5qDRAJevuN5K WJxXDT+aeRWPBIwRaY1hIMHqMl7qkOPIaDM+2ebuuq7GtqTtQLPx3vjE3n4MaE477UQH afDnDGQsaJ9Ap75ZxCAIO88Cyu5KZaF6Vej9iVGEdqEoV4Qf37oPROHPbKJBxg18M53l TenA== X-Gm-Message-State: AHPjjUjMO0uZL+7zZdOfV81HQxbMc/jyrdD1WC2pKVHdst5u3Oq3VyQO DIF/4k8jdLSENnCcEbI= X-Google-Smtp-Source: ADKCNb4OLsADmU3eScJY40dkMtXZFvEiFaAaR1LfAMDrDN7ip+rIAQqGjbmaXA3ojZb2yv2UYXey/A== X-Received: by 10.101.78.131 with SMTP id b3mr30990226pgs.28.1505694125525; Sun, 17 Sep 2017 17:22:05 -0700 (PDT) From: Bart Schaefer Message-Id: <170917172214.ZM21321@torch.brasslantern.com> Date: Sun, 17 Sep 2017 17:22:14 -0700 In-Reply-To: <1505690609.1747008.1109155032.651AC839@webmail.messagingengine.com> Comments: In reply to Daniel Shahaf "Re: Memory leak when working with undefined associative array keys & problems with unset" (Sep 17, 11:23pm) References: <170917161514.ZM21068@torch.brasslantern.com> <1505690609.1747008.1109155032.651AC839@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Memory leak when working with undefined associative array keys & problems with unset MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii [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.