From 70ac0c9358251bf54f29a30a369880d94680ace7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 21:00:27 +0800 Subject: vim-patch:8.2.3889: duplicate code for translating script-local function name Problem: Duplicate code for translating script-local function name. Solution: Move the code to get_scriptlocal_funcname(). (Yegappan Lakshmanan, closes vim/vim#9393) https://github.com/vim/vim/commit/e7f4abd38b6e05100c699900c8f87281e363beb2 Co-authored-by: Yegappan Lakshmanan --- src/nvim/eval.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c4afd6934c..d8dbcf6eb0 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5018,18 +5018,11 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) int arg_idx = 0; list_T *list = NULL; if (strncmp(s, "s:", 2) == 0 || strncmp(s, "", 5) == 0) { - char sid_buf[25]; - int off = *s == 's' ? 2 : 5; - // Expand s: and into nr_, so that the function can // also be called from another script. Using trans_function_name() // would also work, but some plugins depend on the name being // printable text. - snprintf(sid_buf, sizeof(sid_buf), "%" PRId64 "_", - (int64_t)current_sctx.sc_sid); - name = xmalloc(strlen(sid_buf) + strlen(s + off) + 1); - STRCPY(name, sid_buf); - STRCAT(name, s + off); + name = get_scriptlocal_funcname(s); } else { name = xstrdup(s); } @@ -5538,6 +5531,14 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) callback->type = kCallbackNone; callback->data.funcref = NULL; } else { + if (arg->v_type == VAR_STRING) { + char *newname = get_scriptlocal_funcname(arg->vval.v_string); + if (newname != NULL) { + xfree(arg->vval.v_string); + name = arg->vval.v_string = newname; + } + } + func_ref((char_u *)name); callback->data.funcref = xstrdup(name); callback->type = kCallbackFuncref; -- cgit From afb3ff52ecafe2d5bd1239869124794bb2ac68b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 03:44:37 +0800 Subject: vim-patch:9.0.0990: callback name argument is changed by setqflist() Problem: Callback name argument is changed by setqflist(). Solution: Use the expanded function name for the callback, do not store it in the argument. (closes vim/vim#11653) https://github.com/vim/vim/commit/c96b7f5d2af241c5eb1589e9da3dc09e45355e65 Co-authored-by: Bram Moolenaar --- src/nvim/eval.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d8dbcf6eb0..6d8f4d092c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5510,6 +5510,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist } } +/// Get a callback from "arg". It can be a Funcref or a function name. bool callback_from_typval(Callback *const callback, typval_T *const arg) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { @@ -5531,16 +5532,14 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg) callback->type = kCallbackNone; callback->data.funcref = NULL; } else { + callback->data.funcref = NULL; if (arg->v_type == VAR_STRING) { - char *newname = get_scriptlocal_funcname(arg->vval.v_string); - if (newname != NULL) { - xfree(arg->vval.v_string); - name = arg->vval.v_string = newname; - } + callback->data.funcref = get_scriptlocal_funcname(name); } - - func_ref((char_u *)name); - callback->data.funcref = xstrdup(name); + if (callback->data.funcref == NULL) { + callback->data.funcref = xstrdup(name); + } + func_ref((char_u *)callback->data.funcref); callback->type = kCallbackFuncref; } } else if (nlua_is_table_from_lua(arg)) { -- cgit