zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] First try of null typeset
@ 2020-12-01  9:13 Felipe Contreras
  2020-12-02 18:47 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Felipe Contreras @ 2020-12-01  9:13 UTC (permalink / raw)
  To: zsh-workers; +Cc: Bart Schaefer, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

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



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

end of thread, other threads:[~2020-12-03  9:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01  9:13 [PATCH] First try of null typeset Felipe Contreras
2020-12-02 18:47 ` Bart Schaefer
2020-12-02 21:59   ` Felipe Contreras
2020-12-03  8:44     ` Roman Perepelitsa
2020-12-03  9:18       ` Felipe Contreras

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).