mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
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().
6ed8819822
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.
This commit is contained in:
parent
4edf7b9ff2
commit
2a57dce9f2
@ -736,7 +736,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv,
|
|||||||
if (s == NULL || *s == NUL) {
|
if (s == NULL || *s == NUL) {
|
||||||
return FAIL;
|
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) {
|
0L, 0L, &dummy, true, NULL, NULL) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv,
|
|||||||
if (s == NULL || *s == NUL) {
|
if (s == NULL || *s == NUL) {
|
||||||
return FAIL;
|
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) {
|
0L, 0L, &dummy, true, partial, NULL) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -7270,7 +7270,7 @@ bool callback_call(Callback *const callback, const int argcount_in,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dummy;
|
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,
|
NULL, curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy,
|
||||||
true, partial, NULL);
|
true, partial, NULL);
|
||||||
}
|
}
|
||||||
@ -8492,7 +8492,7 @@ handle_subscript(
|
|||||||
} else {
|
} else {
|
||||||
s = (char_u *)"";
|
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,
|
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
|
||||||
&len, evaluate, pt, selfdict);
|
&len, evaluate, pt, selfdict);
|
||||||
|
|
||||||
|
@ -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
|
rettv.v_type = VAR_UNKNOWN; // tv_clear() uses this
|
||||||
res = call_func((const char_u *)func_name,
|
res = call_func((const char_u *)func_name,
|
||||||
(int)STRLEN(func_name),
|
-1,
|
||||||
&rettv, 2, argv, NULL, 0L, 0L, &dummy, true,
|
&rettv, 2, argv, NULL, 0L, 0L, &dummy, true,
|
||||||
partial, sortinfo->item_compare_selfdict);
|
partial, sortinfo->item_compare_selfdict);
|
||||||
tv_clear(&argv[0]);
|
tv_clear(&argv[0]);
|
||||||
|
@ -367,7 +367,7 @@ void emsg_funcname(char *ermsg, const char_u *name)
|
|||||||
int
|
int
|
||||||
get_func_tv(
|
get_func_tv(
|
||||||
const char_u *name, // name of the function
|
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,
|
typval_T *rettv,
|
||||||
char_u **arg, // argument, pointing to the '('
|
char_u **arg, // argument, pointing to the '('
|
||||||
linenr_T firstline, // first line of range
|
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++]);
|
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,
|
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
|
||||||
&dummy, true, partial, selfdict);
|
&dummy, true, partial, selfdict);
|
||||||
|
|
||||||
@ -1316,7 +1316,7 @@ func_call_skip_call:
|
|||||||
int
|
int
|
||||||
call_func(
|
call_func(
|
||||||
const char_u *funcname, // name of the function
|
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
|
typval_T *rettv, // [out] value goes here
|
||||||
int argcount_in, // number of "argvars"
|
int argcount_in, // number of "argvars"
|
||||||
typval_T *argvars_in, // vars for arguments, must have "argcount"
|
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
|
// Make a copy of the name, if it comes from a funcref variable it could
|
||||||
// be changed or deleted in the called function.
|
// be changed or deleted in the called function.
|
||||||
|
if (len <= 0) {
|
||||||
|
len = (int)STRLEN(funcname);
|
||||||
|
}
|
||||||
name = vim_strnsave(funcname, len);
|
name = vim_strnsave(funcname, len);
|
||||||
|
|
||||||
fname = fname_trans_sid(name, fname_buf, &tofree, &error);
|
fname = fname_trans_sid(name, fname_buf, &tofree, &error);
|
||||||
@ -2853,7 +2856,7 @@ void ex_call(exarg_T *eap)
|
|||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
}
|
}
|
||||||
arg = startarg;
|
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,
|
eap->line1, eap->line2, &doesrange,
|
||||||
true, partial, fudi.fd_dict) == FAIL) {
|
true, partial, fudi.fd_dict) == FAIL) {
|
||||||
failed = true;
|
failed = true;
|
||||||
|
@ -2483,7 +2483,7 @@ do_mouse (
|
|||||||
typval_T rettv;
|
typval_T rettv;
|
||||||
int doesrange;
|
int doesrange;
|
||||||
(void)call_func((char_u *)tab_page_click_defs[mouse_col].func,
|
(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,
|
&rettv, ARRAY_SIZE(argv), argv, NULL,
|
||||||
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
|
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
|
||||||
&doesrange, true, NULL, NULL);
|
&doesrange, true, NULL, NULL);
|
||||||
|
@ -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;
|
argv[0].vval.v_list = &matchList.sl_list;
|
||||||
if (expr->v_type == VAR_FUNC) {
|
if (expr->v_type == VAR_FUNC) {
|
||||||
s = expr->vval.v_string;
|
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,
|
fill_submatch_list, 0L, 0L, &dummy,
|
||||||
true, NULL, NULL);
|
true, NULL, NULL);
|
||||||
} else if (expr->v_type == VAR_PARTIAL) {
|
} else if (expr->v_type == VAR_PARTIAL) {
|
||||||
partial_T *partial = expr->vval.v_partial;
|
partial_T *partial = expr->vval.v_partial;
|
||||||
|
|
||||||
s = partial_name(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,
|
fill_submatch_list, 0L, 0L, &dummy,
|
||||||
true, partial, NULL);
|
true, partial, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user