From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26797 invoked from network); 23 Dec 2020 23:47:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Dec 2020 23:47:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1608767257; b=i785yyyXcyVUcR0tfC/XzLQ0XzJfzMFxv/W9i5M8KOJVMA9YdhpQcOWs62KvoSyB0NEp54W6G5 QA4+UEJBapdukeJFZy1Eq9y0bJ+8dNZM2ZHiSDe1aQtznRhZYGd6ZGkn1j1lrwXiDxG0eBZrCY CzvkzO/G6w1aBN6U49dhdEhTJdypM/5lfN45HF8i8pVe3LnscVD9H0j2RtIm3E3eLcEP9yXY4Z QotJDJ01CWNX9uIj4bv+8l7ewjcTkjZ/XIvtwo0sqfPtdaM147dF+he4s7h9XI9pgoNU6l+44r SnrMc9Z6t6Ncpw4KeMoy5is2Ton0jFBrvP8oE4B6F6N3Lg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1608767257; bh=5aS4PSYUbLM2+lQuPRwweoDF6vUuyCx4/W6xrk8ftOM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:Cc:To:From:DKIM-Signature:DKIM-Signature; b=09NE5kYsTjR8icrIlR/YPNncx93PnEkGpi5Ba1byIZdvEFSizxn+yGogGOqPpVx91Qk1YkliF/ 0OIn1Jgqb1pT+jV9lSwhWGpsflvz4DOCVp7EiD3TRE193kBpZOEXI5x3Yam1fMmI+8DDSKgYTY b9CxqvL3rTegH4JuqIlL9p/WMXND9B1SDU5pMx2699iysWmNOmWVi3KcTizueolxF68ewfJW4W hBPiUn5E09DLzwFW06/XhWwizjD5DmwmMez4PYLR9pR5/wHrfwHyJXvSWYbEQVZkJQvsZWCF2I MvKBjFnaBAgusOjy3HH1Mf4IOmZhoghAxJE9ZNzozieVBw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=FAeKNHdFAKYtC2vOz37kzew16lrbcBZH9X/OXkx7brE=; b=QYmEtCcj4LY5V8Hpf2TTvgSg0n KJBQSYA6+3+vLguQfc5b9ofNwHocGQXvvexiHhoFJZPyJeJfhzdyftiFQMkrtDgoN91EJ2XgA/+ho i5X9nKCtYC3hG6+N9RNBEfGaTbkHh5hsW/Ai8tMEfOZqRw0zkEodmCGASA5/IiuNcCxgrPYS5D7N0 xUG+6kVbF+HfJL2GtG93FOSON9ecZcB9MJnoj9fcMAsWKRsNc7zIm452pBeli95O0LV8didwnNctq fBjU3oIa8jjxBi7n7KmrGgoji7lr53a2QG6y/Jxzm0/6DHghx49GcgV8vEOIsE/lcyNoKYa5iEsJt u2Wawhkg==; Received: from authenticated user by zero.zsh.org with local id 1ksDqy-0003nX-5j; Wed, 23 Dec 2020 23:47:36 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-oi1-f180.google.com ([209.85.167.180]:34244) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ksDqd-0003dy-6a; Wed, 23 Dec 2020 23:47:17 +0000 Received: by mail-oi1-f180.google.com with SMTP id s75so852447oih.1 for ; Wed, 23 Dec 2020 15:47:15 -0800 (PST) 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=FAeKNHdFAKYtC2vOz37kzew16lrbcBZH9X/OXkx7brE=; b=EgBNmMrtONLrmMvkBD5Z6eqTImMQCxLYVzYs3shIY3S3m4taRE6wpEDenj25SS5bjj I43AwQUaW0OxdVbXLGuKj8LcO9bYx3tdCEWj9d9MrUOKVgULfBpdh6Wil+uAM8bH5/m3 j8r1HGU53U3TNmV3mUvcnRfJ3OWWnmYSVfaDx+LQG6tE4YBtw5nsljG6gs+uTp/kZsJ8 Zx5zLHkRfKvTtfpx3o51SDOk+g086wPF0H/h/kHQzfW71zXc36jCr4xeZ203p2vCFlxi ZFbou+z8erKzV3gCmkM8E3WXnVFPDbQx7VekNMWyH0DlNuC1KPCz4fVHjlNASkoKpGOP WBjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FAeKNHdFAKYtC2vOz37kzew16lrbcBZH9X/OXkx7brE=; b=rgR+T2HfATCAVrHBs70kXQBptftFddH96uyBmtjYOZ4xIPXkiYmyuigi4CAwY+2me9 w1dr4lUAQRHF16ttdHjvv1UlOl7n1hwnQ1PVh/jbeJNE8QAQbyb4TidYDA7sOLUB+eLt rJk5T2q6wSpjq1Tq/OgwP1fMZ5NL3IGF73zYmyQJhDBMYOKL13qknM15UUUa116n/SvF IWmbOXLT6UI3/rzir+zmOxnwC0NdfCZIk9zxR3dqxGSPUdfmk17i94AmAhsvw5oIPxGB QK0/l8LjthWMz82hdDIeb0dnnQfBCzWAU4lPgpAB9zgTQoEP9L7LbsdGExbcGHExf79X PYnw== X-Gm-Message-State: AOAM531ZddkmENTbfldp+vvrEroLg3o/WoAumqWps4LedavHuTxJ4yp9 GeRhoM0sZ9T0hQD3RPxr1tn8ksOsXNmr7A== X-Google-Smtp-Source: ABdhPJxmX7NGYNmclrKbWZwDFV8C8jzEnVaKanwgShlThgC5ZZEUdNbTbd0bzT7qfH69wv5lRIw4Bg== X-Received: by 2002:a54:479a:: with SMTP id o26mr1433760oic.48.1608767233643; Wed, 23 Dec 2020 15:47:13 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id s66sm5016998ooa.37.2020.12.23.15.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 15:47:13 -0800 (PST) From: Felipe Contreras To: zsh-workers@zsh.org Cc: Bart Schaefer , Felipe Contreras Subject: [PATCH] declarednull: felipec's approach Date: Wed, 23 Dec 2020 17:47:11 -0600 Message-Id: <20201223234711.492603-1-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 47757 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: This patch merges Bart's approach with my approach, and should be applied on top of the branch declarednull. The main difference is that PM_DECLAREDNULL does not set PM_UNSET. So in the two relevant places where PM_UNSET should be checked, PM_DELCAREDNULL is checked too. In my branch it's actually called PM_NULL because I think semantically makes more sense. I just renamed it for this patch to minimize the diff. A variable is initially declared with PM_NULL (same as PM_DECLAREDNULL), then, once a value is a assigned, PM_NULL is removed. That's it. Semantically it makes sense. What doesn't make sense is to remove PM_DECLAREDNULL, because it's a combination of PM_UNSET and PM_DECLARED. It makes sense to remove PM_UNSET, but not to remove PM_DECLARED. Why would this local var var=foobar remove PM_DELCARED? Additionally it's not clear why unset should clear the PM_DECLAREDNULL flag. PM_UNSET is going to be immediately set anyway, and PM_DECLARED is set only when there's no value (essentially PM_NULL), so it's kind of returning to var='' (assuming there's a value). I added a test that shows a discrepancy I found (${(t)var}) but there could be many, may more. I only checked one instance of PM_UNSET. Signed-off-by: Felipe Contreras --- Src/builtin.c | 2 +- Src/params.c | 11 ++++------- Src/subst.c | 2 +- Src/zsh.h | 3 +-- Test/E03posix.ztst | 8 ++++++++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Src/builtin.c b/Src/builtin.c index 1e950f122..988233504 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2837,7 +2837,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) unqueue_signals(); return 1; } else if (pm) { - if ((!(pm->node.flags & PM_UNSET) || pm->node.flags & PM_DECLARED) + if (!(pm->node.flags & PM_UNSET) && (locallevel == pm->level || !(on & PM_LOCAL))) { if (pm->node.flags & PM_TIED) { if (PM_TYPE(pm->node.flags) != PM_SCALAR) { diff --git a/Src/params.c b/Src/params.c index c09a3eccf..8912a7f65 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2093,8 +2093,7 @@ fetchvalue(Value v, char **pptr, int bracks, int flags) if (sav) *s = sav; *pptr = s; - if (!pm || ((pm->node.flags & PM_UNSET) && - !(pm->node.flags & PM_DECLARED))) + if (!pm || (pm->node.flags & PM_UNSET)) return NULL; if (v) memset(v, 0, sizeof(*v)); @@ -3625,7 +3624,6 @@ unsetparam_pm(Param pm, int altflag, int exp) else altremove = NULL; - pm->node.flags &= ~PM_DECLARED; /* like ksh, not like bash */ if (!(pm->node.flags & PM_UNSET)) pm->gsu.s->unsetfn(pm, exp); if (pm->env) @@ -5854,9 +5852,8 @@ printparamnode(HashNode hn, int printflags) Param peer = NULL; if (p->node.flags & PM_UNSET) { - if ((printflags & (PRINT_POSIX_READONLY|PRINT_POSIX_EXPORT) && - p->node.flags & (PM_READONLY|PM_EXPORTED)) || - (p->node.flags & PM_DECLAREDNULL) == PM_DECLAREDNULL) { + if (printflags & (PRINT_POSIX_READONLY|PRINT_POSIX_EXPORT) && + p->node.flags & (PM_READONLY|PM_EXPORTED)) { /* * Special POSIX rules: show the parameter as readonly/exported * even though it's unset, but with no value. @@ -5971,7 +5968,7 @@ printparamnode(HashNode hn, int printflags) } } - if ((printflags & PRINT_NAMEONLY) || + if ((printflags & PRINT_NAMEONLY) || p->node.flags & PM_DECLAREDNULL || ((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..89d6abbba 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) || (v->pm->node.flags & PM_DECLAREDNULL))) || (v->flags & VALFLAG_EMPTY)) vunset = 1; diff --git a/Src/zsh.h b/Src/zsh.h index 6d7f517c6..97d3a142a 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1929,10 +1929,8 @@ struct tieddata { made read-only by the user */ #define PM_READONLY_SPECIAL (PM_SPECIAL|PM_READONLY|PM_RO_BY_DESIGN) #define PM_DONTIMPORT (1<<22) /* do not import this variable */ -#define PM_DECLARED (1<<22) /* explicitly named with typeset */ #define PM_RESTRICTED (1<<23) /* cannot be changed in restricted mode */ #define PM_UNSET (1<<24) /* has null value */ -#define PM_DECLAREDNULL (PM_DECLARED|PM_UNSET) #define PM_REMOVABLE (1<<25) /* special can be removed from paramtab */ #define PM_AUTOLOAD (1<<26) /* autoloaded from module */ #define PM_NORESTORE (1<<27) /* do not restore value of local special */ @@ -1942,6 +1940,7 @@ struct tieddata { */ #define PM_HASHELEM (1<<28) /* is a hash-element */ #define PM_NAMEDDIR (1<<29) /* has a corresponding nameddirtab entry */ +#define PM_DECLAREDNULL (1<<30) /* declared but null */ /* The option string corresponds to the first of the variables above */ #define TYPESET_OPTSTR "aiEFALRZlurtxUhHTkz" diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index 5e6eddeba..b66782eea 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -103,3 +103,11 @@ >arg1 arg2 >noktarg1 >0 0 + + f () { + local var + print ${(t)var} + } + f +0:(t) returns correct type +>scalar-local -- 2.30.0.rc1