Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] First try of null typeset
- X-seq: zsh-workers 47708
- From: Felipe Contreras <felipe.contreras@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] First try of null typeset
- Date: Tue, 1 Dec 2020 03:13:42 -0600
- Archived-at: <https://zsh.org/workers/47708>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-12/20201201091342.310763-1-felipe.contreras%40gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-oi1-f194.google.com) smtp.remote-ip=209.85.167.194; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Felipe Contreras <felipe.contreras@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qWJbhNNKYpdUnqUdiyY31FlBX96s2hVvtyph0o78I6U=; b=k/Z4pkDa2FKb6l86PkrOFb+Eid86HovWOdeN1l+1Bl3y9dXBpLISusH4MVLRJ0ba7I ZFmpkGcbwdtiOF3qNN2T2ul6fndhqXMR4l/n7Z/WRdiNhHuLfA/8Z0EFnp0Xn/wiwztH nqFuOi6YTdo2xMSxjI+zMxq89Hw+vkJdro2Y8HIvZ6yb1eHBWHd3w+1ro7U4MXa3/7qi yJuWNKQp4bJ6vHUJ8d1QZrsBVxqPJHUnUze1wQRsMGc/fAg5eeDnt/xvWrzSU0x3ovps 95+3ljaB1sFXoh3Kl5lHpI9aDVeRLRXQ65UbPFioC0ZTNsgj0YtdcXZj/ksBj+J6EGch Q8Jw==
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- Sender: zsh-workers-request@xxxxxxx
Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
This achieves most of what Bart Schaefer's version achieves, except no extra hacks are needed, and
integer and floats are not changed.
This most definetly is not close to the final solution, but shows what can be achieved by narrowing
down the functional changes to two functions.
In my opinion a separate concept of "null" variable will be needed, and should be separate from
PM_UNSET, since that changes a lot of behavior.
Also, I don't think $empty[(i)] should return nothing, so probably paramsubst() would need to be
tuned, not simply set vunset=1.
Addtionally, this patch doesn't change the behavior of the private module.
Src/params.c | 23 ++++++++++++++++++++++-
Src/subst.c | 2 +-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Src/params.c b/Src/params.c
index 122f5da7d..7dbe67bd1 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3697,6 +3697,27 @@ unsetparam_pm(Param pm, int altflag, int exp)
return 0;
}
+/**/
+mod_export int
+isnull(Param pm)
+{
+ switch (PM_TYPE(pm->node.flags)) {
+ case PM_SCALAR:
+ if (pm->gsu.s->getfn == strgetfn && !pm->u.str)
+ return 1;
+ break;
+ case PM_ARRAY:
+ if (pm->gsu.a->getfn == arrgetfn && !pm->u.arr)
+ return 1;
+ break;
+ case PM_HASHED:
+ if (pm->gsu.h->getfn == hashgetfn && !pm->u.hash)
+ return 1;
+ break;
+ }
+ return 0;
+}
+
/* Standard function to unset a parameter. This is mostly delegated to *
* the specific set function.
*
@@ -5955,7 +5976,7 @@ printparamnode(HashNode hn, int printflags)
}
}
- if ((printflags & PRINT_NAMEONLY) ||
+ if ((printflags & PRINT_NAMEONLY) || isnull(p) ||
((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE)))
quotedzputs(p->node.nam, stdout);
else {
diff --git a/Src/subst.c b/Src/subst.c
index 8f5bd355e..42d18d58d 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2532,7 +2532,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
(wantt ? -1 :
((unset(KSHARRAYS) || inbrace) ? 1 : -1)),
scanflags)) ||
- (v->pm && (v->pm->node.flags & PM_UNSET)) ||
+ (v->pm && (v->pm->node.flags & PM_UNSET || isnull(v->pm))) ||
(v->flags & VALFLAG_EMPTY))
vunset = 1;
--
2.29.2
Messages sorted by:
Reverse Date,
Date,
Thread,
Author