From: Bart Schaefer <schaefer@brasslantern.com> To: Zsh hackers list <zsh-workers@zsh.org> Subject: [PATCH] Re: zsh/db oddities Date: Sun, 12 Jun 2022 14:19:22 -0700 [thread overview] Message-ID: <CAH+w=7bSYMnjws3Xsye1Lm1Y-5VessC4UbsAcg_BzrS8GCuR9w@mail.gmail.com> (raw) In-Reply-To: <CAH+w=7bcLDkhMnRHjsFnD3+S3rbP4gMRLAK0YAFZ5bW9xndbww@mail.gmail.com> [-- Attachment #1: Type: text/plain, Size: 1825 bytes --] Returning to this 8+ months later ... On Mon, Sep 6, 2021 at 9:29 PM Bart Schaefer <schaefer@brasslantern.com> wrote: > > Open a database as a global and assign something to it: > [...] > Now start messing with the declaration in a function: > [...] > As soon as the tied parameter is declared local, the file has been > written, erasing all the existing values. This seems undesirable? > [...] > Untying the local destroys the global, too, and leaves the file as the > local wrote it. > [...] > I think the correct thing might be to prohibit changing the scope, > similar to what happens when an attempt is made to remove the readonly > attribute? > [...] > Re-ztie-ing the database file while it is still tied, is already > handled as an error. Looking into how this might be accomplished, I noticed this: #ifndef PM_UPTODATE #define PM_UPTODATE (1<<19) /* Parameter has up-to-date data (e.g. loaded from DB) */ #endif I don't think that's a safe choice of bitflag any more? That was introduced 2017-02-16, but the PM_ bit values were rearranged 2018-10-12 and bit 19 is now PM_LOCAL. That doesn't have any effect on the aforementioned behavior of "local"/"zuntie", but perhaps something like this is better? -#ifndef PM_UPTODATE -#define PM_UPTODATE (1<<19) /* Parameter has up-to-date data (e.g. loaded from DB) */ +#ifndef PM_UPTODATE /* Parameter has up-to-date data (e.g. loaded from DB) */ +#define PM_UPTODATE PM_DONTIMPORT_SUID /* Safe PM_ bit to re-use */ #endif Back on the original issue, the simplest way to fix this appears to be to declare the ztie'd parameters to be PM_SINGLE. % zmodload zsh/db/gdbm ztie -d db/gdbm -f sample.gdbm sampledb % () { local sampledb typeset +m sampledb } (anon):local:2: sampledb: can only have a single instance % Patch attached. Comments welcome. [-- Attachment #2: gdbm.txt --] [-- Type: text/plain, Size: 909 bytes --] diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 7e11ec939..3fefd412b 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -34,8 +34,8 @@ #include "db_gdbm.mdh" #include "db_gdbm.pro" -#ifndef PM_UPTODATE -#define PM_UPTODATE (1<<19) /* Parameter has up-to-date data (e.g. loaded from DB) */ +#ifndef PM_UPTODATE /* Parameter has up-to-date data (e.g. loaded from DB) */ +#define PM_UPTODATE PM_DONTIMPORT_SUID /* Safe PM_ bit to re-use */ #endif static Param createhash( char *name, int flags ); @@ -111,7 +111,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) struct gsu_scalar_ext *dbf_carrier; char *resource_name, *pmname; GDBM_FILE dbf = NULL; - int read_write = GDBM_SYNC, pmflags = PM_REMOVABLE; + int read_write = GDBM_SYNC, pmflags = PM_REMOVABLE|PM_SINGLE; Param tied_param; if(!OPT_ISSET(ops,'d')) {
prev parent reply other threads:[~2022-06-12 21:19 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-07 4:29 Bart Schaefer 2022-06-12 21:19 ` Bart Schaefer [this message]
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='CAH+w=7bSYMnjws3Xsye1Lm1Y-5VessC4UbsAcg_BzrS8GCuR9w@mail.gmail.com' \ --to=schaefer@brasslantern.com \ --cc=zsh-workers@zsh.org \ --subject='[PATCH] Re: zsh/db oddities' \ /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
Code repositories for project(s) associated with this 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).