zsh-workers
 help / color / mirror / code / Atom feed
From: ZyX <kp-pav@yandex.ru>
To: Bart Schaefer <schaefer@brasslantern.com>,
	"zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Anyone want to help make zsh/db/gdbm work?
Date: Fri, 23 Jan 2015 08:37:13 +0300	[thread overview]
Message-ID: <4302591421991433@web9g.yandex.ru> (raw)
In-Reply-To: <150122211942.ZM28918@torch.brasslantern.com>



23.01.2015, 08:20, "Bart Schaefer" <schaefer@brasslantern.com>:
> This module has been sitting around forever, completely undocumented.  The
> basic functions work; I tweaked a couple of things and wrote a short page
> of documentation, which explains about this:
>
> schaefer<507> typeset GDBMDB
> schaefer<508> ztie -d db/gdbm -f gdbmdb GDBMDB
> ztie: cannot create the requested parameter GDBMDB
>
> 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
>
> This happens because ztie/zuntie directly manipulate the global paramtab.
> Somebody else may be able to patch that up quicker than I.
>
> diff --git a/Doc/Makefile.in b/Doc/Makefile.in
> index 41af4a3..a420781 100644
> --- a/Doc/Makefile.in
> +++ b/Doc/Makefile.in
> @@ -60,7 +60,7 @@ MODDOCSRC = \
>  Zsh/mod_attr.yo Zsh/mod_cap.yo Zsh/mod_clone.yo \
>  Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \
>  Zsh/mod_computil.yo Zsh/mod_curses.yo \
> -Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \
> +Zsh/mod_datetime.yo Zsh/mod_db_gdbm.yo Zsh/mod_deltochar.yo \

It looks like if you forgot to `git add` Doc/Zsh/mod_db_gdbm.yo. I do not see it in the patch, only a small reference here.

>  Zsh/mod_example.yo Zsh/mod_files.yo Zsh/mod_langinfo.yo \
>  Zsh/mod_mapfile.yo Zsh/mod_mathfunc.yo Zsh/mod_newuser.yo \
>  Zsh/mod_parameter.yo Zsh/mod_pcre.yo Zsh/mod_regex.yo \
> diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
> index 9a2a7a5..f079094 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;
>  }
>
>  /**/


  reply	other threads:[~2015-01-23  5:42 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 [this message]
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
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=4302591421991433@web9g.yandex.ru \
    --to=kp-pav@yandex.ru \
    --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).