To: vim_dev@googlegroups.com Subject: Patch 7.4.1638 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1638 Problem: When binding a function to a dict the reference count is wrong. Solution: Decrement dict reference count, only reference the function when actually making a copy. (Ken Takata) Files: src/eval.c, src/testdir/test_partial.vim *** ../vim-7.4.1637/src/eval.c 2016-03-20 20:56:56.036283020 +0100 --- src/eval.c 2016-03-22 20:57:04.986808504 +0100 *************** *** 12019,12024 **** --- 12019,12025 ---- for (i = 0; i < pt->pt_argc; ++i) clear_tv(&pt->pt_argv[i]); vim_free(pt->pt_argv); + dict_unref(pt->pt_dict); func_unref(pt->pt_name); vim_free(pt->pt_name); vim_free(pt); *************** *** 21797,21803 **** selfdict = NULL; if (rettv->v_type == VAR_FUNC) { ! /* just a function: use selfdict */ pt->pt_name = rettv->vval.v_string; } else --- 21798,21805 ---- selfdict = NULL; if (rettv->v_type == VAR_FUNC) { ! /* Just a function: Take over the function name and use ! * selfdict. */ pt->pt_name = rettv->vval.v_string; } else *************** *** 21805,21812 **** partial_T *ret_pt = rettv->vval.v_partial; int i; ! /* partial: use selfdict and copy args */ pt->pt_name = vim_strsave(ret_pt->pt_name); if (ret_pt->pt_argc > 0) { pt->pt_argv = (typval_T *)alloc( --- 21807,21817 ---- partial_T *ret_pt = rettv->vval.v_partial; int i; ! /* Partial: copy the function name, use selfdict and copy ! * args. Can't take over name or args, the partial might ! * be referenced elsewhere. */ pt->pt_name = vim_strsave(ret_pt->pt_name); + func_ref(pt->pt_name); if (ret_pt->pt_argc > 0) { pt->pt_argv = (typval_T *)alloc( *************** *** 21823,21829 **** } partial_unref(ret_pt); } - func_ref(pt->pt_name); rettv->v_type = VAR_PARTIAL; rettv->vval.v_partial = pt; } --- 21828,21833 ---- *** ../vim-7.4.1637/src/testdir/test_partial.vim 2016-03-19 20:05:38.080396214 +0100 --- src/testdir/test_partial.vim 2016-03-22 20:49:39.863348049 +0100 *************** *** 170,172 **** --- 170,182 ---- let F = function('MyFunc', ['foo'], d) call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F)) endfunc + + func Test_func_unref() + let obj = {} + function! obj.func() abort + endfunction + let funcnumber = matchstr(string(obj.func), '^function(''\zs.\{-}\ze''') + call assert_true(exists('*{' . funcnumber . '}')) + unlet obj + call assert_false(exists('*{' . funcnumber . '}')) + endfunc *** ../vim-7.4.1637/src/version.c 2016-03-22 20:42:26.967739061 +0100 --- src/version.c 2016-03-22 20:58:04.218201619 +0100 *************** *** 750,751 **** --- 750,753 ---- { /* Add new patch number below this line */ + /**/ + 1638, /**/ -- hundred-and-one symptoms of being an internet addict: 97. Your mother tells you to remember something, and you look for a File/Save command. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///