mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 10:41:11 +02:00
34447: fix assignment of key-value array to ztie'd parameter.
Add gdbmhashsetfn() for this purpose. Erases and reorganizes the database before bulk assign.
This commit is contained in:
parent
a5333cc344
commit
1254538a41
2 changed files with 61 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
2015-02-02 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 34447: Src/Modules/db_gdbm.c: fix assignment of key-value array
|
||||
to ztie'd parameter.
|
||||
|
||||
2015-02-02 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* 34444: Completion/Unix/Command/_git: git completion: minor
|
||||
|
|
|
@ -45,7 +45,7 @@ static const struct gsu_scalar gdbm_gsu =
|
|||
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
||||
/**/
|
||||
static const struct gsu_hash gdbm_hash_gsu =
|
||||
{ hashgetfn, hashsetfn, gdbmhashunsetfn };
|
||||
{ hashgetfn, gdbmhashsetfn, gdbmhashunsetfn };
|
||||
|
||||
static struct builtin bintab[] = {
|
||||
BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:f:r", NULL),
|
||||
|
@ -194,7 +194,7 @@ gdbmsetfn(Param pm, char *val)
|
|||
|
||||
/**/
|
||||
static void
|
||||
gdbmunsetfn(Param pm, int um)
|
||||
gdbmunsetfn(Param pm, UNUSED(int um))
|
||||
{
|
||||
datum key;
|
||||
GDBM_FILE dbf;
|
||||
|
@ -232,9 +232,7 @@ scangdbmkeys(HashTable ht, ScanFunc func, int flags)
|
|||
{
|
||||
Param pm = NULL;
|
||||
datum key, content;
|
||||
GDBM_FILE dbf;
|
||||
|
||||
dbf = (GDBM_FILE)(ht->tmpdata);
|
||||
GDBM_FILE dbf = (GDBM_FILE)(ht->tmpdata);
|
||||
|
||||
pm = (Param) hcalloc(sizeof(struct param));
|
||||
|
||||
|
@ -257,6 +255,59 @@ scangdbmkeys(HashTable ht, ScanFunc func, int flags)
|
|||
|
||||
}
|
||||
|
||||
/**/
|
||||
static void
|
||||
gdbmhashsetfn(Param pm, HashTable ht)
|
||||
{
|
||||
int i;
|
||||
HashNode hn;
|
||||
GDBM_FILE dbf;
|
||||
datum key, content;
|
||||
|
||||
if (!pm->u.hash || pm->u.hash == ht)
|
||||
return;
|
||||
|
||||
if (!(dbf = (GDBM_FILE)(pm->u.hash->tmpdata)))
|
||||
return;
|
||||
|
||||
key = gdbm_firstkey(dbf);
|
||||
while (key.dptr) {
|
||||
queue_signals();
|
||||
(void)gdbm_delete(dbf, key);
|
||||
free(key.dptr);
|
||||
unqueue_signals();
|
||||
key = gdbm_firstkey(dbf);
|
||||
}
|
||||
|
||||
/* just deleted everything, clean up */
|
||||
(void)gdbm_reorganize(dbf);
|
||||
|
||||
if (!ht)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ht->hsize; i++)
|
||||
for (hn = ht->nodes[i]; hn; hn = hn->next) {
|
||||
struct value v;
|
||||
|
||||
v.isarr = v.flags = v.start = 0;
|
||||
v.end = -1;
|
||||
v.arr = NULL;
|
||||
v.pm = (Param) hn;
|
||||
|
||||
key.dptr = v.pm->node.nam;
|
||||
key.dsize = strlen(key.dptr) + 1;
|
||||
|
||||
queue_signals();
|
||||
|
||||
content.dptr = getstrvalue(&v);
|
||||
content.dsize = strlen(content.dptr) + 1;
|
||||
|
||||
(void)gdbm_store(dbf, key, content, GDBM_REPLACE);
|
||||
|
||||
unqueue_signals();
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
static void
|
||||
gdbmuntie(Param pm)
|
||||
|
|
Loading…
Reference in a new issue