1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-10 12:40:58 +02:00

39758: revise 39704 for array and hash parameters; more POSIXBUITINS tweaks for

export

39704 was commit 0f5e670, forgot to reference article number in that log.

"typeset -p" outputs "typeset" for array and hash parameters, even when
exported, because those types can be marked export but are never pushed
to the enviroment.

For POSIXBUILTINS, "export var" does not implicitly set $var, and its
export state is preserved when assigned (but not when explicitly unset).
This commit is contained in:
Barton E. Schaefer 2016-10-29 11:56:50 -07:00
parent 87c951c6bd
commit ab81b98c49
3 changed files with 26 additions and 12 deletions

View file

@ -1,3 +1,11 @@
2016-10-29 Barton E. Schaefer <schaefer@zsh.org>
* 39758: Src/builtin.c, Src/params.c: revise 39704 to output
"typeset" for array and hash parameters, even when exported; for
POSIXBUILTINS, "export var" does not implicitly set $var, and its
export state is preserved when assigned (but not when explicitly
unset).
2016-10-28 Daniel Shahaf <d.s@daniel.shahaf.name> 2016-10-28 Daniel Shahaf <d.s@daniel.shahaf.name>
* users/22036: Doc/Zsh/zle.yo: bracketed-paste: Document * users/22036: Doc/Zsh/zle.yo: bracketed-paste: Document

View file

@ -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 * handled in createparam(). Here we just avoid using it for the
* present tests if it's unset. * present tests if it's unset.
* *
* POSIXBUILTINS horror: we need to retain the 'readonly' flag * POSIXBUILTINS horror: we need to retain the 'readonly' or 'export'
* of an unset parameter. * flags of an unset parameter.
*/ */
usepm = pm && (!(pm->node.flags & PM_UNSET) || 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, * 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. * 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)) !ASG_VALUEP(asg))
on |= PM_UNSET; on |= PM_UNSET;
else if (usepm && (pm->node.flags & PM_READONLY) && 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); zerr("read-only variable: %s", pm->node.nam);
return NULL; return NULL;
} }
/* This is handled by createparam():
if (usepm && (pm->node.flags & PM_EXPORTED) && !(off & PM_EXPORTED))
on |= PM_EXPORTED;
*/
} }
/* /*

View file

@ -940,7 +940,10 @@ createparam(char *name, int flags)
zerr("%s: restricted", name); zerr("%s: restricted", name);
return NULL; 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; oldpm->node.flags &= ~PM_UNSET;
if ((oldpm->node.flags & PM_SPECIAL) && oldpm->ename) { if ((oldpm->node.flags & PM_SPECIAL) && oldpm->ename) {
Param altpm = Param altpm =
@ -5225,10 +5228,6 @@ printparamvalue(Param p, int printflags)
{ {
char *t, **u; char *t, **u;
if ((p->node.flags & PM_EXPORTED) && !p->env) {
putchar('\n');
return;
}
if (printflags & PRINT_KV_PAIR) if (printflags & PRINT_KV_PAIR)
putchar(' '); putchar(' ');
else else
@ -5332,7 +5331,8 @@ printparamnode(HashNode hn, int printflags)
} }
if (locallevel && p->level >= locallevel) { if (locallevel && p->level >= locallevel) {
printf("typeset "); /* printf("local "); */ 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 "); printf("export ");
} else if (locallevel) { } else if (locallevel) {
printf("typeset -g "); printf("typeset -g ");
@ -5350,8 +5350,8 @@ printparamnode(HashNode hn, int printflags)
if (pmptr->flags & PMTF_TEST_LEVEL) { if (pmptr->flags & PMTF_TEST_LEVEL) {
if (p->level) if (p->level)
doprint = 1; doprint = 1;
} else if ((pmptr->binflag != PM_EXPORTED || } else if ((pmptr->binflag != PM_EXPORTED || p->level ||
((p->node.flags & PM_LOCAL) || p->level)) && (p->node.flags & (PM_LOCAL|PM_ARRAY|PM_HASHED))) &&
(p->node.flags & pmptr->binflag)) (p->node.flags & pmptr->binflag))
doprint = 1; doprint = 1;