zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: Re: PATCH: local exports
Date: Thu, 13 Apr 2000 18:54:19 +0100	[thread overview]
Message-ID: <0FSY00HFQV2JPE@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Thu, 13 Apr 2000 15:42:36 -0000." <1000413154237.ZM16996@candle.brasslantern.com>

Bart Schaefer wrote:
> The following seems to be a pretty effective test:
> 
>   unenv() {
>     local x
>     x=($(typeset +x))
>     local $x
>     unset $x
>     /usr/bin/printenv	# $path is (correctly?) nuked by unset PATH
>   }
> 
> The output on my system differs if I run this function twice.  The first
> time it is:
> 
>   TERM=xterm
>   HOME=/home/schaefer
>   _=/usr/bin/printenv
>   COLUMNS=80
>   LINES=24

Oddly, this wasn't actually my fault; it came from the import of special
parameters at startup.  The code set the variable, then tried to replace
the value in the environment with the value generated internlly, for
consistency.  Unfortunately it was trying to replace it into the old
environment, which failed.  This returned null, which was set to the env
element of the parameter struct.  Hence when the new code looked for this
to see if the value was in the environment already it failed, so never
deleted it.  (It was doing this on the `local', not the unset, since the
local parameter wasn't being exported.)  This usually didn't show up
because the values in the environment were OK anyway, as in this case, so
the fact that they didn't get replaced didn't matter.

> } This was necessary to get around the -g-with--x kludge.  Ksh 88 doesn't
> } have that and its `typeset -x' behaves more or less like `typeset +g -x'.
> 
> This is why I keep talking about ksh emulation.  I want to be able to
> keep exporting things from functions with `typeset -x' the way I have
> for the entire time I've been using zsh, but it causes problems when
> running scripts written for ksh.

OK, so it's a ksh compatibility vs. old zsh compatibility issue.  The
problem with using an option is that in this case the latter is the kludge,
but needs to be enabled by default.  There isn't a good way round that.
If somebody wants to write an option they can.  It could be called e.g.
GLOBAL_EXPORT and be on by default; at least that tells you that something's
up.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.4
diff -u -r1.4 params.c
--- Src/params.c	2000/04/13 14:22:47	1.4
+++ Src/params.c	2000/04/13 17:51:26
@@ -454,6 +454,7 @@
 {
     Param ip, pm;
     char **new_environ, **envp, **envp2, **sigptr, **t;
+    char **old_environ = environ;
     char buf[50], *str, *iname;
     int num_env, oae = opts[ALLEXPORT];
 #ifdef HAVE_UNAME
@@ -516,9 +517,12 @@
 		    pm->flags |= PM_EXPORTED;
 		    pm->env = *envp++ = ztrdup(*envp2);
 		    *envp = NULL;
-		    if (pm->flags & PM_SPECIAL)
+		    if (pm->flags & PM_SPECIAL) {
+			environ = new_environ;
 			pm->env = replenv(pm->env, getsparam(pm->nam),
 					  pm->flags);
+			environ = old_environ;
+		    }
 		}
 	    }
 	    *str = '=';

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


  reply	other threads:[~2000-04-13 17:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-12  6:14 List of unresolved issues Bart Schaefer
2000-04-12 15:56 ` Andrej Borsenkow
2000-04-12 20:55 ` Peter Stephenson
2000-04-13  0:26   ` Bart Schaefer
2000-04-13  8:56     ` Peter Stephenson
2000-04-13 14:10       ` PATCH: local exports Peter Stephenson
2000-04-13 15:42         ` Bart Schaefer
2000-04-13 17:54           ` Peter Stephenson [this message]
2000-05-01  5:21 ` List of unresolved issues (update) Bart Schaefer
2000-05-01  9:09   ` Adam Spiers
2000-05-02  9:50   ` Peter Stephenson
2000-04-14  7:51 PATCH: Re: PATCH: local exports Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FSY00HFQV2JPE@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).