From f8680d009741d01e137aeb2232aa7e033cd70d7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Jan 2025 09:27:08 +0800 Subject: vim-patch:9.1.1013: Vim9: Regression caused by patch v9.1.0646 Problem: Vim9: Regression caused by patch v9.1.0646 Solution: Translate the function name before invoking it in call() (Yegappan Lakshmanan) fixes: vim/vim#16430 closes: vim/vim#16445 https://github.com/vim/vim/commit/6289f9159102e0855bedc566636b5e7ca6ced72c N/A patch: vim-patch:8.2.4176: Vim9: cannot use imported function with call() Co-authored-by: Yegappan Lakshmanan --- src/nvim/errors.h | 1 + src/nvim/eval/funcs.c | 15 +++++++++++---- src/nvim/eval/userfunc.c | 1 - 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/errors.h b/src/nvim/errors.h index df94945a3d..baea005f15 100644 --- a/src/nvim/errors.h +++ b/src/nvim/errors.h @@ -129,6 +129,7 @@ EXTERN const char e_missingparen[] INIT(= N_("E107: Missing parentheses: %s")); EXTERN const char e_empty_buffer[] INIT(= N_("E749: Empty buffer")); EXTERN const char e_nobufnr[] INIT(= N_("E86: Buffer %" PRId64 " does not exist")); +EXTERN const char e_unknown_function_str[] INIT(= N_("E117: Unknown function: %s")); EXTERN const char e_str_not_inside_function[] INIT(= N_("E193: %s not inside a function")); EXTERN const char e_invalpat[] INIT(= N_("E682: Invalid search pattern or delimiter")); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index ed3efca0d7..0d2653ef21 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -575,22 +575,29 @@ static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (func == NULL || *func == NUL) { return; // type error, empty name or null function } + char *p = func; + char *tofree = trans_function_name(&p, false, TFN_INT|TFN_QUIET, NULL, NULL); + if (tofree == NULL) { + emsg_funcname(e_unknown_function_str, func); + return; + } + func = tofree; dict_T *selfdict = NULL; if (argvars[2].v_type != VAR_UNKNOWN) { if (tv_check_for_dict_arg(argvars, 2) == FAIL) { - if (owned) { - func_unref(func); - } - return; + goto done; } selfdict = argvars[2].vval.v_dict; } func_call(func, &argvars[1], partial, selfdict, rettv); + +done: if (owned) { func_unref(func); } + xfree(tofree); } /// "changenr()" function diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 4f1098632c..a24a3d5622 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -78,7 +78,6 @@ static funccall_T *current_funccal = NULL; // item in it is still being used. static funccall_T *previous_funccal = NULL; -static const char *e_unknown_function_str = N_("E117: Unknown function: %s"); static const char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it"); static const char *e_funcdict = N_("E717: Dictionary entry already exists"); static const char *e_funcref = N_("E718: Funcref required"); -- cgit From 47a4e4239203fe96d404874bdc1ea6910f72b695 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Jan 2025 09:35:52 +0800 Subject: vim-patch:9.1.1017: Vim9: Patch 9.1.1013 causes a few problems Problem: Vim9: Patch 9.1.1013 causes a few problems Solution: Translate the function name only when it is a string (Yegappan Lakshmanan) fixes: vim/vim#16453 closes: vim/vim#16450 https://github.com/vim/vim/commit/9904cbca4132f7376246a1a31305eb53e9530023 Cherry-pick call() change from patch 9.0.0345. Co-authored-by: Yegappan Lakshmanan --- src/nvim/eval/funcs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 0d2653ef21..c125bd8893 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -548,8 +548,7 @@ static void f_byte2line(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "call(func, arglist [, dict])" function static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (argvars[1].v_type != VAR_LIST) { - emsg(_(e_listreq)); + if (tv_check_for_list_arg(argvars, 1) == FAIL) { return; } if (argvars[1].vval.v_list == NULL) { @@ -575,13 +574,16 @@ static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (func == NULL || *func == NUL) { return; // type error, empty name or null function } - char *p = func; - char *tofree = trans_function_name(&p, false, TFN_INT|TFN_QUIET, NULL, NULL); - if (tofree == NULL) { - emsg_funcname(e_unknown_function_str, func); - return; + char *tofree = NULL; + if (argvars[0].v_type == VAR_STRING) { + char *p = func; + tofree = trans_function_name(&p, false, TFN_INT|TFN_QUIET, NULL, NULL); + if (tofree == NULL) { + emsg_funcname(e_unknown_function_str, func); + return; + } + func = tofree; } - func = tofree; dict_T *selfdict = NULL; if (argvars[2].v_type != VAR_UNKNOWN) { -- cgit