Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Adapt gdbm code to named references
- X-seq: zsh-workers 54731
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Adapt gdbm code to named references
- Date: Wed, 10 Jun 2026 00:55:00 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=s1mmXIIyOQG8d4eD/du1KAu5nhqUZZY1Id6x28JDjds=; fh=BgAYDYpL6Ne/A5nWEMVJiHiBtrz8Imz3uf26RDwgQX4=; b=WiBgGyNGwK6SB/xNY/JksM8FBMRExhi5Ab5qVQLxrxxvf9hDhvmflPs2Uf+GU2/U2R GWP5D6Hy0oSrTh0w8HO5DIBq9Gob8eTNHUeaLu52y3EpXq7OktoBjU2flxcxe7NNIvjV bOQTeL4K5Ls6rS1xZzYoMOO+1c2VEBySOn0DiroX4lUWQZoHGksGOn67oyoorNJmc1O8 zEdoeVUSxWXOo3wuPN2NabgN7UK6jALguycJZfYYGGL4vKmp+1J1Leu92Yw00Wlq/Rm2 pKk97hRMOYmBQZLEUBIDKRlQ5xaIGvY1iUaFUhtJcxd7opdvOBlOM8cQE1T5qLPu0eSe tJEQ==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1781045713; cv=none; d=google.com; s=arc-20240605; b=WaEeOVdeTTNI6ZxVsGMk+LtE1QEFVnUrYYFokMaIzeuobMGZFrV6dOAMxKGzyS367d HMvI5Wtk1i4Hy/xQclFEhBik6EkRCACJwCopnAv5ihBvxD/6/HqIErgbdOU/+eTmJun3 CsjlUyxjOhGy2jshXtzqSQv1ADf40KwGXAilhNqCtQnhlj02FY7BgcngQxeEIJA2LKjs Cwc1Ad6Q/yWSOGCSAtVaJxwQ5Yapa9s8papK9Kta7T4J4LvFqdG2FsuHsGU6cC8ytzaf fbpoSucMwAaS8Xt25rc3vArNE20mQKiWLNeKFo8qyzYVOUmXRRWPLsev7L0fhtxgOD/u CEZA==
- Archived-at: <https://zsh.org/workers/54731>
- In-reply-to: <CAGdYchtWFD+j+NkaUSoBKsoo8N3Oyatk1P_NceRGakLpSAGb+Q@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchtWFD+j+NkaUSoBKsoo8N3Oyatk1P_NceRGakLpSAGb+Q@mail.gmail.com>
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 604788ae8..09f8224f0 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -38,12 +38,6 @@
#define PM_UPTODATE PM_DONTIMPORT_SUID /* Safe PM_ bit to re-use */
#endif
-static Param createhash( char *name, int flags );
-static int append_tied_name( const char *name );
-static int remove_tied_name( const char *name );
-static char *unmetafy_zalloc(const char *to_copy, int *new_len);
-static void myfreeparamnode(HashNode hn);
-
static int no_database_action = 0;
#include <gdbm.h>
@@ -133,7 +127,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
resource_name = OPT_ARG(ops, 'f');
pmname = *args;
- if ((tied_param = (Param)paramtab->getnode(paramtab, pmname)) &&
+ if ((tied_param = (Param)realparamtab->getnode(realparamtab, pmname)) &&
!(tied_param->node.flags & PM_UNSET)) {
/*
* Unset any existing parameter. Note there's no implicit
@@ -159,7 +153,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
return 1;
}
- if (!(tied_param = createhash(pmname, pmflags))) {
+ if (!(tied_param = creategdbmhash(pmname, pmflags))) {
zwarnnam(nam, "cannot create the requested parameter %s", pmname);
gdbm_close(dbf);
return 1;
@@ -185,7 +179,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
dbf_carrier->dbfile_path = ztrdup(resource_name);
addmodulefd(gdbm_fdesc(dbf), FDT_INTERNAL);
- append_tied_name(pmname);
+ append_tied_name(tied_param->node.nam);
return 0;
}
@@ -199,7 +193,7 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
int ret = 0;
for (pmname = *args; *args++; pmname = *args) {
- pm = (Param) paramtab->getnode(paramtab, pmname);
+ pm = (Param) realparamtab->getnode(realparamtab, pmname);
if(!pm) {
zwarnnam(nam, "cannot untie %s", pmname);
ret = 1;
@@ -239,7 +233,7 @@ bin_zgdbmpath(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
return 1;
}
- pm = (Param) paramtab->getnode(paramtab, pmname);
+ pm = (Param) realparamtab->getnode(realparamtab, pmname);
if(!pm) {
zwarnnam(nam, "no such parameter: %s", pmname);
return 1;
@@ -651,7 +645,8 @@ finish_(UNUSED(Module m))
* Utility functions *
*********************/
-static Param createhash( char *name, int flags ) {
+/**/
+static Param creategdbmhash( char *name, int flags ) {
Param pm;
HashTable ht;
@@ -660,20 +655,11 @@ static Param createhash( char *name, int flags ) {
return NULL;
}
- if (pm->old)
- pm->level = locallevel;
-
/* This creates standard hash. */
ht = pm->u.hash = newparamtable(17, name);
- if (!pm->u.hash) {
- paramtab->removenode(paramtab, name);
- paramtab->freenode(&pm->node);
- zwarnnam(name, "out of memory when allocating hash");
- return NULL;
- }
/* Does free Param (unsetfn is called) */
- ht->freenode = myfreeparamnode;
+ ht->freenode = freegdbmnode;
/* These provide special features */
ht->getnode = ht->getnode2 = getgdbmnode;
@@ -686,6 +672,7 @@ static Param createhash( char *name, int flags ) {
* Adds parameter name to `zgdbm_tied`
*/
+/**/
static int append_tied_name( const char *name ) {
int old_len = arrlen(zgdbm_tied);
char **new_zgdbm_tied = zshcalloc( (old_len+2) * sizeof(char *));
@@ -711,6 +698,7 @@ static int append_tied_name( const char *name ) {
* Removes parameter name from `zgdbm_tied`
*/
+/**/
static int remove_tied_name( const char *name ) {
int old_len = arrlen(zgdbm_tied);
int new_len;
@@ -766,6 +754,8 @@ static int remove_tied_name( const char *name ) {
* - does zalloc of exact size for the new string,
* - restores work buffer to original content, to restore strlen
*/
+
+/**/
static char *
unmetafy_zalloc(const char *to_copy, int *new_len) {
char *work, *to_return;
@@ -789,8 +779,9 @@ unmetafy_zalloc(const char *to_copy, int *new_len) {
return to_return;
}
+/**/
static void
-myfreeparamnode(HashNode hn)
+freegdbmnode(HashNode hn)
{
Param pm = (Param) hn;
diff --git a/Test/V11db_gdbm.ztst b/Test/V11db_gdbm.ztst
index 6d74cef2c..1ac9fc0c2 100644
--- a/Test/V11db_gdbm.ztst
+++ b/Test/V11db_gdbm.ztst
@@ -204,34 +204,67 @@
local -a dbase
dbase=( fromarray )
() {
- local -a dbase
+ local dbase
+ () {
ztie -d db/gdbm -f $dbfile dbase
- echo ${(t)dbase}
- zuntie dbase
+ echo "Connected:" $dbase[a]
+ }
+ echo "Still connected:" $dbase[a]
}
echo $dbase[1]
ztie -d db/gdbm -f $dbfile dbase2
echo "Can connect, so untie happened:" $dbase2[a]
zuntie dbase2
0:Test of automatic untie (use of local scope) and of scoping
->association-local-special
+>Connected: b
+>Still connected: b
>fromarray
>Can connect, so untie happened: b
+ local dbase
+ () {
+ local -n rbase=dbase
+ local dbase=not-a-dbase
+ ztie -d db/gdbm -f $dbfile rbase
+ echo $dbase
+ echo "Connected:" $rbase[a]
+ zuntie rbase
+ echo "Disconnected:" $rbase[a]
+ ztie -d db/gdbm -f $dbfile rbase
+ echo "Reconnected:" $rbase[a]
+ echo $dbase
+ }
+ echo "Still connected:" $dbase[a]
+ zuntie dbase
+0:Test of tie to hidden local via named reference
+>not-a-dbase
+>Connected: b
+>Disconnected:
+>Reconnected: b
+>not-a-dbase
+>Still connected: b
+
echo $zgdbm_tied ${#zgdbm_tied}
ztie -r -d db/gdbm -f $dbfile dbase
echo $zgdbm_tied ${#zgdbm_tied}
ztie -d db/gdbm -f ${dbfile}2 dbase2
echo $zgdbm_tied ${#zgdbm_tied}
+ local -n rbase3=dbase3
+ ztie -d db/gdbm -f ${dbfile}3 rbase3
+ echo $zgdbm_tied ${#zgdbm_tied}
zuntie -u dbase
echo $zgdbm_tied ${#zgdbm_tied}
zuntie dbase2
echo $zgdbm_tied ${#zgdbm_tied}
+ zuntie rbase3
+ echo $zgdbm_tied ${#zgdbm_tied}
0:zgdbm_tied parameter
>0
>dbase 1
>dbase dbase2 2
->dbase2 1
+>dbase dbase2 dbase3 3
+>dbase2 dbase3 2
+>dbase3 1
>0
unset zgdbm_tied 2>/dev/null
@@ -311,8 +344,14 @@
zgdbmpath dbase
[[ $REPLY = */Test/db.gdbm ]] && echo correct
zuntie -u dbase
+ local -n rbase=dbase
+ ztie -r -d db/gdbm -f $dbfile rbase
+ zgdbmpath rbase
+ [[ $REPLY = */Test/db.gdbm ]] && echo correct
+ zuntie -u rbase
0:zgdbmpath builtin
>correct
+>correct
>correct
ztie -d db/gdbm -f $dbfile dbase
Messages sorted by:
Reverse Date,
Date,
Thread,
Author