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)

e7f4abd38b

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2022-12-02 21:00:27 +08:00
parent 07e6296520
commit 70ac0c9358
5 changed files with 71 additions and 28 deletions

View File

@@ -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, "<SID>", 5) == 0) {
char sid_buf[25];
int off = *s == 's' ? 2 : 5;
// Expand s: and <SID> into <SNR>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), "<SNR>%" 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;