From d00931de5c2b7aa846daf137865dd05ac8d4be8a Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 26 Feb 2017 12:03:56 -0800 Subject: 40650: redo 40508 and 40626 with comments explaining what is actually going on --- ChangeLog | 5 +++++ Src/Modules/parameter.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f8bc93e8..95a3ccd41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-02-26 Barton E. Schaefer + + * 40650: Src/Modules/parameter.c: redo 40508 and 40626 with + comments explaining what is actually going on + 2017-02-25 Daniel Shahaf * 40644: Src/Modules/parameter.c, Test/V06parameter.ztst: diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index c251e4f97..10c47d214 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -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; @@ -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 = @@ -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); } /**/ @@ -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; @@ -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 = @@ -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; @@ -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; } @@ -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; @@ -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); } /**/ -- cgit 1.4.1