From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28732 invoked by alias); 3 Sep 2010 09:52:40 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15366 Received: (qmail 5458 invoked from network); 3 Sep 2010 09:52:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at seiken.de designates 62.75.149.128 as permitted sender) From: Joke de Buhr To: zsh-users@zsh.org Subject: Re: exporting environment variables to shell functions (maybe bug) Date: Fri, 3 Sep 2010 11:52:22 +0200 User-Agent: KMail/1.13.2 (Linux/2.6.35-19-generic; KDE/4.4.2; x86_64; ; ) References: <201009031034.47905.joke@seiken.de> <20100903095444.1a902d09@pwslap01u.europe.root.pri> In-Reply-To: <20100903095444.1a902d09@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2036735.0ZRs6SIDaD"; protocol="application/pgp-signature"; micalg=pgp-ripemd160 Content-Transfer-Encoding: 7bit Message-Id: <201009031152.24682.joke@seiken.de> --nextPart2036735.0ZRs6SIDaD Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Friday 03 September 2010 10:54:44 Peter Stephenson wrote: > On Fri, 3 Sep 2010 10:34:30 +0200 >=20 > Joke de Buhr wrote: > > I've ask this question a couple of days before but I didn't get any > > response [1]. I think this may be a bug. >=20 > It's a bug, so I sent a fix to zsh-workers, not realising you weren't > on that list... zsh-workers/28220 It's only important it will be fixed. This bug caused some trouble in one o= f=20 my scripts and it took some time to realize the identical variable name was= to=20 blame.=20 =20 > pws >=20 >=20 > On Tue, 31 Aug 2010 17:54:25 +0200 >=20 > Joke de Buhr wrote: > > ## 4: HELLO not exported to shell function, different from 2 and 3 > > $ call() { env | grep '^HELLO' } > > $ HELLO=3Dworld > > $ HELLO=3D$HELLO call > >=20 > > HELLO=3D ## <-- empty >=20 > (Moved to zsh-workers immediately, this time.) >=20 > That's a bug. When HELLO needs to be restored explicitly because the > code where it's set to something else is running in the main shell, we > remove the parameter from the table to be restored later. The > assignment than can't see the value it's temporarily modifying. You > don't need to search the environment for this; zsh consistently screws > up the parameter within the shell, too. >=20 > I think we can just copy the parameter instead of removing it, so long > as we copy it properly. >=20 > valgrind says this doesn't cause any leaks. >=20 > Index: Src/exec.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/zsh/zsh/Src/exec.c,v > retrieving revision 1.182 > diff -p -u -r1.182 exec.c > --- Src/exec.c 22 Aug 2010 20:08:57 -0000 1.182 > +++ Src/exec.c 31 Aug 2010 19:11:41 -0000 > @@ -3313,13 +3313,17 @@ save_params(Estate state, Wordcode pc, L > while (wc_code(ac =3D *pc) =3D=3D WC_ASSIGN) { > s =3D ecrawstr(state->prog, pc + 1, NULL); > if ((pm =3D (Param) paramtab->getnode(paramtab, s))) { > + Param tpm; > if (pm->env) > delenv(pm); > if (!(pm->node.flags & PM_SPECIAL)) { > - paramtab->removenode(paramtab, s); > + tpm =3D (Param) zshcalloc(sizeof *tpm); > + tpm->node.nam =3D ztrdup(pm->node.nam); > + copyparam(tpm, pm, 0); > + pm =3D tpm; > } else if (!(pm->node.flags & PM_READONLY) && > (unset(RESTRICTED) || !(pm->node.flags & PM_RESTRICTED))) { > - Param tpm =3D (Param) hcalloc(sizeof *tpm); > + tpm =3D (Param) hcalloc(sizeof *tpm); > tpm->node.nam =3D pm->node.nam; > copyparam(tpm, pm, 1); > pm =3D tpm; > @@ -3383,8 +3387,9 @@ restore_params(LinkList restorelist, Lin > break; > } > pm =3D tpm; > - } else > + } else { > paramtab->addnode(paramtab, pm->node.nam, pm); > + } > if ((pm->node.flags & PM_EXPORTED) && ((s =3D > getsparam(pm->node.nam)))) addenv(pm, s); > } > Index: Src/params.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/zsh/zsh/Src/params.c,v > retrieving revision 1.161 > diff -p -u -r1.161 params.c > --- Src/params.c 3 Jun 2010 13:38:17 -0000 1.161 > +++ Src/params.c 31 Aug 2010 19:11:41 -0000 > @@ -927,11 +927,17 @@ createspecialhash(char *name, GetNodeFun > } >=20 >=20 > -/* Copy a parameter */ > +/* > + * Copy a parameter > + * > + * If fakecopy is set, we are just saving the details of a special > + * parameter. Otherwise, the result will be used as a real parameter > + * and we need to do more work. > + */ >=20 > /**/ > void > -copyparam(Param tpm, Param pm, int toplevel) > +copyparam(Param tpm, Param pm, int fakecopy) > { > /* > * Note that tpm, into which we're copying, may not be in permanent > @@ -942,7 +948,8 @@ copyparam(Param tpm, Param pm, int tople > tpm->node.flags =3D pm->node.flags; > tpm->base =3D pm->base; > tpm->width =3D pm->width; > - if (!toplevel) > + tpm->level =3D pm->level; > + if (!fakecopy) > tpm->node.flags &=3D ~PM_SPECIAL; > switch (PM_TYPE(pm->node.flags)) { > case PM_SCALAR: > @@ -963,13 +970,15 @@ copyparam(Param tpm, Param pm, int tople > break; > } > /* > - * If called from inside an associative array, that array is later > going - * to be passed as a real parameter, so we need the gets and > sets - * functions to be useful. However, the saved associated array > is - * not itself special, so we just use the standard ones. > - * This is also why we switch off PM_SPECIAL. > + * If the value is going to be passed as a real parameter (e.g. this > is + * called from inside an associative array), we need the gets and > sets + * functions to be useful. > + * > + * In this case we assume the the saved parameter is not itself > special, + * so we just use the standard functions. This is also why > we switch off + * PM_SPECIAL. > */ > - if (!toplevel) > + if (!fakecopy) > assigngetset(tpm); > } >=20 > Index: Test/A06assign.ztst > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/zsh/zsh/Test/A06assign.ztst,v > retrieving revision 1.5 > diff -p -u -r1.5 A06assign.ztst > --- Test/A06assign.ztst 23 Sep 2006 06:55:29 -0000 1.5 > +++ Test/A06assign.ztst 31 Aug 2010 19:11:41 -0000 > @@ -277,3 +277,18 @@ >=20 >=20 >=20 > + > + call() { print $HELLO; } > + export HELLO=3Dworld > + call > + HELLO=3Duniverse call > + call > + HELLO=3D${HELLO}liness call > + call > + unset HELLO > +0:save and restore when using original value in temporary > +>world > +>universe > +>world > +>worldliness > +>world >=20 >=20 >=20 >=20 > Member of the CSR plc group of companies. CSR plc registered in England a= nd > Wales, registered number 4187346, registered office Churchill House, > Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom --nextPart2036735.0ZRs6SIDaD Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQG7BAABAwAlBQJMgMVWHhhoa3A6Ly9wb29sLnNrcy1rZXlzZXJ2ZXJzLm5ldAAK CRCWUloJhwFWxvWwC/98KdSyCPIqQ2K+hdgovWlBsdVemy/NtMI7N1MHO89eRfPU MUyeCBOwqP+qrL6syr9iN9DSU40dSfxKh87F/REbUoOioy6Lwxcxe1gk+fdV+AF5 YW32TgKvIkh9zwyE6BnR+n1N1AOQlezdtDOPZEgVD09LfmqVlY4qnY4GfIHHjyel wvX55HAfpr1I9nMS+zvUKG2Fx7lBLmGwBUu9ahGweY9GCKGwHxnK/6PiwC8sGpqT XLLKcjob+B+JWSOUg2DunmkMUoZPb7wV0vrhKJ+GS3lgdqsSVZL8Jb0RkJ7BD0NH f774wR+EBgxWXjFsZ6B12QBGX0uo1M2kIOBX/y82CkdEkKQSVqJUhA8UmFcPmn00 qh1d+eU04aYdSmcZezh00cOUoeW08Y4tVHnilT7oiGKrvTuG3RZtGkigEELXSI0v hABT9dQK9sSR3mwBOh5jlbJiY3iOh1XwMMNe58vKcLptWkQdqvm7pNkL7hdFTMkX HXAT5zDXytUYsIQw5hQ= =XVtp -----END PGP SIGNATURE----- --nextPart2036735.0ZRs6SIDaD--