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

Re: Unsetting a variable that was not previously set



Oliver Kiddle wrote:
> Also, at the moment, it seems
> that for an readonly variable, it is returning 0 which is clearly
> wrong.

Hmm, the code is full of calls to unsetparam_pm() and they are all
(except now this one) being roundly ignored.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.99
diff -u -r1.99 builtin.c
--- Src/builtin.c	28 Mar 2003 20:21:00 -0000	1.99
+++ Src/builtin.c	4 Apr 2003 16:41:41 -0000
@@ -2580,8 +2580,10 @@
 		zerrnam(name, "%s: invalid element for unset", s, 0);
 		returnval = 1;
 	    }
-	} else
-	    unsetparam_pm(pm, 0, 1);
+	} else {
+	    if (unsetparam_pm(pm, 0, 1))
+		returnval = 1;
+	}
 	if (ss)
 	    *ss = '[';
     }
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.70
diff -u -r1.70 params.c
--- Src/params.c	11 Mar 2003 17:29:58 -0000	1.70
+++ Src/params.c	4 Apr 2003 16:41:41 -0000
@@ -2214,18 +2214,18 @@
 /* Unset a parameter */
 
 /**/
-mod_export void
+mod_export int
 unsetparam_pm(Param pm, int altflag, int exp)
 {
     Param oldpm, altpm;
 
     if ((pm->flags & PM_READONLY) && pm->level <= locallevel) {
 	zerr("read-only variable: %s", pm->nam, 0);
-	return;
+	return 1;
     }
     if ((pm->flags & PM_RESTRICTED) && isset(RESTRICTED)) {
 	zerr("%s: restricted", pm->nam, 0);
-	return;
+	return 1;
     }
     pm->unsetfn(pm, exp);
     if ((pm->flags & PM_EXPORTED) && pm->env) {
@@ -2267,7 +2267,7 @@
      */
     if ((pm->level && locallevel >= pm->level) ||
 	(pm->flags & (PM_SPECIAL|PM_REMOVABLE)) == PM_SPECIAL)
-	return;
+	return 0;
 
     /* remove parameter node from table */
     paramtab->removenode(paramtab, pm->nam);
@@ -2292,6 +2292,8 @@
     }
 
     paramtab->freenode((HashNode) pm); /* free parameter node */
+
+    return 0;
 }
 
 /* Standard function to unset a parameter.  This is mostly delegated to *

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


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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