To: vim_dev@googlegroups.com Subject: Patch 8.2.3351 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3351 Problem: Vim9: using a function by name may delete it. (Naohiro Ono) Solution: Increment the reference count when using a function by name. (closes #8760) Files: src/evalvars.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.3350/src/evalvars.c 2021-08-15 13:49:38.126905573 +0200 --- src/evalvars.c 2021-08-15 15:44:04.110389452 +0200 *************** *** 2636,2641 **** --- 2636,2643 ---- { ufunc_T *ufunc = find_func(name, FALSE, NULL); + // In Vim9 script we can get a function reference by using the + // function name. if (ufunc != NULL) { found = TRUE; *************** *** 2643,2648 **** --- 2645,2652 ---- { rettv->v_type = VAR_FUNC; rettv->vval.v_string = vim_strsave(ufunc->uf_name); + if (rettv->vval.v_string != NULL) + func_ref(ufunc->uf_name); } } } *** ../vim-8.2.3350/src/testdir/test_vim9_func.vim 2021-08-14 14:00:58.233863891 +0200 --- src/testdir/test_vim9_func.vim 2021-08-15 16:00:40.555745202 +0200 *************** *** 3089,3094 **** --- 3089,3111 ---- call CheckDefAndScriptSuccess(lines) enddef + func CreateMydict() + let g:mydict = {} + func g:mydict.afunc() + let g:result = self.key + endfunc + endfunc + + def Test_numbered_function_reference() + CreateMydict() + var output = execute('legacy func g:mydict.afunc') + var funcName = 'g:' .. substitute(output, '.*function \(\d\+\).*', '\1', '') + execute 'function(' .. funcName .. ', [], {key: 42})()' + # check that the function still exists + assert_equal(output, execute('legacy func g:mydict.afunc')) + unlet g:mydict + enddef + if has('python3') def Test_python3_heredoc() py3 << trim EOF *** ../vim-8.2.3350/src/version.c 2021-08-15 15:04:37.188080291 +0200 --- src/version.c 2021-08-15 15:45:25.558121144 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3351, /**/ -- Arthur pulls Pin out. The MONK blesses the grenade as ... ARTHUR: (quietly) One, two, five ... GALAHAD: Three, sir! ARTHUR: Three. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@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 ///