Patch 8.2.4548

6 views
Skip to first unread message

Bram Moolenaar

unread,
Mar 11, 2022, 1:55:37 PM3/11/22
to vim...@googlegroups.com

Patch 8.2.4548
Problem: Script-local function is deleted when used in a funcref.
Solution: Do not consider a function starting with "<SNR>" reference
counted. (closes #9916, closes #9820)
Files: src/userfunc.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.4547/src/userfunc.c 2022-03-08 19:43:51.688198945 +0000
--- src/userfunc.c 2022-03-11 18:51:17.221099302 +0000
***************
*** 2215,2222 ****

/*
* There are two kinds of function names:
! * 1. ordinary names, function defined with :function or :def
! * 2. numbered functions and lambdas
* For the first we only count the name stored in func_hashtab as a reference,
* using function() does not count as a reference, because the function is
* looked up by name.
--- 2215,2223 ----

/*
* There are two kinds of function names:
! * 1. ordinary names, function defined with :function or :def;
! * can start with "<SNR>123_" literally or with K_SPECIAL.
! * 2. Numbered functions and lambdas: "<lambda>123"
* For the first we only count the name stored in func_hashtab as a reference,
* using function() does not count as a reference, because the function is
* looked up by name.
***************
*** 2224,2230 ****
int
func_name_refcount(char_u *name)
{
! return numbered_function(name) || *name == '<';
}

/*
--- 2225,2231 ----
int
func_name_refcount(char_u *name)
{
! return numbered_function(name) || (name[0] == '<' && name[1] == 'l');
}

/*
*** ../vim-8.2.4547/src/testdir/test_vim9_func.vim 2022-03-08 19:43:51.692198946 +0000
--- src/testdir/test_vim9_func.vim 2022-03-11 18:50:26.253226566 +0000
***************
*** 3717,3722 ****
--- 3717,3740 ----
v9.CheckScriptSuccess(lines)
enddef

+ def Test_script_local_other_script()
+ var lines =<< trim END
+ function LegacyJob()
+ let FuncRef = function('s:close_cb')
+ endfunction
+ function s:close_cb(...)
+ endfunction
+ END
+ lines->writefile('Xlegacy.vim')
+ source Xlegacy.vim
+ g:LegacyJob()
+ g:LegacyJob()
+ g:LegacyJob()
+
+ delfunc g:LegacyJob
+ delete('Xlegacy.vim')
+ enddef
+
def Test_check_func_arg_types()
var lines =<< trim END
vim9script
*** ../vim-8.2.4547/src/version.c 2022-03-11 16:01:22.309619180 +0000
--- src/version.c 2022-03-11 18:22:31.883774292 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4548,
/**/

--
hundred-and-one symptoms of being an internet addict:
233. You start dreaming about web pages...in html.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages