Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: LC_ALL=C foo, where foo is a shell function



On Sun, Jul 10, 2005 at 12:57:47AM +0000, Bart Schaefer wrote:
> I just noticed that, even in the latest build, if LC_ALL starts out set
> (even to nothing), but not exported, then when "LC_ALL=C foo" is run
> LC_ALL becomes and remains exported, even though its value gets reset
> to the previous state.

There are two completely separate parts of the shell that restore
parameters.  There is one I wrote for function scope, and there is a second
one that someone else wrote without taking any notice of the first one that
restores parameters in this case.  (Good job I never get bitter, eh?)  This
second one doesn't take account of restoring a special parameter when the
local value is exported and the old value isn't.  For specials there is
always an entry in the table, so this applies even if LC_ALL isn't actually
set.

It should just be a case of removing stuff from the environment if we know
it shouldn't be there.  I can't see any cases when this would be wrong,
anyway.  (There are POSIX exceptions, which I don't think cover LC_ALL
anyway, where the value is preserved after the function call, but none that
would force an export to be inconsistent with the local value.)

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.128
diff -u -r1.128 exec.c
--- Src/exec.c	9 Dec 2007 23:53:33 -0000	1.128
+++ Src/exec.c	21 Feb 2008 18:14:41 -0000
@@ -3113,6 +3113,8 @@
 		DPUTS(!tpm || PM_TYPE(pm->node.flags) != PM_TYPE(tpm->node.flags) ||
 		      !(pm->node.flags & PM_SPECIAL),
 		      "BUG: in restoring special parameters");
+		if (!pm->env && tpm->env)
+		    delenv(tpm);
 		tpm->node.flags = pm->node.flags;
 		switch (PM_TYPE(pm->node.flags)) {
 		case PM_SCALAR:


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author