Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Fix appending empty array to associations
- X-seq: zsh-workers 36347
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Fix appending empty array to associations
- Date: Mon, 31 Aug 2015 15:19:17 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=T3znBlRrdVRRFUbeG1MSA9Jxd14aPXe/ad0MCD90T2w=; b=GQjBStQ0hqBylvr/w9JIReH5HNc2hSON+qRLw1M0ZirV7ffrYqM2NcVDgdIw4510sE lEZsZycAtSOplNCwxHJAw9ziqNpNrROd4TADjLaAOPNr7CnAszoHyZh+ddFTTAt54QfY VygXR3e1YfVysxUDTh3VBGuwsRluMU5eXC7R1j+Etr+GloQndZz2MBKrfd0NQwM95ud2 QgCnqlZDEmo1yDmESK7C2f6+FbjbzUgJ2Lz2V7NRyopx2LgoY5Dc5WfFnmYdGMI0o0TL L+9Dd7acjwBOHtM/tqhpgqLJQy5ZEry6BI8ki1WZ34YRChdqRWrzhAZM0bb9RydZoHt0 HJkw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
I discovered that
% typeset -A foo=(a 1)
% foo+=()
results in foo being emptied, which surprised me.
Daniel Shahaf tracked down the code in question and figured out removing
the original "if (alen)" line appeared to fix it. This patch attempts to
be more similar to the previous code in the case that we are not appending
(which is called augmenting in the code but nowhere in the documentation,
okay). I also took the opportunity to reword the very confusing golfed
statement into something you can follow somewhat easily.
I haven't run into any problems so far, but it might be worth giving
this a second look.
---
Src/params.c | 9 ++++++---
Test/A06assign.ztst | 8 ++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Src/params.c b/Src/params.c
index c8b4356..e7c2ce7 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3315,9 +3315,12 @@ arrhashsetfn(Param pm, char **val, int augment)
zerr("bad set of key/value pairs for associative array");
return;
}
- if (alen)
- if (!(augment && (ht = paramtab = pm->gsu.h->getfn(pm))))
- ht = paramtab = newparamtable(17, pm->node.nam);
+ if (augment) {
+ ht = paramtab = pm->gsu.h->getfn(pm);
+ }
+ if (alen && (!augment || !paramtab)) {
+ ht = paramtab = newparamtable(17, pm->node.nam);
+ }
while (*aptr) {
/* The parameter name is ztrdup'd... */
v->pm = createparam(*aptr, PM_SCALAR|PM_UNSET);
diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst
index 302659c..1e3d2ed 100644
--- a/Test/A06assign.ztst
+++ b/Test/A06assign.ztst
@@ -249,6 +249,14 @@
>2
>3
+ typeset -A h
+ h=(a 1 b 2)
+ h+=()
+ print -l $h
+0:add empty array to association
+>1
+>2
+
# tests of var[range]+=scalar
s=sting
--
2.5.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author