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

PATCH: 3.1.5-pws-N: unset fix



This fixes the parameter bugs I reported yesterday:  first, typeset -m
restored unset parameters; second, global parameters didn't get removed
from the parameter table by an unset inside a function (without a typeset,
they will be restored as globals anyway, so this was definitely a bug).

The first hunk of this is relevant to 3.0.6, although the if (pm->flags &
PM_UNSET) test needs adding by hand.  The second bug does not exist as such
in 3.0.6 --- though I noticed that if a parameter that was local in one
function is unset in a function called from that, it will be restored next
time in global scope, in other words this:

% fn2() { unset foo; }          
% fn1() { typeset foo=bar; fn2; foo=notbar; }
% fn1
% print $foo
notbar

which may not be intended, and does not happen in 3.1.5++ (foo is restored
at the level of fn1).  It compares with

% fn1() { typeset foo=bar; unset foo; foo=notbar; }
% fn1
% print ${+foo}
0

so it may be a bug.  Should I send a patch for both for 3.0.6?

--- Src/builtin.c.unset	Mon May  3 13:13:57 1999
+++ Src/builtin.c	Fri May  7 15:16:54 1999
@@ -1768,7 +1768,8 @@
 	    for (i = 0; i < paramtab->hsize; i++) {
 		for (pm = (Param) paramtab->nodes[i]; pm;
 		     pm = (Param) pm->next) {
-		    if ((pm->flags & PM_RESTRICTED) && isset(RESTRICTED))
+		    if (((pm->flags & PM_RESTRICTED) && isset(RESTRICTED)) ||
+			(pm->flags & PM_UNSET))
 			continue;
 		    if (domatch(pm->nam, com, 0))
 			addlinknode(pmlist, pm);
--- Src/params.c.unset	Wed May  5 09:34:37 1999
+++ Src/params.c	Fri May  7 15:20:08 1999
@@ -1755,7 +1755,7 @@
      * Some specials, such as those used in zle, still need removing
      * from the parameter table; they have the PM_REMOVABLE flag.
      */
-    if ((locallevel && locallevel >= pm->level) ||
+    if ((pm->level && locallevel >= pm->level) ||
 	(pm->flags & (PM_SPECIAL|PM_REMOVABLE)) == PM_SPECIAL)
 	return;
 

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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