To: vim_dev@googlegroups.com Subject: Patch 8.2.2812 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2812 Problem: Vim9: still crash when using substitute expression. Solution: Put the instruction list in the stack frame. (closes #8154) Files: src/vim9execute.c, src/vim9.h, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.2811/src/vim9execute.c 2021-04-25 14:48:45.500794221 +0200 --- src/vim9execute.c 2021-04-26 20:28:26.379200014 +0200 *************** *** 279,284 **** --- 279,285 ---- // Store current execution state in stack frame for ISN_RETURN. STACK_TV_BOT(STACK_FRAME_FUNC_OFF)->vval.v_number = ectx->ec_dfunc_idx; STACK_TV_BOT(STACK_FRAME_IIDX_OFF)->vval.v_number = ectx->ec_iidx; + STACK_TV_BOT(STACK_FRAME_INSTR_OFF)->vval.v_string = (void *)ectx->ec_instr; STACK_TV_BOT(STACK_FRAME_OUTER_OFF)->vval.v_string = (void *)ectx->ec_outer; STACK_TV_BOT(STACK_FRAME_FUNCLOCAL_OFF)->vval.v_string = (void *)floc; STACK_TV_BOT(STACK_FRAME_IDX_OFF)->vval.v_number = ectx->ec_frame_idx; *************** *** 592,597 **** --- 593,600 ---- ectx->ec_dfunc_idx = prev_dfunc_idx; ectx->ec_iidx = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_IIDX_OFF)->vval.v_number; + ectx->ec_instr = (void *)STACK_TV(ectx->ec_frame_idx + + STACK_FRAME_INSTR_OFF)->vval.v_string; ectx->ec_outer = (void *)STACK_TV(ectx->ec_frame_idx + STACK_FRAME_OUTER_OFF)->vval.v_string; floc = (void *)STACK_TV(ectx->ec_frame_idx *************** *** 599,611 **** // restoring ec_frame_idx must be last ectx->ec_frame_idx = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_IDX_OFF)->vval.v_number; - ectx->ec_instr = INSTRUCTIONS(prev_dfunc); - - // If the call was inside an ISN_SUBSTITUTE instruction need to use its - // list of instructions. - if (ectx->ec_instr[ectx->ec_iidx - 1].isn_type == ISN_SUBSTITUTE) - ectx->ec_instr = ectx->ec_instr[ectx->ec_iidx - 1] - .isn_arg.subs.subs_instr; if (floc == NULL) ectx->ec_funclocal.floc_restore_cmdmod = FALSE; --- 602,607 ---- *** ../vim-8.2.2811/src/vim9.h 2021-04-19 20:49:58.156857538 +0200 --- src/vim9.h 2021-04-26 20:22:43.064076181 +0200 *************** *** 427,441 **** // Number of entries used by stack frame for a function call. // - ec_dfunc_idx: function index // - ec_iidx: instruction index // - ec_outer: stack used for closures // - funclocal: function-local data // - ec_frame_idx: previous frame index #define STACK_FRAME_FUNC_OFF 0 #define STACK_FRAME_IIDX_OFF 1 ! #define STACK_FRAME_OUTER_OFF 2 ! #define STACK_FRAME_FUNCLOCAL_OFF 3 ! #define STACK_FRAME_IDX_OFF 4 ! #define STACK_FRAME_SIZE 5 #ifdef DEFINE_VIM9_GLOBALS --- 427,443 ---- // Number of entries used by stack frame for a function call. // - ec_dfunc_idx: function index // - ec_iidx: instruction index + // - ec_instr: instruction list pointer // - ec_outer: stack used for closures // - funclocal: function-local data // - ec_frame_idx: previous frame index #define STACK_FRAME_FUNC_OFF 0 #define STACK_FRAME_IIDX_OFF 1 ! #define STACK_FRAME_INSTR_OFF 2 ! #define STACK_FRAME_OUTER_OFF 3 ! #define STACK_FRAME_FUNCLOCAL_OFF 4 ! #define STACK_FRAME_IDX_OFF 5 ! #define STACK_FRAME_SIZE 6 #ifdef DEFINE_VIM9_GLOBALS *** ../vim-8.2.2811/src/testdir/test_vim9_cmd.vim 2021-04-25 16:35:52.101622736 +0200 --- src/testdir/test_vim9_cmd.vim 2021-04-26 20:29:44.006995388 +0200 *************** *** 1208,1222 **** --- 1208,1225 ---- CheckDefFailure(['s/from/\="x"/9'], 'E488:') # When calling a function the right instruction list needs to be restored. + g:cond = true var lines =<< trim END vim9script def Foo() Bar([]) enddef def Bar(l: list) + if g:cond s/^/\=Rep()/ for n in l[:] endfor + endif enddef def Rep(): string return 'rep' *************** *** 1227,1232 **** --- 1230,1236 ---- bwipe! END CheckScriptSuccess(lines) + unlet g:cond enddef def Test_redir_to_var() *** ../vim-8.2.2811/src/version.c 2021-04-25 16:35:52.101622736 +0200 --- src/version.c 2021-04-26 20:31:35.054699695 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2812, /**/ -- The CIA drives around in cars with the "Intel inside" logo. /// 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 ///