From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Named reference typos & misc.
Date: Mon, 13 Feb 2023 18:08:51 -0800 [thread overview]
Message-ID: <CAH+w=7YRxyV6sj4eobpgo3aEgw3MOZj6jJ9bhi+acJn=ywbVAA@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2023-02-14 2:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 2:08 Bart Schaefer [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7YRxyV6sj4eobpgo3aEgw3MOZj6jJ9bhi+acJn=ywbVAA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).