zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Named reference typos & misc.
@ 2023-02-14  2:08 Bart Schaefer
  2023-02-14 14:46 ` Peter Stephenson
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Schaefer @ 2023-02-14  2:08 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 261 bytes --]

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.

[-- Attachment #2: nameref-9-bugs.txt --]
[-- Type: text/plain, Size: 2823 bytes --]

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-02-21 15:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14  2:08 [PATCH] Named reference typos & misc Bart Schaefer
2023-02-14 14:46 ` Peter Stephenson
2023-02-14 16:14   ` Bart Schaefer
2023-02-14 16:36     ` Peter Stephenson
2023-02-14 20:00       ` Bart Schaefer
2023-02-15  1:39         ` Bart Schaefer
2023-02-16 15:29           ` zmodload (-u?) changing options (was Re: [PATCH] Named reference typos & misc.) Bart Schaefer
2023-02-16 15:52             ` Peter Stephenson
2023-02-16 18:17               ` Bart Schaefer
2023-02-16 19:28                 ` Bart Schaefer
2023-02-16 23:10                 ` Bart Schaefer
2023-02-21 11:47                 ` Peter Stephenson
2023-02-21 12:11                   ` Peter Stephenson
2023-02-21 15:57                     ` Bart Schaefer
2023-02-15 10:12         ` [PATCH] Named reference typos & misc Peter Stephenson
2023-02-15 10:36           ` Peter Stephenson
2023-02-15 14:58             ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).