zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: SHLVL not updated in environment
@ 2004-09-20 13:09 Peter Stephenson
  2004-09-20 14:19 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2004-09-20 13:09 UTC (permalink / raw)
  To: Zsh hackers list

% zsh
% print $SHLVL
3
% printenv SHLVL
2

This is a bug, right?  I'm not missing some extreme sublety?
Is this the right fix, rather than reversing the sense of the test?
It seems that SHLVL has to be exported for it to work, although the
documentation doesn't explicitly indicate it always will be exported.

((SHLVL++, SHLVL--)) is a workaround.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.89
diff -u -r1.89 params.c
--- Src/params.c	17 Sep 2004 09:25:42 -0000	1.89
+++ Src/params.c	20 Sep 2004 13:05:20 -0000
@@ -594,8 +594,8 @@
 	addenv(pm, pm->u.str);
     pm = (Param) paramtab->getnode(paramtab, "SHLVL");
     sprintf(buf, "%d", (int)++shlvl);
-    if (!(pm->flags & PM_EXPORTED))
-	addenv(pm, buf);
+    /* shlvl value in environment needs updating unconditionally */
+    addenv(pm, buf);
 
     /* Add the standard non-special parameters */
     set_pwd_env();

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: PATCH: SHLVL not updated in environment
  2004-09-20 13:09 PATCH: SHLVL not updated in environment Peter Stephenson
@ 2004-09-20 14:19 ` Bart Schaefer
  2004-09-20 14:30   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2004-09-20 14:19 UTC (permalink / raw)
  To: Zsh hackers list

On Mon, 20 Sep 2004, Peter Stephenson wrote:

> % zsh
> % print $SHLVL
> 3
> % printenv SHLVL
> 2
> 
> This is a bug, right?  I'm not missing some extreme sublety?

That seems to be the way it worked before 4.2.1.

> It seems that SHLVL has to be exported for it to work, although the
> documentation doesn't explicitly indicate it always will be exported.

It *is* always exported, though:

schaefer[520] zsh -f
toltec% typeset -p SHLVL
typeset -i10 -x SHLVL=2

> Is this the right fix, rather than reversing the sense of the test?

I think it's right, but it begs the question:  What changed from 4.2.0
to make this fix necessary?


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

* Re: PATCH: SHLVL not updated in environment
  2004-09-20 14:19 ` Bart Schaefer
@ 2004-09-20 14:30   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2004-09-20 14:30 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> I think it's right, but it begs the question:  What changed from 4.2.0
> to make this fix necessary?

The code changed from "right" to "wrong".  It used to look like this.

    pm = (Param) paramtab->getnode(paramtab, "SHLVL");
    if (!(pm->flags & PM_EXPORTED))
        pm->flags |= PM_EXPORTED;
    sprintf(buf, "%d", (int)++shlvl);
    pm->env = addenv("SHLVL", buf, pm->flags);

I rationalised addenv and in my zeal I probably didn't notice that the
shlvl code wanted rationalising in a slightly different way from the
others.  The PM_EXPORTED flag is now handled within addenv().  So it
looks like the patch is correct.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

end of thread, other threads:[~2004-09-20 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-20 13:09 PATCH: SHLVL not updated in environment Peter Stephenson
2004-09-20 14:19 ` Bart Schaefer
2004-09-20 14:30   ` Peter Stephenson

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