Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 1/2] internal: Add a second parameter to zlinklist2array(), analogously to hlinklist2array().
- X-seq: zsh-workers 45729
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 1/2] internal: Add a second parameter to zlinklist2array(), analogously to hlinklist2array().
- Date: Mon, 27 Apr 2020 19:30:39 +0000
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Will be used in the next commit.
---
Src/Modules/curses.c | 4 ++--
Src/Zle/compcore.c | 4 ++--
Src/Zle/computil.c | 4 ++--
Src/builtin.c | 10 +++++-----
Src/linklist.c | 13 +++++++++----
5 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/Src/Modules/curses.c b/Src/Modules/curses.c
index 19f285e34..e46903916 100644
--- a/Src/Modules/curses.c
+++ b/Src/Modules/curses.c
@@ -1212,7 +1212,7 @@ zccmd_input(const char *nam, char **args)
addlinknode(margs, "CTRL");
if (mevent.bstate & BUTTON_ALT)
addlinknode(margs, "ALT");
- if (!setaparam(args[3], zlinklist2array(margs)))
+ if (!setaparam(args[3], zlinklist2array(margs, 1)))
return 1;
} else {
#endif
@@ -1464,7 +1464,7 @@ zccmd_querychar(const char *nam, char **args)
}
/* Turn this into an array and store it. */
- return !setaparam(args[1] ? args[1] : "reply", zlinklist2array(clist));
+ return !setaparam(args[1] ? args[1] : "reply", zlinklist2array(clist, 1));
}
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 7e3badc57..958fef8e7 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -648,7 +648,7 @@ callcompfunc(char *s, char *fn)
if (compredirs)
freearray(compredirs);
if (rdstrs)
- compredirs = zlinklist2array(rdstrs);
+ compredirs = zlinklist2array(rdstrs, 1);
else
compredirs = (char **) zshcalloc(sizeof(char *));
@@ -1922,7 +1922,7 @@ set_comp_sep(void)
mod_export void
set_list_array(char *name, LinkList l)
{
- setaparam(name, zlinklist2array(l));
+ setaparam(name, zlinklist2array(l, 1));
}
/* Get the words from a variable or a (list of words). */
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 90db8b4b8..ddfa70077 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -3591,7 +3591,7 @@ bin_compvalues(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
if (cv_laststate.vals) {
char **ret;
- ret = zlinklist2array(cv_laststate.vals);
+ ret = zlinklist2array(cv_laststate.vals, 1);
sethparam(args[1], ret);
return 0;
@@ -4016,7 +4016,7 @@ bin_comptry(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
set = (Ctset) zalloc(sizeof(*set));
- set->tags = zlinklist2array(list);
+ set->tags = zlinklist2array(list, 1);
set->next = NULL;
set->ptr = NULL;
set->tag = NULL;
diff --git a/Src/builtin.c b/Src/builtin.c
index 3dab3f9b4..d5a874a95 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2280,7 +2280,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
} else if (asg->flags & ASG_ARRAY) {
int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
if (!(pm = assignaparam(pname, asg->value.array ?
- zlinklist2array(asg->value.array) :
+ zlinklist2array(asg->value.array, 1) :
mkarray(NULL), flags)))
return NULL;
}
@@ -2442,7 +2442,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
} else if (PM_TYPE(on) == PM_ARRAY && ASG_ARRAYP(asg)) {
int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
if (!(pm = assignaparam(pname, asg->value.array ?
- zlinklist2array(asg->value.array) :
+ zlinklist2array(asg->value.array, 1) :
mkarray(NULL), flags)))
return NULL;
dont_set = 1;
@@ -2536,7 +2536,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
arrayval = mkarray(NULL);
}
} else if (asg->value.array)
- arrayval = zlinklist2array(asg->value.array);
+ arrayval = zlinklist2array(asg->value.array, 1);
else
arrayval = mkarray(NULL);
if (!(pm=assignaparam(pname, arrayval, flags)))
@@ -2923,7 +2923,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
apm->ename = ztrdup(asg0.name);
if (asg->value.array) {
int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
- assignaparam(asg->name, zlinklist2array(asg->value.array), flags);
+ assignaparam(asg->name, zlinklist2array(asg->value.array, 1), flags);
} else if (oldval)
assignsparam(asg0.name, oldval, 0);
unqueue_signals();
@@ -3901,7 +3901,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
}
unqueue_signals();
if (all) {
- allmatched = argv = zlinklist2array(matchednodes);
+ allmatched = argv = zlinklist2array(matchednodes, 1);
matchednodes = NULL;
popheap();
} else
diff --git a/Src/linklist.c b/Src/linklist.c
index 85d9bb367..f64685d9e 100644
--- a/Src/linklist.c
+++ b/Src/linklist.c
@@ -438,22 +438,27 @@ hlinklist2array(LinkList list, int copy)
/*
* Convert a linked list whose data elements are strings to
- * an array. The result is a permanently allocated, freearrayable
- * array.
+ * a permanently-allocated array. The elements of the array are the same
+ * elements as the linked list data if copy is 0, else they are duplicated
+ * into permanent memory so the result is a permanently allocated,
+ * freearrayable array that's a deep copy of the linked list.
*/
/**/
mod_export char **
-zlinklist2array(LinkList list)
+zlinklist2array(LinkList list, int copy)
{
int l = countlinknodes(list);
char **ret = (char **) zalloc((l + 1) * sizeof(char *)), **p;
LinkNode n;
for (n = firstnode(list), p = ret; n; incnode(n), p++) {
- *p = ztrdup((char *) getdata(n));
+ *p = (char *) getdata(n);
+ if (copy)
+ *p = ztrdup(*p);
}
*p = NULL;
return ret;
}
+
Messages sorted by:
Reverse Date,
Date,
Thread,
Author