zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Ghastly typeset -p array hack finally bites the dust
@ 2015-12-04 15:34 Peter Stephenson
  2015-12-04 17:29 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-12-04 15:34 UTC (permalink / raw)
  To: Zsh Hackers' List

diff --git a/Src/params.c b/Src/params.c
index aed72d4..8cab969 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5182,9 +5182,6 @@ printparamvalue(Param p, int printflags)
     }
     if (printflags & PRINT_KV_PAIR)
 	putchar(' ');
-    else if ((printflags & PRINT_TYPESET) &&
-	     (PM_TYPE(p->node.flags) == PM_ARRAY || PM_TYPE(p->node.flags) == PM_HASHED))
-	printf("%s=", p->node.nam);
     else
 	putchar('=');
 
@@ -5255,7 +5252,6 @@ mod_export void
 printparamnode(HashNode hn, int printflags)
 {
     Param p = (Param) hn;
-    int array_typeset;
 
     if (p->node.flags & PM_UNSET) {
 	if (isset(POSIXBUILTINS) && (p->node.flags & PM_READONLY) &&
@@ -5280,28 +5276,8 @@ printparamnode(HashNode hn, int printflags)
 	     */
 	    return;
 	}
-	/*
-	 * Printing the value of array: this needs to be on
-	 * a separate line so more care is required.
-	 */
-	array_typeset = (PM_TYPE(p->node.flags) == PM_ARRAY ||
-			 PM_TYPE(p->node.flags) == PM_HASHED) &&
-	    !(printflags & PRINT_NAMEONLY);
-	if (array_typeset && (p->node.flags & PM_READONLY)) {
-	    /*
-	     * We need to create the array before making it
-	     * readonly.
-	     */
-	    printf("typeset -a ");
-	    zputs(p->node.nam, stdout);
-	    putchar('\n');
-	    printparamvalue(p, printflags);
-	    printflags |= PRINT_NAMEONLY;
-	}
 	printf("typeset ");
     }
-    else
-	array_typeset = 0;
 
     /* Print the attributes of the parameter */
     if (printflags & (PRINT_TYPE|PRINT_TYPESET)) {
@@ -5349,8 +5325,6 @@ printparamnode(HashNode hn, int printflags)
     } else {
 	quotedzputs(p->node.nam, stdout);
 
-	if (array_typeset)
-	    putchar('\n');
 	printparamvalue(p, printflags);
     }
 }
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index fc8b3e4..7d65cc8 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -454,8 +454,7 @@
  fn() { typeset -p array nonexistent; }
  fn
 1:declare -p shouldn't create scoped values
->typeset -a array
->array=( foo bar )
+>typeset -a array=( foo bar )
 ?fn:typeset: no such variable: nonexistent
 
  unsetopt typesetsilent
@@ -508,11 +507,8 @@
   typeset -pm 'a[12]'
   typeset -pm 'r[12]'
 0:readonly -p output
->typeset -a a1
->a1=( one two )
->typeset -ar a1
->typeset -a a2
->a2=( three four )
+>typeset -ar a1=( one two )
+>typeset -a a2=( three four )
 >typeset -r r1=yes
 >typeset -r r2=no
 
@@ -707,8 +703,6 @@
   fn
   print $array
 0:setting empty array in typeset
->typeset -a array
->array=( '' two '' four )
->typeset -a array
->array=( one '' three )
+>typeset -a array=( '' two '' four )
+>typeset -a array=( one '' three )
 >no really nothing here
diff --git a/Test/V10private.ztst b/Test/V10private.ztst
index 513a3c4..320e357 100644
--- a/Test/V10private.ztst
+++ b/Test/V10private.ztst
@@ -127,12 +127,9 @@
  outer
  print ${(kv)hash_test}
 0:private hides value from surrounding scope in nested scope
->typeset -a hash_test
->hash_test=( top level )
->typeset -A hash_test
->hash_test=( in function )
->typeset -a hash_test
->hash_test=( top level )
+>typeset -a hash_test=( top level )
+>typeset -A hash_test=( in function )
+>typeset -a hash_test=( top level )
 >array-local top level
 >top level
 F:note "typeset" rather than "private" in output from outer


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

* Re: PATCH: Ghastly typeset -p array hack finally bites the dust
  2015-12-04 15:34 PATCH: Ghastly typeset -p array hack finally bites the dust Peter Stephenson
@ 2015-12-04 17:29 ` Bart Schaefer
  2015-12-04 17:56   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2015-12-04 17:29 UTC (permalink / raw)
  To: Zsh Hackers' List

So we're just going to ignore the possibility that the typeset keyword
has been disabled?

I'm fine with that, as long as it's explicitly acknowledged.  Also the doc
should contain a warning about this side-effect of disable, someplace.


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

* Re: PATCH: Ghastly typeset -p array hack finally bites the dust
  2015-12-04 17:29 ` Bart Schaefer
@ 2015-12-04 17:56   ` Peter Stephenson
  2015-12-04 18:06     ` "disable typeset" (was Re: PATCH: Ghastly typeset -p array hack finally bites the dust) Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-12-04 17:56 UTC (permalink / raw)
  To: Zsh Hackers' List

On Fri, 04 Dec 2015 09:29:23 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> So we're just going to ignore the possibility that the typeset keyword
> has been disabled?

Yes, I think it's a "so don't do that, then".  We don't generally check
if something's enabled before outputting code that uses it.  Also, there
are already assumptions built into the use of "typeset -p" output that
the shell is in a pristine state e.g. the readonly parameters don't yet
exist.

> I'm fine with that, as long as it's explicitly acknowledged.  Also the doc
> should contain a warning about this side-effect of disable, someplace.

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 49806e4..120ec82 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -1812,7 +1812,10 @@ this means.
 Note that each interface to any of the commands my be disabled
 separately.  For example, `tt(disable -r typeset)' disables the reserved
 word interface to tt(typeset), exposing the builtin interface, while
-`tt(disable typeset)' disables the builtin.
+`tt(disable typeset)' disables the builtin.  Note that disabling the
+reserved word interface for tt(typeset) may cause problems with the
+output of `tt(typeset -p)', which assumes the reserved word interface is
+available in order to restore array and associative array values.
 
 If the shell option tt(TYPESET_SILENT) is not set, for each remaining
 var(name) that refers to a parameter that is already set, the name and

pws


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

* "disable typeset" (was Re: PATCH: Ghastly typeset -p array hack finally bites the dust)
  2015-12-04 17:56   ` Peter Stephenson
@ 2015-12-04 18:06     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-12-04 18:06 UTC (permalink / raw)
  To: Zsh Hackers' List

On Dec 4,  5:56pm, Peter Stephenson quoted the doc:
}
}  Note that each interface to any of the commands my be disabled
}  separately.  For example, `tt(disable -r typeset)' disables the reserved
}  word interface to tt(typeset), exposing the builtin interface, while
} -`tt(disable typeset)' disables the builtin.

Hmm, I just noticed that "disable typeset" doesn't accomplish anything
(except make "builtin typeset" fail) without "disable -r typeset" too.

Not sure what I expected to happen, or why anyone would do this anyway.


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

end of thread, other threads:[~2015-12-04 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 15:34 PATCH: Ghastly typeset -p array hack finally bites the dust Peter Stephenson
2015-12-04 17:29 ` Bart Schaefer
2015-12-04 17:56   ` Peter Stephenson
2015-12-04 18:06     ` "disable typeset" (was Re: PATCH: Ghastly typeset -p array hack finally bites the dust) Bart Schaefer

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