zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: exported unset variables [was: 'export -p' lacks POSIX output]
Date: Sat, 29 Oct 2016 11:09:04 -0700	[thread overview]
Message-ID: <161029110904.ZM2918@torch.brasslantern.com> (raw)
In-Reply-To: <6db9e2a5-8f0b-71a2-95e6-8a8bbf4a281e@inlv.org>

On Oct 29,  9:11am, Martijn Dekker wrote:
} Subject: Re: exported unset variables [was: 'export -p' lacks POSIX output
}
} % var=; echo ${var+set} ${var-unset}; typeset -p var
} set
} typeset var=''
} 
} The variable name loses its export attribute upon assignment; it should
} retain it.

That one potentially gets rather ugly; consider:

% setopt POSIXBUILTINS
% export var
% var=()
zsh: var: attempt to assign array value to non-array

Is that OK with everyone?

As an aside, zsh currently allows the export flag to be applied to array
variables, but then will not put them in the environment.  Patch below
revises 39704 to use "typeset -xa ary" rather than "export -a ary".

Replaces 39754.


diff --git a/Src/builtin.c b/Src/builtin.c
index 2db739f..986ace2 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2008,11 +2008,12 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
      * handled in createparam().  Here we just avoid using it for the
      * present tests if it's unset.
      *
-     * POSIXBUILTINS horror: we need to retain the 'readonly' flag
-     * of an unset parameter.
+     * POSIXBUILTINS horror: we need to retain the 'readonly' or 'export'
+     * flags of an unset parameter.
      */
     usepm = pm && (!(pm->node.flags & PM_UNSET) ||
-		   (isset(POSIXBUILTINS) && (pm->node.flags & PM_READONLY)));
+		   (isset(POSIXBUILTINS) &&
+		    (pm->node.flags & (PM_READONLY|PM_EXPORTED))));
 
     /*
      * We need to compare types with an existing pm if special,
@@ -2135,7 +2136,8 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	/*
 	 * Stricter rules about retaining readonly attribute in this case.
 	 */
-	if ((on & PM_READONLY) && (!usepm || (pm->node.flags & PM_UNSET)) &&
+	if ((on & (PM_READONLY|PM_EXPORTED)) &&
+	    (!usepm || (pm->node.flags & PM_UNSET)) &&
 	    !ASG_VALUEP(asg))
 	    on |= PM_UNSET;
 	else if (usepm && (pm->node.flags & PM_READONLY) &&
@@ -2143,6 +2145,10 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	    zerr("read-only variable: %s", pm->node.nam);
 	    return NULL;
 	}
+	/* This is handled by createparam():
+	if (usepm && (pm->node.flags & PM_EXPORTED) && !(off & PM_EXPORTED))
+	    on |= PM_EXPORTED;
+	*/
     }
 
     /*
diff --git a/Src/params.c b/Src/params.c
index 3084b1f..330f22b 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -940,7 +940,10 @@ createparam(char *name, int flags)
 		zerr("%s: restricted", name);
 		return NULL;
 	    }
-	    if (!(oldpm->node.flags & PM_UNSET) || (oldpm->node.flags & PM_SPECIAL)) {
+	    if (!(oldpm->node.flags & PM_UNSET) ||
+		(oldpm->node.flags & PM_SPECIAL) ||
+		/* POSIXBUILTINS horror: we need to retain 'export' flags */
+		(isset(POSIXBUILTINS) && (oldpm->node.flags & PM_EXPORTED))) {
 		oldpm->node.flags &= ~PM_UNSET;
 		if ((oldpm->node.flags & PM_SPECIAL) && oldpm->ename) {
 		    Param altpm =
@@ -5225,10 +5228,6 @@ printparamvalue(Param p, int printflags)
 {
     char *t, **u;
 
-    if ((p->node.flags & PM_EXPORTED) && !p->env) {
-	putchar('\n');
-	return;
-    }
     if (printflags & PRINT_KV_PAIR)
 	putchar(' ');
     else
@@ -5332,7 +5331,8 @@ printparamnode(HashNode hn, int printflags)
 	}
 	if (locallevel && p->level >= locallevel) {
 	    printf("typeset ");	    /* printf("local "); */
-	} else if (p->node.flags & PM_EXPORTED) {
+	} else if ((p->node.flags & PM_EXPORTED) &&
+		   !(p->node.flags & (PM_ARRAY|PM_HASHED))) {
 	    printf("export ");
 	} else if (locallevel) {
 	    printf("typeset -g ");
@@ -5350,8 +5350,8 @@ printparamnode(HashNode hn, int printflags)
 	    if (pmptr->flags & PMTF_TEST_LEVEL) {
 		if (p->level)
 		    doprint = 1;
-	    } else if ((pmptr->binflag != PM_EXPORTED ||
-			((p->node.flags & PM_LOCAL) || p->level)) &&
+	    } else if ((pmptr->binflag != PM_EXPORTED || p->level ||
+			(p->node.flags & (PM_LOCAL|PM_ARRAY|PM_HASHED))) &&
 		       (p->node.flags & pmptr->binflag))
 		doprint = 1;
 


  reply	other threads:[~2016-10-29 18:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-22  3:02 'export -p' lacks POSIX output Martijn Dekker
2016-10-22 18:24 ` Bart Schaefer
2016-10-23 12:00   ` Martijn Dekker
2016-10-23 16:47     ` Bart Schaefer
2016-10-24  8:33   ` Peter Stephenson
2016-10-28 21:00 ` exported unset variables [was: 'export -p' lacks POSIX output] Martijn Dekker
2016-10-28 21:31   ` Bart Schaefer
2016-10-28 21:48     ` Martijn Dekker
2016-10-29  0:18       ` Bart Schaefer
2016-10-29  8:11         ` Martijn Dekker
2016-10-29 18:09           ` Bart Schaefer [this message]
2016-10-29 18:43             ` Peter Stephenson
2016-10-29 19:05           ` Bart Schaefer
2016-10-29 20:20             ` interactive comments [was: exported unset variables] Martijn Dekker
2016-10-30  1:25               ` 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=161029110904.ZM2918@torch.brasslantern.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).