From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: Anyone want to help make zsh/db/gdbm work?
Date: Mon, 26 Jan 2015 12:11:16 +0000 [thread overview]
Message-ID: <CAECNH1RmrF9+w86zPxoiG=TM9j_0rdeeW9LV+9Qp0ksQ7LyJVg@mail.gmail.com> (raw)
In-Reply-To: <150122211942.ZM28918@torch.brasslantern.com>
[-- Attachment #1: Type: text/plain, Size: 2476 bytes --]
On 23 January 2015 at 05:19, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> However, there's still this:
>
> schaefer<518> typeset GDBMDB
> schaefer<519> (){ local GDBMDB; unset GDBMDB; ztie -d db/gdbm -f gdbmdb
GDBMDB }
> ../../zsh-5.0/Src/params.c:4914: BUG: in restoring scope of special
parameter
> zsh: segmentation fault (core dumped) Src/zsh
I think this is better, but you may still be able to find ways it
fails. It's possibly a bit more paranoid than it needs to be;
the PM_REMOVABLE flag is probably the key.
However, in any case I think the way ztie and zuntie work play
fast and loose with parameters. Try
typeset GDBMB-foo
(){
local GDBMDB
unset GDBMDB
ztie -d db/gdbm -f gdbmdb GDBMDB
zuntie GDBMDB
}
print $GDBMB
Note there's now a zuntie there. This still doesn't appear to work.
It now does without the zuntie, though, at least for the most obvious
limited value of "work".
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index f079094..d75af98 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -43,6 +43,9 @@ static char *backtype = "db/gdbm";
static const struct gsu_scalar gdbm_gsu =
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
+/**/
+static const struct gsu_hash gdbm_hash_gsu =
+{ hashgetfn, hashsetfn, gdbmhashunsetfn };
static struct builtin bintab[] = {
BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:f:", NULL),
@@ -84,12 +87,14 @@ bin_ztie(char *nam, char **args, Options ops,
UNUSED(int func))
return 1;
}
- if (!(tied_param = createspecialhash(pmname, &getgdbmnode,
&scangdbmkeys, 0))) {
+ if (!(tied_param = createspecialhash(pmname, &getgdbmnode,
&scangdbmkeys,
+ PM_REMOVABLE))) {
zwarnnam(nam, "cannot create the requested parameter %s", pmname);
gdbm_close(dbf);
return 1;
}
+ tied_param->gsu.h = &gdbm_hash_gsu;
tied_param->u.hash->tmpdata = (void *)dbf;
return 0;
@@ -225,6 +230,25 @@ scangdbmkeys(HashTable ht, ScanFunc func, int flags)
}
+/**/
+static void
+gdbmhashunsetfn(Param pm, UNUSED(int exp))
+{
+ GDBM_FILE dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
+
+ if (!dbf) /* paranoia */
+ return;
+
+ gdbm_close(dbf);
+ pm->u.hash->tmpdata = NULL;
+
+ /* hash table is now normal, so proceed normally... */
+ pm->node.flags &= ~PM_SPECIAL;
+ pm->gsu.h = &stdhash_gsu;
+ pm->gsu.h->setfn(pm, NULL);
+ pm->node.flags |= PM_UNSET;
+}
+
#else
# error no gdbm
#endif /* have gdbm */
next prev parent reply other threads:[~2015-01-26 12:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-23 5:19 Bart Schaefer
2015-01-23 5:37 ` ZyX
2015-01-23 5:59 ` Bart Schaefer
2015-01-23 15:49 ` ZyX
2015-01-23 19:47 ` Peter Stephenson
2015-01-23 20:00 ` ZyX
2015-01-23 20:16 ` Aaron Schrab
2015-01-23 20:33 ` Mikael Magnusson
2015-01-26 12:11 ` Peter Stephenson [this message]
2015-01-29 20:46 ` Peter Stephenson
2015-01-29 22:06 ` Bart Schaefer
2015-01-30 8:59 ` Peter Stephenson
2015-01-30 19:56 ` Peter Stephenson
2015-01-30 20:03 ` Bart Schaefer
2015-02-02 9:46 ` Peter Stephenson
2015-02-03 10:22 ` Peter Stephenson
2015-01-31 3:21 ` Bart Schaefer
2015-01-31 3:37 ` Bart Schaefer
2015-02-01 19:57 ` Bart Schaefer
2015-02-01 21:49 ` Bart Schaefer
2015-02-02 5:18 ` ZyX
2015-02-02 17:33 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAECNH1RmrF9+w86zPxoiG=TM9j_0rdeeW9LV+9Qp0ksQ7LyJVg@mail.gmail.com' \
--to=p.w.stephenson@ntlworld.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).