From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25130 invoked by alias); 30 Jan 2015 19:56:55 -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: 34439 Received: (qmail 26119 invoked from network); 30 Jan 2015 19:56:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.153.127] X-Spam: 0 X-Authority: v=2.1 cv=RcseCjdv c=1 sm=1 tr=0 a=39NrsSuza2clQiZR/7fYWQ==:117 a=39NrsSuza2clQiZR/7fYWQ==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=hD80L64hAAAA:8 a=c9ifLZfHh1zavKCjYtAA:9 a=CjuIK1q_8ugA:10 Date: Fri, 30 Jan 2015 19:56:35 +0000 From: Peter Stephenson To: zsh workers Subject: Re: Anyone want to help make zsh/db/gdbm work? Message-ID: <20150130195635.1845793e@ntlworld.com> In-Reply-To: <20150130085949.4d44007d@pwslap01u.europe.root.pri> References: <150122211942.ZM28918@torch.brasslantern.com> <20150129204658.4a800bcb@ntlworld.com> <150129140625.ZM14730@torch.brasslantern.com> <20150130085949.4d44007d@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 30 Jan 2015 08:59:49 +0000 Peter Stephenson wrote: > > Should we document the need to both declare and unset the parameter, > > or should we add an implicit unset to ztie() ? > > It should probably unset the variable; any other attempt to reuse a > variable declared local (e.g. by declaring it local as a scalar and > assigning it as an array) will silently do that, so I don't see why this > should be different. I wonder if this is good enough. pws diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index a6027de..9896bb5 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -77,8 +77,6 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) return 1; } - pmname = ztrdup(*args); - resource_name = OPT_ARG(ops, 'f'); dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0); @@ -87,6 +85,21 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) return 1; } + pmname = ztrdup(*args); + + if ((tied_param = (Param)paramtab->getnode(paramtab, pmname)) && + !(tied_param->node.flags & PM_UNSET)) { + /* + * Unset any existing parameter. Note there's no implicit + * "local" here, but if the existing parameter is local + * that will be reflected in the new one. + */ + if (unsetparam_pm(tied_param, 0, 1)) { + zsfree(pmname); + gdbm_close(dbf); + return 1; + } + } if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, PM_REMOVABLE))) { zwarnnam(nam, "cannot create the requested parameter %s", pmname);