Mercurial > vim
diff src/userfunc.c @ 20943:1693ca876049 v8.2.1023
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Commit: https://github.com/vim/vim/commit/0cb5bcf5836de83f7d64fb01d3ce708caacaf66c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 20 18:19:09 2020 +0200
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Problem: Vim9: redefining a function uses a new index every time.
Solution: When redefining a function clear the contents and re-use the
index.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 20 Jun 2020 18:30:04 +0200 |
parents | 9064044fd4f6 |
children | 0653b9b72091 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -409,7 +409,7 @@ get_lambda_tv(char_u **arg, typval_T *re fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); if (fp == NULL) goto errret; - fp->uf_dfunc_idx = UF_NOT_COMPILED; + fp->uf_def_status = UF_NOT_COMPILED; pt = ALLOC_CLEAR_ONE(partial_T); if (pt == NULL) goto errret; @@ -1001,7 +1001,7 @@ func_remove(ufunc_T *fp) { // When there is a def-function index do not actually remove the // function, so we can find the index when defining the function again. - if (fp->uf_dfunc_idx >= 0) + if (fp->uf_def_status == UF_COMPILED) fp->uf_flags |= FC_DEAD; else hash_remove(&func_hashtab, hi); @@ -1046,7 +1046,7 @@ func_clear(ufunc_T *fp, int force) // clear this function func_clear_items(fp); funccal_unref(fp->uf_scoped, fp, force); - delete_def_function(fp); + clear_def_function(fp); } /* @@ -1074,7 +1074,8 @@ func_free(ufunc_T *fp, int force) func_clear_free(ufunc_T *fp, int force) { func_clear(fp, force); - func_free(fp, force); + if (force || fp->uf_dfunc_idx == 0) + func_free(fp, force); } @@ -1137,7 +1138,7 @@ call_user_func( ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1); func_ptr_ref(fp); - if (fp->uf_dfunc_idx != UF_NOT_COMPILED) + if (fp->uf_def_status != UF_NOT_COMPILED) { estack_push_ufunc(fp, 1); save_current_sctx = current_sctx; @@ -1662,7 +1663,7 @@ free_all_functions(void) // clear the def function index now fp = HI2UF(hi); fp->uf_flags &= ~FC_DEAD; - fp->uf_dfunc_idx = UF_NOT_COMPILED; + fp->uf_def_status = UF_NOT_COMPILED; // Only free functions that are not refcounted, those are // supposed to be freed when no longer referenced. @@ -2058,7 +2059,7 @@ list_func_head(ufunc_T *fp, int indent) msg_start(); if (indent) msg_puts(" "); - if (fp->uf_dfunc_idx != UF_NOT_COMPILED) + if (fp->uf_def_status != UF_NOT_COMPILED) msg_puts("def "); else msg_puts("function "); @@ -2107,7 +2108,7 @@ list_func_head(ufunc_T *fp, int indent) } msg_putchar(')'); - if (fp->uf_dfunc_idx != UF_NOT_COMPILED) + if (fp->uf_def_status != UF_NOT_COMPILED) { if (fp->uf_ret_type != &t_void) { @@ -2624,7 +2625,7 @@ def_function(exarg_T *eap, char_u *name_ if (!got_int) { msg_putchar('\n'); - if (fp->uf_dfunc_idx != UF_NOT_COMPILED) + if (fp->uf_def_status != UF_NOT_COMPILED) msg_puts(" enddef"); else msg_puts(" endfunction"); @@ -3097,6 +3098,7 @@ def_function(exarg_T *eap, char_u *name_ fp->uf_profiling = FALSE; fp->uf_prof_initialized = FALSE; #endif + clear_def_function(fp); } } } @@ -3162,7 +3164,7 @@ def_function(exarg_T *eap, char_u *name_ fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); if (fp == NULL) goto erret; - fp->uf_dfunc_idx = eap->cmdidx == CMD_def ? UF_TO_BE_COMPILED + fp->uf_def_status = eap->cmdidx == CMD_def ? UF_TO_BE_COMPILED : UF_NOT_COMPILED; if (fudi.fd_dict != NULL) @@ -3219,7 +3221,7 @@ def_function(exarg_T *eap, char_u *name_ { int lnum_save = SOURCING_LNUM; - fp->uf_dfunc_idx = UF_TO_BE_COMPILED; + fp->uf_def_status = UF_TO_BE_COMPILED; // error messages are for the first function line SOURCING_LNUM = sourcing_lnum_top; @@ -3289,7 +3291,7 @@ def_function(exarg_T *eap, char_u *name_ SOURCING_LNUM = lnum_save; } else - fp->uf_dfunc_idx = UF_NOT_COMPILED; + fp->uf_def_status = UF_NOT_COMPILED; fp->uf_lines = newlines; if ((flags & FC_CLOSURE) != 0) @@ -3372,7 +3374,7 @@ ex_defcompile(exarg_T *eap UNUSED) --todo; ufunc = HI2UF(hi); if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid - && ufunc->uf_dfunc_idx == UF_TO_BE_COMPILED) + && ufunc->uf_def_status == UF_TO_BE_COMPILED) { compile_def_function(ufunc, FALSE, NULL);