[PATCH] Fix WATCH/watch tying

Philippe Altherr <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAGdYchvS7FYPj2+4O4wmG_N-PPXjAD4AbmetA3fZH26YadCB4Q@mail.gmail.com>
The code that ties WATCH and watch never triggers. This patch replaces it
with support for tied paramdef instances. The two commits on GitHib show
the before and after state of the two parameters:

- Fix WATCH/watch tying
<https://github.com/paltherr/zsh/compare/fix-unset...paltherr:zsh:fix-watch-tying>

Philippe
fix-watch-tying.txt (text/plain, 2.4 KB)
diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c
index bb27ab9db..f23819b25 100644
--- a/Src/Modules/watch.c
+++ b/Src/Modules/watch.c
@@ -695,8 +695,10 @@ static struct builtin bintab[] = {
 };
 
 static struct paramdef partab[] = {
-    PARAMDEF("WATCH", PM_SCALAR|PM_SPECIAL, &watch, NULL),
-    PARAMDEF("watch", PM_ARRAY|PM_SPECIAL, &watch, NULL),
+    PARAMDEF("WATCH", PM_SCALAR|PM_SPECIAL|PM_TIED, &watch,
+	     NULL /* &colonarr_gsu (see setup_()) */),
+    PARAMDEF("watch", PM_ARRAY|PM_SPECIAL|PM_TIED, &watch,
+	     NULL /* &vararray_gsu (see setup_() */),
 };
 
 static struct features module_features = {
@@ -739,15 +741,6 @@ boot_(UNUSED(Module m))
 {
     static char const * const default_watchfmt = DEFAULT_WATCHFMT;
 
-    Param pma = (Param) paramtab->getnode(paramtab, "watch");
-    Param pms = (Param) paramtab->getnode(paramtab, "WATCH");
-    if (pma && pms && pma->u.arr == watch && pms->u.arr == watch) {
-	/* only tie the two parameters if both were added */
-	pma->ename = "WATCH";
-	pms->ename = "watch";
-	pma->node.flags |= PM_TIED;
-	pms->node.flags |= PM_TIED;
-    }
     watch = mkarray(NULL);
 
     /* These two parameters are only set to defaults if not set.
diff --git a/Src/module.c b/Src/module.c
index 659bc3544..4ca15e7e2 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -1085,6 +1085,9 @@ addparamdef(Paramdef d)
 	 */
 	switch (PM_TYPE(pm->node.flags)) {
 	case PM_SCALAR:
+	    if (pm->node.flags & PM_TIED)
+		pm->ename = casemodify(pm->node.nam, CASMOD_LOWER);
+	    /* fall-through */
 	case PM_NAMEREF:
 	    pm->gsu.s = d->gsu ? (GsuScalar)d->gsu : &varscalar_gsu;
 	    break;
@@ -1099,6 +1102,8 @@ addparamdef(Paramdef d)
 	    break;
 
 	case PM_ARRAY:
+	    if (pm->node.flags & PM_TIED)
+		pm->ename = casemodify(pm->node.nam, CASMOD_UPPER);
 	    pm->gsu.a = d->gsu ? (GsuArray)d->gsu : &vararray_gsu;
 	    break;
 
diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index daf49cd72..ec55e0f95 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -236,6 +236,17 @@
  fi
 0d:Autoload a module via a math function
 
+ if [[ $mods[(r)zsh/watch] == zsh/watch ]]; then
+   zmodload -u zsh/watch
+   WATCH=foo:bar
+   typeset -p WATCH watch
+ else
+   ZTST_skip="zsh/watch module not available"
+ fi
+0:Autoload tied parameters
+>typeset -g -T WATCH watch=( foo bar )
+>typeset -g -aT WATCH watch=( foo bar )
+
 # Test module aliases
 
  zmodload -A example=zsh/example
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.