about summary refs log tree commit diff
path: root/Src/Modules
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-01-24 09:42:20 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2015-01-25 11:34:26 -0800
commit2fa11b7c54d766d6987fb5c0008f8209e6a2529f (patch)
tree178c4c39a89806174ffc49c6190881fcbd15a463 /Src/Modules
parentf7a2fba5342a3cf8c2590111a0a296acd8c8a211 (diff)
downloadzsh-2fa11b7c54d766d6987fb5c0008f8209e6a2529f.tar.gz
zsh-2fa11b7c54d766d6987fb5c0008f8209e6a2529f.tar.xz
zsh-2fa11b7c54d766d6987fb5c0008f8209e6a2529f.zip
34350, 34353: document zsh/db/gdbm module, clean up a few things in the code
Still core dumps at this revision if the tied parameter is forced to be a local and is not untied before end of scope.
Diffstat (limited to 'Src/Modules')
-rw-r--r--Src/Modules/db_gdbm.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 9a2a7a5b9..f079094c0 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -39,9 +39,7 @@
 
 #include <gdbm.h>
 
-#if 0 /* what is this for? */
 static char *backtype = "db/gdbm";
-#endif
 
 static const struct gsu_scalar gdbm_gsu =
 { gdbmgetfn, gdbmsetfn, gdbmunsetfn };
@@ -60,33 +58,38 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
     Param tied_param;
 
     if(!OPT_ISSET(ops,'d')) {
-        zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL);
+        zwarnnam(nam, "you must pass `-d %s'", backtype);
 	return 1;
     }
     if(!OPT_ISSET(ops,'f')) {
-        zwarnnam(nam, "you must pass `-f' with a filename to ztie", NULL);
+        zwarnnam(nam, "you must pass `-f' with a filename", NULL);
 	return 1;
     }
 
     /* Here should be a lookup of the backend type against
      * a registry.
      */
+    if (strcmp(OPT_ARG(ops, 'd'), backtype) != 0) {
+        zwarnnam(nam, "unsupported backend type `%s'", OPT_ARG(ops, 'd'));
+	return 1;
+    }
 
     pmname = ztrdup(*args);
 
     resource_name = OPT_ARG(ops, 'f');
 
-    if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) {
-        zwarnnam(nam, "cannot create the requested parameter name", NULL);
-	return 1;
-    }
-
     dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0);
     if(!dbf) {
         zwarnnam(nam, "error opening database file %s", resource_name);
 	return 1;
     }
 
+    if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) {
+        zwarnnam(nam, "cannot create the requested parameter %s", pmname);
+	gdbm_close(dbf);
+	return 1;
+    }
+
     tied_param->u.hash->tmpdata = (void *)dbf;
 
     return 0;
@@ -98,19 +101,25 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
 {
     Param pm;
     GDBM_FILE dbf;
-
-    pm = (Param) paramtab->getnode(paramtab, args[0]);
-    if(!pm) {
-        zwarnnam(nam, "cannot untie %s", args[0]);
-	return 1;
+    char *pmname;
+    int ret = 0;
+
+    for (pmname = *args; *args++; pmname = *args) {
+	pm = (Param) paramtab->getnode(paramtab, pmname);
+	if(!pm) {
+	    zwarnnam(nam, "cannot untie %s", pmname);
+	    ret = 1;
+	    continue;
+	}
+
+	dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
+	gdbm_close(dbf);
+	/* free(pm->u.hash->tmpdata); */
+	pm->u.hash->tmpdata = NULL;
+	paramtab->removenode(paramtab, pm->node.nam);
     }
 
-    dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
-    gdbm_close(dbf);
-/*    free(pm->u.hash->tmpdata); */
-    paramtab->removenode(paramtab, pm->node.nam);
-
-    return 0;
+    return ret;
 }
 
 /**/