zsh-workers
 help / color / mirror / code / Atom feed
* zsh/db oddities
@ 2021-09-07  4:29 Bart Schaefer
  2022-06-12 21:19 ` [PATCH] " Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2021-09-07  4:29 UTC (permalink / raw)
  To: Zsh hackers list

The only example so far is of course zsh/db/gdbm.

Open a database as a global and assign something to it:

% zmodload zsh/db/gdbm
ztie -d db/gdbm -f sample.gdbm sampledb
% sampledb[GLOBAL]=global
% cksum sample.gdbm
3454148649 16384 sample.gdbm

Now start messing with the declaration in a function:

% () {
cksum sample.gdbm
local sampledb
typeset +m sampledb
cksum sample.gdbm
sampledb[INFUNC]=set
cksum sample.gdbm
print $sampledb[INFUNC]
}
3454148649 16384 sample.gdbm
association local sampledb
2087515864 16384 sample.gdbm
2669724292 16384 sample.gdbm
set

As soon as the tied parameter is declared local, the file has been
written, erasing all the existing values.  This seems undesirable?
Returning to the top level:

% cksum sample.gdbm
1634404396 16384 sample.gdbm
% typeset -p sampledb
typeset -A sampledb=( [GLOBAL]=global )

The file has been written again and the original state is back.

If instead you zuntie the local:

% () {
local sampledb
sampledb[LOCAL]=local
zuntie sampledb
}
% typeset -p sampledb
typeset: no such variable: sampledb

Untying the local destroys the global, too, and leaves the file as the
local wrote it.

% ztie -d db/gdbm -f sample.gdbm sampledb
% typeset -p sampledb
typeset -A sampledb=( [LOCAL]=local )

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?

% ztie -r -d db/gdbm -f sample.gdbm sampledb
% () {
local -A +r sampledb
}
(anon):local:1: sampledb: can't change type of a special parameter

Re-ztie-ing the database file while it is still tied, is already
handled as an error.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-12 21:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07  4:29 zsh/db oddities Bart Schaefer
2022-06-12 21:19 ` [PATCH] " Bart Schaefer

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).