Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Named reference typos & misc.



More stuff helpfully noticed by Oliver; the last patch unintentionally
regressed one valid assignment usage, typeset +m and $parameters
returned (different) incorrect results for named references, and
testing for typeset +m revealed a segfault with typeset -p.
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index a659300fd..96a211c69 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -108,7 +108,7 @@ getpmparameter(UNUSED(HashTable ht), const char *name)
     if ((rpm = (Param) realparamtab->getnode2(realparamtab, name)) &&
 	!(rpm->node.flags & PM_UNSET)) {
 	pm->u.str = paramtypestr(rpm);
-	if ((rpm->node.flags & PM_NAMEREF) &&
+	if ((rpm->node.flags & PM_NAMEREF) && rpm->u.str && *(rpm->u.str) &&
 	    (rpm = (Param) realparamtab->getnode(realparamtab, name)) &&
 	    !(rpm->node.flags & PM_UNSET)) {
 	    pm->u.str = zhtricat(pm->u.str, "-", paramtypestr(rpm));
diff --git a/Src/builtin.c b/Src/builtin.c
index cf7e9d9fe..47b337edc 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2262,8 +2262,9 @@ typeset_single(char *cname, char *pname, Param pm, int func,
 	     */
 	    if (!(on & PM_READONLY) || !isset(POSIXBUILTINS))
 		off |= PM_UNSET;
-	    pm->node.flags = (pm->node.flags |
-			      (on & ~PM_READONLY)) & ~off;
+	    if (!OPT_ISSET(ops, 'p'))
+		pm->node.flags = (pm->node.flags |
+				  (on & ~PM_READONLY)) & ~off;
 	}
 	if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) {
 	    if (typeset_setwidth(cname, pm, ops, on, 0))
@@ -3063,12 +3064,15 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    if (asg->value.scalar &&
 		((pm = (Param)resolve_nameref((Param)hn, asg)) &&
 		 (pm->node.flags & PM_NAMEREF))) {
-		if (pm->node.flags & PM_SPECIAL)
+		if (pm->node.flags & PM_SPECIAL) {
 		    zwarnnam(name, "%s: invalid reference", pm->node.nam);
-		else
+		    returnval = 1;
+		    continue;
+		} else if (pm->u.str && strcmp(pm->u.str, asg->name) == 0) {
 		    zwarnnam(name, "%s: invalid self reference", asg->name);
-		returnval = 1;
-		continue;
+		    returnval = 1;
+		    continue;
+		}
 	    }
 	    if (hn) {
 		/* namerefs always start over fresh */
diff --git a/Src/params.c b/Src/params.c
index f61374b87..92cbecf63 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5851,7 +5851,7 @@ static const struct paramtypes pmtypes[] = {
     { PM_EXPORTED, "exported", 'x', 0},
     { PM_UNIQUE, "unique", 'U', 0},
     { PM_TIED, "tied", 'T', 0},
-    { PM_NAMEREF, "namref", 'n', 0}
+    { PM_NAMEREF, "nameref", 'n', 0}
 };
 
 #define PMTYPES_SIZE ((int)(sizeof(pmtypes)/sizeof(struct paramtypes)))
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index d2abdd391..d240e4917 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -25,6 +25,20 @@
 0:assign nameref placeholder
 >ptr=var
 
+ unset ptr
+ typeset -n ptr
+ typeset -n ptr=var
+ typeset -n
+0:assign placeholder with new typeset
+>ptr=var
+
+ typeset -n ptr1
+ typeset -n ptr2=ptr1
+ typeset -n
+0:chain ending in placeholder
+>ptr1
+>ptr2=ptr1
+
  typeset ptr=var
  typeset -n ptr
  typeset -n


Messages sorted by: Reverse Date, Date, Thread, Author