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

PATCH: Re: ksharrays and assoc array assignments



On Aug 28,  5:00am, Bart Schaefer wrote:
} Subject: PATCH: ksharrays and assoc array assignments (was Re: Files modif
}
} +	int k = opts[KSHARRAYS];	/* Remember the value of KSHARRAYS */
} +	opts[KSHARRAYS] = 0;		/* and clear it to avoid special-  */
} +	v = getvalue(&t, 1);		/* case of $array --> ${array[0]}. */
} +	opts[KSHARRAYS] = k;		/* OK because we can't assign to a */
} +	if (!v)				/* slice of an association anyway, */
} +	    return NULL;		/* so ANY subscript will be wrong. */

Turns out there are other problems with ksharrays and ${(AA)...}.  Even
after the patch quoted above, ${(AA)var:=value} complains about slices
when var is already set; which means it's acting like ${(AA)var::=value},
attempting to assign when it should not.  This is yet another side-effect
of the $array --> ${array[0]} mapping when KSHARRAYS is set.

So, scrap the patch above and apply the following one instead (that is,
on the original 3.1.6-pws-1 source, not on top of zsh-users/2529).

One hunk below is to fix a typo in my patch from zsh-workers/7521.  If you
didn't apply 7521 or Sven's patches that preceded it, remove the exec.c hunk
before applying the following.

Index: Src/exec.c
===================================================================
@@ -622,7 +622,7 @@
     else if (!cn->u.name)
 	return 0;
     else {
-	strcpy(fullnam, cn->u.name);
+	strcpy(fullnam, *(cn->u.name));
 	strcat(fullnam, "/");
 	strcat(fullnam, cn->nam);
     }
Index: Src/params.c
===================================================================
@@ -1217,7 +1217,8 @@
 		*pptr = s;
 		return v;
 	    }
-	} else if (v->isarr && iident(*t) && isset(KSHARRAYS))
+	} else if (!(flags & SCANPM_ASSIGNING) && v->isarr &&
+		   iident(*t) && isset(KSHARRAYS))
 	    v->b = 0, v->isarr = 0;
     }
     if (!bracks && *s)
@@ -1649,7 +1650,7 @@
 	}
 	v = NULL;
     } else {
-	if (!(v = getvalue(&s, 1)))
+	if (!(v = fetchvalue(&s, 1, SCANPM_ASSIGNING)))
 	    createparam(t, PM_ARRAY);
 	else if (!(PM_TYPE(v->pm->flags) & (PM_ARRAY|PM_HASHED)) &&
 		 !(v->pm->flags & (PM_SPECIAL|PM_TIED))) {
@@ -1660,11 +1661,8 @@
 	}
     }
     if (!v)
-	if (!(v = getvalue(&t, 1)))
+	if (!(v = fetchvalue(&t, 1, SCANPM_ASSIGNING)))
 	    return NULL;
-    if (isset(KSHARRAYS) && !ss)
-	/* the whole array should be set instead of only the first element */
-	v->b = -1;
     setarrvalue(v, val);
     return v->pm;
 }
@@ -1688,7 +1686,7 @@
 	errflag = 1;
 	return NULL;
     } else {
-	if (!(v = getvalue(&s, 1)))
+	if (!(v = fetchvalue(&s, 1, SCANPM_ASSIGNING)))
 	    createparam(t, PM_HASHED);
 	else if (!(PM_TYPE(v->pm->flags) & PM_HASHED) &&
 		 !(v->pm->flags & PM_SPECIAL)) {
@@ -1698,7 +1696,7 @@
 	}
     }
     if (!v)
-	if (!(v = getvalue(&t, 1)))
+	if (!(v = fetchvalue(&t, 1, SCANPM_ASSIGNING)))
 	    return NULL;
     setarrvalue(v, val);
     return v->pm;
Index: Src/subst.c
===================================================================
@@ -1028,7 +1028,7 @@
 
 	if (!(v = fetchvalue((subexp ? &ov : &s), (wantt ? -1 :
 				  ((unset(KSHARRAYS) || inbrace) ? 1 : -1)),
-			     hkeys|hvals)) ||
+			     hkeys|hvals|(arrasg ? SCANPM_ASSIGNING : 0))) ||
 	    (v->pm && (v->pm->flags & PM_UNSET)))
 	    vunset = 1;
 
Index: Src/zsh.h
===================================================================
@@ -1045,6 +1045,7 @@
 #define SCANPM_MATCHKEY   (1<<3)
 #define SCANPM_MATCHVAL   (1<<4)
 #define SCANPM_MATCHMANY  (1<<5)
+#define SCANPM_ASSIGNING  (1<<6)
 #define SCANPM_ISVAR_AT   ((-1)<<15)	/* Only sign bit is significant */
 
 /*


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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