Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: seg fault with functions +M -m
- X-seq: zsh-workers 33323
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: seg fault with functions +M -m
- Date: Thu, 02 Oct 2014 14:55:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1412254510; bh=ZOElgh8aY3tdn9wfZ+ls0vXPSZ73fNZeGuE9rMtYfEk=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=nfskMkds/GvaJTSmvipyTffem5eFZdpmp7m5AjcQQKEifq0M0SRe7XoEkNOsGmDuObc/EnmjN73F/ovIdjRWH0WD/cbABZgkugQJ70sZZnTrr8lR8scyCQn9WcVgkhG8imZUwzjMGEU6EpzT4xbUFUxOpmbZ8TtEq3ByHhoxz18=
- 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
If you remove the last math function in the list of math functions,
functions +M seg faults. There's an inner loop which is used where
there are consecutive functions to remove but it breaks down at the end
of the list. I realise that I could already be accused of trolling
yesterday but the whole function would be a lot simpler if a single
pointer to a pointer was used instead of current (p) and previous (q)
pointers. Given that we're just before a release, I've opted for a
non-invasive change in the patch below.
Also the relatively new -M/+M options to functions are missing from the
completion function so I've added that. This patch also makes a tiny
tweak to the documentation for this feature to indicate that +M can take
multiple arguments.
Oliver
diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index f876e1b..367dbfc 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -1,7 +1,7 @@
#compdef autoload declare export functions integer float local readonly typeset
local expl state line func i use curcontext="$curcontext"
-local fopts="-f -k -z"
+local fopts="-f -k -z +k +z"
local popts="-A -E -F -L -R -T -Z -a -g -h -H -i -l -r -x"
local -A allargs opt_args
local -a args
@@ -51,8 +51,9 @@ case ${service} in
;;
float) use="EFHghlprtux";;
functions)
- use="UkmTtuz"
+ use="UkmTtuzM"
func=f
+ allargs[M]='(-k -t -T -u -U -z -M +M +k +t +z)-+M[define mathematical function]'
;;
integer)
use="Hghilprtux"
@@ -73,14 +74,20 @@ onopts=${(j..)${${words[1,CURRENT-1]:#^-*}##-}}
offopts=${(j..)${${words[1,CURRENT-1]:#^+*}##+}}
for ((i=1;i<=$#use;++i)); do
- args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[Uut]]:+$func}]} )
+ args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[UutT]]:+$func}]} )
done
_arguments -C -s -A "-*" -S "${args[@]}" '*::vars:= ->vars_eq'
if [[ "$state" = vars_eq ]]; then
if [[ $func = f ]]; then
- if (( $+opt_args[-w] ));then
+ if (( $+opt_args[+M] || ( $+opt_args[-M] && $+opt_args[-m] ) )); then
+ _wanted functions expl 'math function' compadd -F line - \
+ ${${${(f)"$(functions -M)"}##*-M }%% *}
+ elif (( $+opt_args[-M] )); then
+ _arguments ':new math function:_functions' ':minimum arguments' \
+ ':maximum arguments' ':shell function:_functions'
+ elif (( $+opt_args[-w] )); then
_wanted files expl 'zwc file' _files -g '*.zwc(-.)'
elif [[ $service = autoload || -n $opt_args[(i)-[uU]] ]]; then
args=(${^fpath}/*(-.:t))
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 9862c63..b731b62 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -773,7 +773,7 @@ findex(functions)
xitem(tt(functions) [ {tt(PLUS())|tt(-)}tt(UXkmtTuz) ] [ var(name) ... ])
xitem(tt(functions -M) var(mathfn) [ var(min) [ var(max) [ var(shellfn) ] ] ])
xitem(tt(functions -M) [ tt(-m) var(pattern) ... ])
-item(tt(functions +M) [ tt(-m) ] var(mathfn))(
+item(tt(functions +M) [ tt(-m) ] var(mathfn) ... )(
Equivalent to tt(typeset -f), with the exception of the tt(-M) option.
Use of the tt(-M) option may not be combined with any of the options
handled by tt(typeset -f).
diff --git a/Src/builtin.c b/Src/builtin.c
index a2a3ad7..4a10c7d 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2759,7 +2759,7 @@ bin_functions(char *name, char **argv, Options ops, int func)
tokenize(*argv);
if ((pprog = patcompile(*argv, PAT_STATIC, 0))) {
queue_signals();
- for (p = mathfuncs, q = NULL; p; q = p, p = p->next) {
+ for (p = mathfuncs, q = NULL; p; q = p) {
MathFunc next;
do {
next = NULL;
@@ -2774,6 +2774,8 @@ bin_functions(char *name, char **argv, Options ops, int func)
}
/* if we deleted one, retry with the new p */
} while (next);
+ if (p)
+ p = p->next;
}
unqueue_signals();
} else {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author