Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Anyone want to help make zsh/db/gdbm work?



On Fri, 30 Jan 2015 08:59:49 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> 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);



Messages sorted by: Reverse Date, Date, Thread, Author