Skip to content

Commit

Permalink
40650: redo 40508 and 40626 with comments explaining what is actually…
Browse files Browse the repository at this point in the history
… going on
  • Loading branch information
bartschaefer committed Feb 26, 2017
1 parent c7048cd commit d00931d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2017-02-26 Barton E. Schaefer <schaefer@zsh.org>

* 40650: Src/Modules/parameter.c: redo 40508 and 40626 with
comments explaining what is actually going on

2017-02-25 Daniel Shahaf <d.s@daniel.shahaf.name>

* 40644: Src/Modules/parameter.c, Test/V06parameter.ztst:
Expand Down
34 changes: 25 additions & 9 deletions Src/Modules/parameter.c
Expand Up @@ -167,7 +167,7 @@ unsetpmcommand(Param pm, UNUSED(int exp))

/**/
static void
setpmcommands(UNUSED(Param pm), HashTable ht)
setpmcommands(Param pm, HashTable ht)
{
int i;
HashNode hn;
Expand All @@ -190,7 +190,15 @@ setpmcommands(UNUSED(Param pm), HashTable ht)

cmdnamtab->addnode(cmdnamtab, ztrdup(hn->nam), &cn->node);
}
deleteparamtable(ht);
/*
* On full-array assignment ht is a temporary hash with the default
* get/set functions, whereas pm->u.hash has the special $commands
* get/set functions. Do not assign ht to pm, just delete it.
*
* On append, ht and pm->u.hash are the same table, don't delete.
*/
if (ht != pm->u.hash)
deleteparamtable(ht);
}

static const struct gsu_scalar pmcommand_gsu =
Expand Down Expand Up @@ -349,7 +357,9 @@ setfunctions(Param pm, HashTable ht, int dis)

setfunction(hn->nam, ztrdup(getstrvalue(&v)), dis);
}
hashsetfn(pm, ht);
/* See setpmcommands() above */
if (ht != pm->u.hash)
deleteparamtable(ht);
}

/**/
Expand Down Expand Up @@ -937,7 +947,7 @@ unsetpmoption(Param pm, UNUSED(int exp))

/**/
static void
setpmoptions(UNUSED(Param pm), HashTable ht)
setpmoptions(Param pm, HashTable ht)
{
int i;
HashNode hn;
Expand All @@ -962,7 +972,9 @@ setpmoptions(UNUSED(Param pm), HashTable ht)
(val && strcmp(val, "off")), 0, opts))
zwarn("can't change option: %s", hn->nam);
}
deleteparamtable(ht);
/* See setpmcommands() above */
if (ht != pm->u.hash)
deleteparamtable(ht);
}

static const struct gsu_scalar pmoption_gsu =
Expand Down Expand Up @@ -1501,7 +1513,7 @@ unsetpmnameddir(Param pm, UNUSED(int exp))

/**/
static void
setpmnameddirs(UNUSED(Param pm), HashTable ht)
setpmnameddirs(Param pm, HashTable ht)
{
int i;
HashNode hn, next, hd;
Expand Down Expand Up @@ -1543,7 +1555,9 @@ setpmnameddirs(UNUSED(Param pm), HashTable ht)

i = opts[INTERACTIVE];
opts[INTERACTIVE] = 0;
deleteparamtable(ht);
/* See setpmcommands() above */
if (ht != pm->u.hash)
deleteparamtable(ht);
opts[INTERACTIVE] = i;
}

Expand Down Expand Up @@ -1724,7 +1738,7 @@ unsetpmsalias(Param pm, UNUSED(int exp))

/**/
static void
setaliases(HashTable alht, UNUSED(Param pm), HashTable ht, int flags)
setaliases(HashTable alht, Param pm, HashTable ht, int flags)
{
int i;
HashNode hn, next, hd;
Expand Down Expand Up @@ -1760,7 +1774,9 @@ setaliases(HashTable alht, UNUSED(Param pm), HashTable ht, int flags)
alht->addnode(alht, ztrdup(hn->nam),
createaliasnode(ztrdup(val), flags));
}
deleteparamtable(ht);
/* See setpmcommands() above */
if (ht != pm->u.hash)
deleteparamtable(ht);
}

/**/
Expand Down

0 comments on commit d00931d

Please sign in to comment.