zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] sh/ksh init: don't initialise lowercase parameters
@ 2020-01-28 15:19 ` Martijn Dekker
  2020-01-28 15:26   ` Peter Stephenson
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Martijn Dekker @ 2020-01-28 15:19 UTC (permalink / raw)
  To: Zsh hackers list

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

In POSIX sh and in ksh, it's the convention that lowercase variable 
names are reserved for scripts, and uppercase names may be used by the 
shell or system. So most lowercase zsh parameters are not initialised 
when zsh is invoked as sh or ksh (through a symlink or the --emulate 
option).

However, there are two left that are initialised in sh/ksh mode: 
'histchars' and 'signals'. So this can conflict with POSIX scripts.

Also, if zsh is invoked as sh or ksh, 'histchars' is available whereas 
the 'HISTCHARS' equivalent is not. It seems quite obvious that this 
should be the other way around.

The attached patch makes zsh, when invoked as sh or ksh, not initialise 
'signals', and initialise 'HISTCHARS' instead of 'histchars'. It also 
updates the documentation.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

[-- Attachment #2: posixnames.patch --]
[-- Type: text/plain, Size: 3722 bytes --]

diff --git a/Doc/Zsh/compat.yo b/Doc/Zsh/compat.yo
index f1be15fee..d085dfaa7 100644
--- a/Doc/Zsh/compat.yo
+++ b/Doc/Zsh/compat.yo
@@ -19,7 +19,7 @@ tt(argv),
 tt(cdpath),
 tt(fignore),
 tt(fpath),
-tt(HISTCHARS),
+tt(histchars),
 tt(mailpath),
 tt(MANPATH),
 tt(manpath),
@@ -30,6 +30,7 @@ tt(PROMPT2),
 tt(PROMPT3),
 tt(PROMPT4),
 tt(psvar),
+tt(signals),
 tt(status),
 tt(watch).
 
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 8daf33d5e..5f772bb50 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -850,7 +850,7 @@ item(tt(SHLVL) <S>)(
 Incremented by one each time a new shell is started.
 )
 vindex(signals)
-item(tt(signals))(
+item(tt(signals) <Z>)(
 An array containing the names of the signals.  Note that with
 the standard zsh numbering of array indices, where the first element
 has index 1, the signals are offset by 1 from the signal number
@@ -1161,7 +1161,7 @@ with the tt(-u) attribute is referenced.  If an executable
 file is found, then it is read and executed in the current environment.
 )
 vindex(histchars)
-item(tt(histchars) <S>)(
+item(tt(histchars) <S> <Z>)(
 Three characters used by the shell's history and lexical analysis
 mechanism.  The first character signals the start of a history
 expansion (default `tt(!)').  The second character signals the
@@ -1173,8 +1173,8 @@ tt(histchars) to characters with a locale-dependent meaning will be
 rejected with an error message.
 )
 vindex(HISTCHARS)
-item(tt(HISTCHARS) <S> <Z>)(
-Same as tt(histchars).  (Deprecated.)
+item(tt(HISTCHARS) <S>)(
+Same as tt(histchars).
 )
 vindex(HISTFILE)
 item(tt(HISTFILE))(
diff --git a/NEWS b/NEWS
index af59cb4e6..9d96ef0d1 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,10 @@ has not changed, but code such as the following:
 should be changed either to use 'return' instead of 'exit', or to have
 the try/always block outside of any function.
 
+If the shell is invoked as sh or ksh (through a symlink or with the
+'--emulate' option), the 'HISTCHARS' parameter is now available instead
+of 'histchars', and the 'signals' parameter is not initialised.
+
 Changes from 5.6.2 to 5.7.1
 ---------------------------
 
diff --git a/Src/params.c b/Src/params.c
index 863b32600..699dc7ccd 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -309,7 +309,7 @@ IPDEF1("TTYIDLE", ttyidle_gsu, PM_READONLY_SPECIAL),
 #define IPDEF2(A,B,C) {{NULL,A,PM_SCALAR|PM_SPECIAL|C},BR(NULL),GSU(B),0,0,NULL,NULL,NULL,0}
 IPDEF2("USERNAME", username_gsu, PM_DONTIMPORT|PM_RESTRICTED),
 IPDEF2("-", dash_gsu, PM_READONLY_SPECIAL),
-IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
+IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
 IPDEF2("HOME", home_gsu, PM_UNSET),
 IPDEF2("TERM", term_gsu, PM_UNSET),
 IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET),
@@ -413,7 +413,7 @@ IPDEF8("MODULE_PATH", &module_path, "module_path", PM_DONTIMPORT|PM_RESTRICTED|P
 
 /* All of these have sh compatible equivalents.                */
 IPDEF1("ARGC", argc_gsu, PM_READONLY_SPECIAL),
-IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
+IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
 IPDEF4("status", &lastval),
 IPDEF7("prompt", &prompt),
 IPDEF7("PROMPT", &prompt),
@@ -935,8 +935,10 @@ createparamtable(void)
     setsparam("ZSH_ARGZERO", ztrdup(posixzero));
     setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL));
-    setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));
-    for (t = sigs; (*sigptr++ = ztrdup_metafy(*t++)); );
+    if (!EMULATION(EMULATE_SH|EMULATE_KSH)) {
+	setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));
+	for (t = sigs; (*sigptr++ = ztrdup_metafy(*t++)); );
+    }
 
     noerrs = 0;
 }

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-28 15:19 ` [PATCH] sh/ksh init: don't initialise lowercase parameters Martijn Dekker
@ 2020-01-28 15:26   ` Peter Stephenson
  2020-01-28 15:45     ` Martijn Dekker
  2020-01-29  8:49   ` Daniel Shahaf
  2020-02-01  9:42   ` Daniel Shahaf
  2 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2020-01-28 15:26 UTC (permalink / raw)
  To: zsh-workers

On Tue, 2020-01-28 at 16:19 +0100, Martijn Dekker wrote:
> In POSIX sh and in ksh, it's the convention that lowercase variable 
> names are reserved for scripts, and uppercase names may be used by the 
> shell or system. So most lowercase zsh parameters are not initialised 
> when zsh is invoked as sh or ksh (through a symlink or the --emulate 
> option).
> 
> However, there are two left that are initialised in sh/ksh mode: 
> 'histchars' and 'signals'. So this can conflict with POSIX scripts.
> 
> Also, if zsh is invoked as sh or ksh, 'histchars' is available whereas 
> the 'HISTCHARS' equivalent is not. It seems quite obvious that this 
> should be the other way around.
> 
> The attached patch makes zsh, when invoked as sh or ksh, not initialise 
> 'signals', and initialise 'HISTCHARS' instead of 'histchars'. It also 
> updates the documentation.

That sounds fine to me --- as you know, general policy has always been
that emulation modes are there solely for compatibility with other
shells and backward compatibility is irrelevant, whereas native mode
is the other way round.

I'm guessing histchars got that way round in some kind of mistaken
link up with compatibility with csh, which tends to deal only
with lower case variables.  But that's just a guess, don't think
it really matters.

pws


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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-28 15:26   ` Peter Stephenson
@ 2020-01-28 15:45     ` Martijn Dekker
  0 siblings, 0 replies; 10+ messages in thread
From: Martijn Dekker @ 2020-01-28 15:45 UTC (permalink / raw)
  To: zsh-workers

Op 28-01-20 om 16:26 schreef Peter Stephenson:
[...]
> I'm guessing histchars got that way round in some kind of mistaken
> link up with compatibility with csh, which tends to deal only
> with lower case variables.  But that's just a guess, don't think
> it really matters.

OK. For what it's worth, I did verify my patch doesn't change init in 
csh mode. Both lowercase 'histchars' (as on tcsh) and the uppercase 
variant are initialised, as before.

Thanks,

- M.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-28 15:19 ` [PATCH] sh/ksh init: don't initialise lowercase parameters Martijn Dekker
  2020-01-28 15:26   ` Peter Stephenson
@ 2020-01-29  8:49   ` Daniel Shahaf
  2020-01-29 18:36     ` Bart Schaefer
  2020-02-01  9:42   ` Daniel Shahaf
  2 siblings, 1 reply; 10+ messages in thread
From: Daniel Shahaf @ 2020-01-29  8:49 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: Zsh hackers list

Martijn Dekker wrote on Tue, Jan 28, 2020 at 16:19:41 +0100:
> In POSIX sh and in ksh, it's the convention that lowercase variable names
> are reserved for scripts, and uppercase names may be used by the shell or
> system.

I wouldn't mind having a test for this.  How about:

diff --git a/Test/B07emulate.ztst b/Test/B07emulate.ztst
index 7b1592fa9..28a381aab 100644
--- a/Test/B07emulate.ztst
+++ b/Test/B07emulate.ztst
@@ -276,3 +276,7 @@ F:Some reserved tokens are handled in alias expansion
 0:--emulate followed by other options
 >yes
 >no
+
+ $ZTST_testdir/../Src/zsh --emulate sh -fc 'typeset -pm "[a-z]*"'
+ $ZTST_testdir/../Src/zsh --emulate ksh -fc 'typeset -pm "[a-z]*"'
+0:sh/ksh emulations don't define lowercase variables

> +++ b/Doc/Zsh/compat.yo
> @@ -1173,8 +1173,8 @@ tt(histchars) to characters with a locale-dependent meaning will be
>  vindex(HISTCHARS)
> -item(tt(HISTCHARS) <S> <Z>)(
> -Same as tt(histchars).  (Deprecated.)
> +item(tt(HISTCHARS) <S>)(
> +Same as tt(histchars).
>  )

Why de-deprecate the uppercase spelling?  Do ksh or POSIX sh define "HISTCHARS"
in uppercase?  The lowercase spelling does seem to be a csh/tcsh thing.

Cheers,

Daniel

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-29  8:49   ` Daniel Shahaf
@ 2020-01-29 18:36     ` Bart Schaefer
  2020-01-29 21:35       ` Daniel Shahaf
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2020-01-29 18:36 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Martijn Dekker, Zsh hackers list

On Wed, Jan 29, 2020 at 2:50 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Why de-deprecate the uppercase spelling?  Do ksh or POSIX sh define "HISTCHARS"
> in uppercase?  The lowercase spelling does seem to be a csh/tcsh thing.

I would agree with removing "Deprecated" from the doc for HISTCHARS.
It's pretty clear at this point that we're not actually going to
remove it, and there needs to be one form of the variable even in
non-zsh modes for the feature to work, and we're not allowed to claim
the lower-case one.

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-29 18:36     ` Bart Schaefer
@ 2020-01-29 21:35       ` Daniel Shahaf
  2020-01-29 22:00         ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Shahaf @ 2020-01-29 21:35 UTC (permalink / raw)
  To: zsh-workers; +Cc: Martijn Dekker

Bart Schaefer wrote on Wed, 29 Jan 2020 12:36 -0600:
> On Wed, Jan 29, 2020 at 2:50 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >
> > Why de-deprecate the uppercase spelling?  Do ksh or POSIX sh define "HISTCHARS"
> > in uppercase?  The lowercase spelling does seem to be a csh/tcsh thing.
> 
> I would agree with removing "Deprecated" from the doc for HISTCHARS.
> It's pretty clear at this point that we're not actually going to
> remove it, and there needs to be one form of the variable even in
> non-zsh modes for the feature to work, and we're not allowed to claim
> the lower-case one.

I see.  Yes, we can bless $HISTCHARS as the preferred spelling for
native mode and keep $histchars for csh compatibility…but doesn't this
imply that we should add a $SIGNALS variable (and possibly deprecate
$signals)?

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-29 21:35       ` Daniel Shahaf
@ 2020-01-29 22:00         ` Bart Schaefer
  2020-01-31  4:17           ` Daniel Shahaf
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2020-01-29 22:00 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh hackers list, Martijn Dekker

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

On Wed, Jan 29, 2020, 3:36 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:

>
> I see.  Yes, we can bless $HISTCHARS as the preferred spelling for
> native mode and keep $histchars for csh compatibility…but doesn't this
> imply that we should add a $SIGNALS variable (and possibly deprecate
> $signals)?
>

No, I was not suggesting any change to native mode.  I'm merely saying that
if we can't have the lower-case version in sh/ksh modes, we need the upper
case one there.  $signals is strictly informational, so it doesn't need to
be present in those modes at all, but HISTCHARS is writable and controls
features of history.

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-29 22:00         ` Bart Schaefer
@ 2020-01-31  4:17           ` Daniel Shahaf
  2020-01-31  4:31             ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Shahaf @ 2020-01-31  4:17 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Wed, 29 Jan 2020 16:00 -0600:
> On Wed, Jan 29, 2020, 3:36 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> >
> > I see.  Yes, we can bless $HISTCHARS as the preferred spelling for
> > native mode and keep $histchars for csh compatibility…but doesn't this
> > imply that we should add a $SIGNALS variable (and possibly deprecate
> > $signals)?
> >  
> 
> No, I was not suggesting any change to native mode.  I'm merely saying that
> if we can't have the lower-case version in sh/ksh modes, we need the upper
> case one there.  $signals is strictly informational, so it doesn't need to
> be present in those modes at all, but HISTCHARS is writable and controls
> features of history.

Why does HISTCHARS need to be available in sh/ksh modes?

About $signals, it's too late to change zsh mode special parameters to
uppercase (e.g., $path).  Perhaps we should use uppercase for any new
parameters we introduce going forward, but that's another conversation.

Cheers,

Daniel

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-31  4:17           ` Daniel Shahaf
@ 2020-01-31  4:31             ` Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 2020-01-31  4:31 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh hackers list

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

On Thu, Jan 30, 2020, 10:18 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:

>
> Why does HISTCHARS need to be available in sh/ksh modes?
>

Because it's possible to start in sh/ksh mode and then setopt banghist.

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

* Re: [PATCH] sh/ksh init: don't initialise lowercase parameters
  2020-01-28 15:19 ` [PATCH] sh/ksh init: don't initialise lowercase parameters Martijn Dekker
  2020-01-28 15:26   ` Peter Stephenson
  2020-01-29  8:49   ` Daniel Shahaf
@ 2020-02-01  9:42   ` Daniel Shahaf
  2 siblings, 0 replies; 10+ messages in thread
From: Daniel Shahaf @ 2020-02-01  9:42 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: Zsh hackers list

I was going to apply the patch but I have two questions:

Martijn Dekker wrote on Tue, 28 Jan 2020 16:19 +0100:
> +++ b/Doc/Zsh/params.yo
> @@ -1173,8 +1173,8 @@ tt(histchars) to characters with a locale-dependent meaning will be
>  rejected with an error message.
>  )
>  vindex(HISTCHARS)
> -item(tt(HISTCHARS) <S> <Z>)(
> -Same as tt(histchars).  (Deprecated.)
> +item(tt(HISTCHARS) <S>)(
> +Same as tt(histchars).

Suggest to add ", but available in emulation modes too", otherwise
people will wonder whether the <Z> was omitted here by mistake.  I can
do that before applying the patch.

I intend to apply it to 5.9 unless there'll be another 5.8 test release
first.

> +++ b/Src/params.c
> @@ -309,7 +309,7 @@ IPDEF1("TTYIDLE", ttyidle_gsu, PM_READONLY_SPECIAL),
>  #define IPDEF2(A,B,C) {{NULL,A,PM_SCALAR|PM_SPECIAL|C},BR(NULL),GSU(B),0,0,NULL,NULL,NULL,0}
>  IPDEF2("USERNAME", username_gsu, PM_DONTIMPORT|PM_RESTRICTED),
>  IPDEF2("-", dash_gsu, PM_READONLY_SPECIAL),
> -IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
> +IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
>  IPDEF2("HOME", home_gsu, PM_UNSET),
>  IPDEF2("TERM", term_gsu, PM_UNSET),
>  IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET),
> @@ -413,7 +413,7 @@ IPDEF8("MODULE_PATH", &module_path, "module_path", PM_DONTIMPORT|PM_RESTRICTED|P
>  
>  /* All of these have sh compatible equivalents.                */
>  IPDEF1("ARGC", argc_gsu, PM_READONLY_SPECIAL),
> -IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
> +IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
>  IPDEF4("status", &lastval),
>  IPDEF7("prompt", &prompt),
>  IPDEF7("PROMPT", &prompt),

What's the purpose of these two hunks?  They don't seem to have any build-time nor run-time effect?

Sorry for not spotting these two points earlier.

Daniel

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

end of thread, other threads:[~2020-02-01  9:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200128152042eucas1p20cbbeeb7cbe5f6abff08128ba8792661@eucas1p2.samsung.com>
2020-01-28 15:19 ` [PATCH] sh/ksh init: don't initialise lowercase parameters Martijn Dekker
2020-01-28 15:26   ` Peter Stephenson
2020-01-28 15:45     ` Martijn Dekker
2020-01-29  8:49   ` Daniel Shahaf
2020-01-29 18:36     ` Bart Schaefer
2020-01-29 21:35       ` Daniel Shahaf
2020-01-29 22:00         ` Bart Schaefer
2020-01-31  4:17           ` Daniel Shahaf
2020-01-31  4:31             ` Bart Schaefer
2020-02-01  9:42   ` Daniel Shahaf

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