zsh-workers
 help / color / mirror / Atom feed
* Re: More typeset bugs: POSIX_BUILTINS
       [not found] <CAH+w=7aYGZgF25Hypw=s31u5hfTT-Y+6pKzrCuD-1kB=1pShOg@mail.gmail.com>
@ 2020-11-29 20:12 ` Stephane Chazelas
  2020-11-29 20:18   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Stephane Chazelas @ 2020-11-29 20:12 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

2020-11-29 10:19:44 -0800, Bart Schaefer:
> In printparamnode is this comment:
> 
>       * Special POSIX rules: show the parameter as readonly/exported
>       * even though it's unset, but with no value.
[...]
> % readonly -p OUTER
[...]
> % export -p INNER
[...]

FWIW, though I'd agree it's a bug, it's not a POSIX
non-compliance as the behaviour for "readonly/export -p var" is
unspecified by POSIX, POSIX only specifies "readonly/export -p"
without arguments.

AFAICT, zsh and yash are the only shells that output the
definition of HOME in export -p HOME.

-- 
Stephane


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

* Re: More typeset bugs: POSIX_BUILTINS
  2020-11-29 20:12 ` More typeset bugs: POSIX_BUILTINS Stephane Chazelas
@ 2020-11-29 20:18   ` Bart Schaefer
  2020-11-30 17:07     ` Bart Schaefer
  2020-11-30 17:14     ` Stephane Chazelas
  0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2020-11-29 20:18 UTC (permalink / raw)
  To: Zsh hackers list

On Sun, Nov 29, 2020 at 12:12 PM Stephane Chazelas
<stephane@chazelas.org> wrote:
>
> FWIW, though I'd agree it's a bug, it's not a POSIX
> non-compliance as the behaviour for "readonly/export -p var" is
> unspecified by POSIX, POSIX only specifies "readonly/export -p"
> without arguments.

Both bash and ksh ignore -p for readonly/export when there are any
non-option arguments, and therefore create/assign the named variables.

So this is at least a ksh emulation incompatibility.


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

* Re: More typeset bugs: POSIX_BUILTINS
  2020-11-29 20:18   ` Bart Schaefer
@ 2020-11-30 17:07     ` Bart Schaefer
  2020-11-30 17:14     ` Stephane Chazelas
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2020-11-30 17:07 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

On Sun, Nov 29, 2020 at 12:18 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> Both bash and ksh ignore -p for readonly/export when there are any
> non-option arguments, and therefore create/assign the named variables.

In the event that we want to change this, patch attached.

The param_private.c diff should be applied either way.

[-- Attachment #2: ro-p-diff.txt --]
[-- Type: text/plain, Size: 3628 bytes --]

diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c
index 86416c5c5..24545819d 100644
--- a/Src/Modules/param_private.c
+++ b/Src/Modules/param_private.c
@@ -171,6 +171,7 @@ bin_private(char *nam, char **args, LinkList assigns, Options ops, int func)
 {
     int from_typeset = 1;
     int ofake = fakelevel;	/* paranoia in case of recursive call */
+    int hasargs = *args != NULL || (assigns && firstnode(assigns));
     makeprivate_error = 0;
 
     if (!OPT_ISSET(ops, 'P')) {
@@ -190,6 +191,9 @@ bin_private(char *nam, char **args, LinkList assigns, Options ops, int func)
     }
 
     ops->ind['g'] = 2;	/* force bin_typeset() to behave as "local" */
+    if (OPT_ISSET(ops, 'p') || (!hasargs && OPT_ISSET(ops, '+'))) {
+	return bin_typeset("private", args, assigns, ops, func);
+    }
 
     queue_signals();
     fakelevel = locallevel;
diff --git a/Src/builtin.c b/Src/builtin.c
index 09eb3728c..3d52d563f 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2612,7 +2612,12 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
     int on = 0, off = 0, roff, bit = PM_ARRAY;
     int i;
     int returnval = 0, printflags = 0;
-    int hasargs;
+    int hasargs = *argv != NULL || (assigns && firstnode(assigns));
+
+    /* POSIXBUILTINS is set for bash/ksh and both ignore -p with args */
+    if ((func == BIN_READONLY || func == BIN_EXPORT) &&
+	isset(POSIXBUILTINS) && hasargs)
+	ops->ind['p'] = 0;
 
     /* hash -f is really the builtin `functions' */
     if (OPT_ISSET(ops,'f'))
@@ -2692,7 +2697,6 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    /* -p0 treated as -p for consistency */
 	}
     }
