zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Re: ksharrays and assoc array assignments
Date: Sat, 28 Aug 1999 22:14:06 +0000	[thread overview]
Message-ID: <990828221406.ZM32663@candle.brasslantern.com> (raw)
In-Reply-To: <990828050003.ZM30545@candle.brasslantern.com>

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


           reply	other threads:[~1999-08-28 22:14 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <990828050003.ZM30545@candle.brasslantern.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=990828221406.ZM32663@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).