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

PATCH: Re: exporting -variables [was Re: PATCH: 3.1.6-dev-20: _dpkg thinko]



Clint Adams wrote:

> > Allegedly this is causing "-i=irs" to be exported, though I can't
> > reproduce it.
> 
> I can.  If ALL_EXPORT is on, variables beginning with
> hyphens will be exported during _arguments.  Is this a problem?
> bash seems to think such things are invalid.
> 
> e.g.:
> sh: invalid character 45 in exportstr for -f

Aha. The problem behind the scenes, was, obviously, this:

  % setopt allexport
  % typeset -A foo
  % foo[bar]=baz
  % env|grep bar
  bar=baz

The sub-parameters used in assocs get exported...


The patch adds the PM_HASHELEM flag to be able to detect such param
structs and then keeps them from being exported.

Bye
 Sven

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.2
diff -u -r1.2 builtin.c
--- Src/builtin.c	2000/04/01 20:49:47	1.2
+++ Src/builtin.c	2000/04/04 11:58:42
@@ -1630,7 +1630,8 @@
 		if (!(pm->flags & PM_UNSET) && !pm->env && !value)
 		    pm->env = addenv(pname, getsparam(pname), pm->flags);
 	    } else if (pm->env &&
-		       (!pm->level || (isset(ALLEXPORT) && !pm->old))) {
+		       (!pm->level || (isset(ALLEXPORT) && !pm->old &&
+				       !(pm->flags & PM_HASHELEM)))) {
 		delenv(pm->env);
 		zsfree(pm->env);
 		pm->env = NULL;
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.2
diff -u -r1.2 params.c
--- Src/params.c	2000/04/01 20:49:48	1.2
+++ Src/params.c	2000/04/04 11:58:43
@@ -617,6 +617,9 @@
 {
     Param pm, oldpm;
 
+    if (paramtab != realparamtab)
+	flags = (flags & ~PM_EXPORTED) | PM_HASHELEM;
+
     if (name != nulstring) {
 	oldpm = (Param) (paramtab == realparamtab ?
 			 gethashnode2(paramtab, name) :
@@ -646,7 +649,7 @@
 	    paramtab->addnode(paramtab, ztrdup(name), pm);
 	}
 
-	if (isset(ALLEXPORT) && !oldpm)
+	if (isset(ALLEXPORT) && !oldpm && !(flags & PM_HASHELEM))
 	    flags |= PM_EXPORTED;
     } else {
 	pm = (Param) zhalloc(sizeof *pm);
@@ -1520,7 +1523,7 @@
 	break;
     }
     if ((!v->pm->env && !(v->pm->flags & PM_EXPORTED) &&
-	 !(isset(ALLEXPORT) && !v->pm->old)) ||
+	 !(isset(ALLEXPORT) && !v->pm->old && !(v->pm->flags & PM_HASHELEM))) ||
 	(v->pm->flags & PM_ARRAY) || v->pm->ename)
 	return;
     if (PM_TYPE(v->pm->flags) == PM_INTEGER)
@@ -2742,7 +2745,7 @@
      */
     if (t == path)
 	cmdnamtab->emptytable(cmdnamtab);
-    if (isset(ALLEXPORT) ? !!pm->old : pm->level)
+    if ((pm->flags & PM_HASHELEM) || (isset(ALLEXPORT) ? !!pm->old : pm->level))
 	return;
     u = t ? zjoin(t, ':', 1) : "";
     len_s = strlen(s);
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.2
diff -u -r1.2 zsh.h
--- Src/zsh.h	2000/04/01 20:49:48	1.2
+++ Src/zsh.h	2000/04/04 11:58:43
@@ -1125,6 +1125,7 @@
 #define PM_REMOVABLE	(1<<21)	/* special can be removed from paramtab     */
 #define PM_AUTOLOAD	(1<<22) /* autoloaded from module                   */
 #define PM_NORESTORE	(1<<23)	/* do not restore value of local special    */
+#define PM_HASHELEM     (1<<24) /* is a hash-element */
 
 /* The option string corresponds to the first of the variables above */
 #define TYPESET_OPTSTR "aiEFALRZlurtxUhT"

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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