-    hasargs = *argv != NULL || (assigns && firstnode(assigns));
     if (!hasargs) {
 	int exclude = 0;
 	if (!OPT_ISSET(ops,'p')) {
diff --git a/Src/params.c b/Src/params.c
index 122f5da7d..29c1653af 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5867,8 +5867,12 @@ printparamnode(HashNode hn, int printflags)
 	 * don't.
 	 */
 	if (printflags & PRINT_POSIX_EXPORT) {
+	    if (!(p->node.flags & PM_EXPORTED))
+		return;
 	    printf("export ");
 	} else if (printflags & PRINT_POSIX_READONLY) {
+	    if (!(p->node.flags & PM_READONLY))
+		return;
 	    printf("readonly ");
 	} else if (locallevel && p->level >= locallevel) {
 	    printf("typeset ");	    /* printf("local "); */
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index e7bf93794..8b3988151 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -620,7 +620,7 @@
    print ${+pbro} >&2
    (typeset -g pbro=3)
    (pbro=4)
-   readonly -p pbro >&2   # shows up as "readonly" although unset
+   readonly -p >&2        # shows up as "readonly" although unset
    typeset -gr pbro       # idempotent (no error)...
    print ${+pbro} >&2     # ...so still readonly...
    typeset -g +r pbro     # ...can't turn it off
@@ -1050,23 +1050,21 @@
 
  $ZTST_testdir/../Src/zsh --emulate sh -f -c '
  PATH=/bin; export PATH; readonly PATH
- export -p PATH
+ export -p PATH		# Should be a no-op, -p ignored
  typeset -p PATH
  readonly -p'
 0: readonly/export output for exported+readonly+special when started as sh
->export PATH=/bin
 >export -r PATH=/bin
 >readonly PATH=/bin
 
  function {
  emulate -L sh
  MANPATH=/bin; export MANPATH; readonly MANPATH
- export -p MANPATH
+ export -p MANPATH	# Should be a no-op, -p ignored
  typeset -p MANPATH
  readonly -p
  }
 0: readonly/export output for exported+readonly+tied+special after switching to sh emulation
->export MANPATH=/bin
 >export -rT MANPATH manpath=( /bin )
 >readonly MANPATH=/bin
 

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

* Re: More typeset bugs: POSIX_BUILTINS
  2020-11-29 20:18   ` Bart Schaefer
  2020-11-30 17:07     ` Bart Schaefer
@ 2020-11-30 17:14     ` Stephane Chazelas
  1 sibling, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2020-11-30 17:14 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

2020-11-29 12:18:29 -0800, Bart Schaefer:
> On Sun, Nov 29, 2020 at 12:12 PM Stephane Chazelas
> <stephane@chazelas.org> wrote:
> >
> > FWIW, though I'd agree it's a bug, it's not a POSIX
> > non-compliance as the behaviour for "readonly/export -p var" is
> > unspecified by POSIX, POSIX only specifies "readonly/export -p"
> > without arguments.
> 
> Both bash and ksh ignore -p for readonly/export when there are any
> non-option arguments, and therefore create/assign the named variables.
> 
> So this is at least a ksh emulation incompatibility.

Yes, I had assumed "-p" was for "print", but it looks like it's
more for "POSIX" / "portable" (though neither bash nor zsh give
portable output upon "export -p" when not in posix mode)

With that in mind, it makes more sense now that 
export -p foo
could be expected to do anything else than print the definition
of foo.

Still, I can't see why anyone would write that as the "-p" has
no effect if the intention is to export foo.

While yash and zsh agree on "export -p HOME" printing the
definition of HOME, "export -p HOME=bar" sets HOME to bar
in yash and ignores -p, while in zsh, it prints the current
value of HOME and ignores =bar.

-- 
Stephane


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

end of thread, other threads:[~2020-11-30 17:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAH+w=7aYGZgF25Hypw=s31u5hfTT-Y+6pKzrCuD-1kB=1pShOg@mail.gmail.com>
2020-11-29 20:12 ` More typeset bugs: POSIX_BUILTINS Stephane Chazelas
2020-11-29 20:18   ` Bart Schaefer
2020-11-30 17:07     ` Bart Schaefer
2020-11-30 17:14     ` Stephane Chazelas

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git