aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-09-26 15:34:17 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-09-30 21:00:17 -0400
commit2a57dce9f2ea157a6f9b15613788cdd8cebc26e5 (patch)
tree74fb8a6dba09c1dc4e4bdc41fc7e3da4bada6bee /src
parent4edf7b9ff22ca702876a7d0b5534fa2fc16b1897 (diff)
downloadrneovim-2a57dce9f2ea157a6f9b15613788cdd8cebc26e5.tar.gz
rneovim-2a57dce9f2ea157a6f9b15613788cdd8cebc26e5.tar.bz2
rneovim-2a57dce9f2ea157a6f9b15613788cdd8cebc26e5.zip
vim-patch:8.1.1319: computing function length name in many places
Problem: Computing function length name in many places. Solution: compute name length in call_func(). https://github.com/vim/vim/commit/6ed8819822994512c160006bd1204aa11ae3c494 In call_func(), reassign "len" param to (int)STRLEN(funcname) instead of using vim_strsave() which runs strlen(). "len" param is checked for v:lua functions. call_func() states that strlen() is used if "len" is set to -1.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c8
-rw-r--r--src/nvim/eval/funcs.c2
-rw-r--r--src/nvim/eval/userfunc.c11
-rw-r--r--src/nvim/normal.c2
-rw-r--r--src/nvim/regexp.c4
5 files changed, 15 insertions, 12 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 00542e3766..24192dfefa 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -736,7 +736,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv,
if (s == NULL || *s == NUL) {
return FAIL;
}
- if (call_func(s, (int)STRLEN(s), rettv, argc, argv, NULL,
+ if (call_func(s, -1, rettv, argc, argv, NULL,
0L, 0L, &dummy, true, NULL, NULL) == FAIL) {
return FAIL;
}
@@ -746,7 +746,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv,
if (s == NULL || *s == NUL) {
return FAIL;
}
- if (call_func(s, (int)STRLEN(s), rettv, argc, argv, NULL,
+ if (call_func(s, -1, rettv, argc, argv, NULL,
0L, 0L, &dummy, true, partial, NULL) == FAIL) {
return FAIL;
}
@@ -7270,7 +7270,7 @@ bool callback_call(Callback *const callback, const int argcount_in,
}
int dummy;
- return call_func(name, (int)STRLEN(name), rettv, argcount_in, argvars_in,
+ return call_func(name, -1, rettv, argcount_in, argvars_in,
NULL, curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy,
true, partial, NULL);
}
@@ -8492,7 +8492,7 @@ handle_subscript(
} else {
s = (char_u *)"";
}
- ret = get_func_tv(s, lua ? slen : (int)STRLEN(s), rettv, (char_u **)arg,
+ ret = get_func_tv(s, lua ? slen : -1, rettv, (char_u **)arg,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&len, evaluate, pt, selfdict);
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index bd77a3b7e2..83ad948a93 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -9174,7 +9174,7 @@ static int item_compare2(const void *s1, const void *s2, bool keep_zero)
rettv.v_type = VAR_UNKNOWN; // tv_clear() uses this
res = call_func((const char_u *)func_name,
- (int)STRLEN(func_name),
+ -1,
&rettv, 2, argv, NULL, 0L, 0L, &dummy, true,
partial, sortinfo->item_compare_selfdict);
tv_clear(&argv[0]);
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index d5a19dd7b9..873fe90797 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -367,7 +367,7 @@ void emsg_funcname(char *ermsg, const char_u *name)
int
get_func_tv(
const char_u *name, // name of the function
- int len, // length of "name"
+ int len, // length of "name" or -1 to use strlen()
typval_T *rettv,
char_u **arg, // argument, pointing to the '('
linenr_T firstline, // first line of range
@@ -1291,7 +1291,7 @@ int func_call(char_u *name, typval_T *args, partial_T *partial,
tv_copy(TV_LIST_ITEM_TV(item), &argv[argc++]);
});
- r = call_func(name, (int)STRLEN(name), rettv, argc, argv, NULL,
+ r = call_func(name, -1, rettv, argc, argv, NULL,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&dummy, true, partial, selfdict);
@@ -1316,7 +1316,7 @@ func_call_skip_call:
int
call_func(
const char_u *funcname, // name of the function
- int len, // length of "name"
+ int len, // length of "name" or -1 to use strlen()
typval_T *rettv, // [out] value goes here
int argcount_in, // number of "argvars"
typval_T *argvars_in, // vars for arguments, must have "argcount"
@@ -1350,6 +1350,9 @@ call_func(
// Make a copy of the name, if it comes from a funcref variable it could
// be changed or deleted in the called function.
+ if (len <= 0) {
+ len = (int)STRLEN(funcname);
+ }
name = vim_strnsave(funcname, len);
fname = fname_trans_sid(name, fname_buf, &tofree, &error);
@@ -2853,7 +2856,7 @@ void ex_call(exarg_T *eap)
curwin->w_cursor.coladd = 0;
}
arg = startarg;
- if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg,
+ if (get_func_tv(name, -1, &rettv, &arg,
eap->line1, eap->line2, &doesrange,
true, partial, fudi.fd_dict) == FAIL) {
failed = true;
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 760536d48a..a51aa0dc07 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -2483,7 +2483,7 @@ do_mouse (
typval_T rettv;
int doesrange;
(void)call_func((char_u *)tab_page_click_defs[mouse_col].func,
- (int)strlen(tab_page_click_defs[mouse_col].func),
+ -1,
&rettv, ARRAY_SIZE(argv), argv, NULL,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&doesrange, true, NULL, NULL);
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index a570328499..6316129c6a 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -6708,14 +6708,14 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
argv[0].vval.v_list = &matchList.sl_list;
if (expr->v_type == VAR_FUNC) {
s = expr->vval.v_string;
- call_func(s, (int)STRLEN(s), &rettv, 1, argv,
+ call_func(s, -1, &rettv, 1, argv,
fill_submatch_list, 0L, 0L, &dummy,
true, NULL, NULL);
} else if (expr->v_type == VAR_PARTIAL) {
partial_T *partial = expr->vval.v_partial;
s = partial_name(partial);
- call_func(s, (int)STRLEN(s), &rettv, 1, argv,
+ call_func(s, -1, &rettv, 1, argv,
fill_submatch_list, 0L, 0L, &dummy,
true, partial, NULL);
}