To: vim_dev@googlegroups.com Subject: Patch 9.0.1624 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1624 Problem: Crash when calling object constructor from legacy script. (Israel Chauca Fuentes) Solution: Pass a pointer for "ufunc". (closes #12502) Files: src/userfunc.c, src/structs.h, src/testdir/test_vim9_class.vim *** ../vim-9.0.1623/src/userfunc.c 2023-06-04 18:11:31.998816728 +0100 --- src/userfunc.c 2023-06-10 16:23:25.011096640 +0100 *************** *** 3666,3671 **** --- 3666,3674 ---- if (partial != NULL) fp = partial->pt_func; if (fp == NULL) + fp = funcexe->fe_ufunc; + + if (fp == NULL) { // Make a copy of the name, if it comes from a funcref variable it // could be changed or deleted in the called function. *************** *** 4161,4168 **** if (lv.ll_ufunc != NULL) { ! *ufunc = lv.ll_ufunc; name = vim_strsave(lv.ll_ufunc->uf_name); goto theend; } --- 4164,4173 ---- if (lv.ll_ufunc != NULL) { ! if (ufunc != NULL) ! *ufunc = lv.ll_ufunc; name = vim_strsave(lv.ll_ufunc->uf_name); + *pp = end; goto theend; } *************** *** 5915,5921 **** char_u *name, char_u **arg, char_u *startarg, ! funcexe_T *funcexe_init, evalarg_T *evalarg) { linenr_T lnum; --- 5920,5926 ---- char_u *name, char_u **arg, char_u *startarg, ! funcexe_T *funcexe_init, evalarg_T *evalarg) { linenr_T lnum; *************** *** 6204,6209 **** --- 6209,6215 ---- int len; int failed = FALSE; funcdict_T fudi; + ufunc_T *ufunc = NULL; partial_T *partial = NULL; evalarg_T evalarg; type_T *type = NULL; *************** *** 6227,6233 **** } tofree = trans_function_name_ext(&arg, NULL, FALSE, TFN_INT, ! &fudi, &partial, vim9script ? &type : NULL, NULL); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. --- 6233,6239 ---- } tofree = trans_function_name_ext(&arg, NULL, FALSE, TFN_INT, ! &fudi, &partial, vim9script ? &type : NULL, &ufunc); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. *************** *** 6275,6280 **** --- 6281,6287 ---- CLEAR_FIELD(funcexe); funcexe.fe_check_type = type; + funcexe.fe_ufunc = ufunc; funcexe.fe_partial = partial; funcexe.fe_selfdict = fudi.fd_dict; funcexe.fe_firstline = eap->line1; *** ../vim-9.0.1623/src/structs.h 2023-05-27 22:22:06.458633197 +0100 --- src/structs.h 2023-06-10 16:08:27.310608810 +0100 *************** *** 2184,2190 **** linenr_T fe_lastline; // last line of range int *fe_doesrange; // if not NULL: return: function handled range int fe_evaluate; // actually evaluate expressions ! partial_T *fe_partial; // for extra arguments dict_T *fe_selfdict; // Dictionary for "self" object_T *fe_object; // object, e.g. for "this.Func()" typval_T *fe_basetv; // base for base->method() --- 2184,2192 ---- linenr_T fe_lastline; // last line of range int *fe_doesrange; // if not NULL: return: function handled range int fe_evaluate; // actually evaluate expressions ! ufunc_T *fe_ufunc; // function to be called, when NULL lookup by ! // name ! partial_T *fe_partial; // for "dict" and extra arguments dict_T *fe_selfdict; // Dictionary for "self" object_T *fe_object; // object, e.g. for "this.Func()" typval_T *fe_basetv; // base for base->method() *** ../vim-9.0.1623/src/testdir/test_vim9_class.vim 2023-06-05 16:53:20.817489906 +0100 --- src/testdir/test_vim9_class.vim 2023-06-10 16:25:59.043062525 +0100 *************** *** 1767,1772 **** --- 1767,1795 ---- v9.CheckScriptSuccess(lines) enddef + def Test_call_constructor_from_legacy() + var lines =<< trim END + vim9script + + var newCalled = 'false' + + class A + def new() + newCalled = 'true' + enddef + endclass + + export def F(options = {}): any + return A + enddef + + g:p = F() + legacy call p.new() + assert_equal('true', newCalled) + END + v9.CheckScriptSuccess(lines) + enddef + def Test_defer_with_object() var lines =<< trim END vim9script *** ../vim-9.0.1623/src/version.c 2023-06-09 21:00:55.972056565 +0100 --- src/version.c 2023-06-10 16:26:42.963050003 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1624, /**/ -- hundred-and-one symptoms of being an internet addict: 144. You eagerly await the update of the "Cool Site of the Day." /// 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 ///