Patch 8.2.4179

3 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 22, 2022, 8:39:47 AMJan 22
to vim...@googlegroups.com

Patch 8.2.4179
Problem: 'foldtext' is evaluated in the current script context.
Solution: Use the script context where the option was set.
Files: src/fold.c, src/buffer.c, src/eval.c, src/proto/eval.pro,
src/findfile.c, src/testdir/test_vim9_import.vim


*** ../vim-8.2.4178/src/fold.c 2022-01-21 16:31:06.299109897 +0000
--- src/fold.c 2022-01-22 13:27:44.713228582 +0000
***************
*** 1923,1929 ****
if (*wp->w_p_fdt != NUL)
{
char_u dashes[MAX_LEVEL + 2];
- win_T *save_curwin;
int level;
char_u *p;

--- 1923,1928 ----
***************
*** 1941,1963 ****
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
set_vim_var_nr(VV_FOLDLEVEL, (long)level);

! // skip evaluating foldtext on errors
if (!got_fdt_error)
{
! save_curwin = curwin;
curwin = wp;
curbuf = wp->w_buffer;

! ++emsg_silent; // handle exceptions, but don't display errors
text = eval_to_string_safe(wp->w_p_fdt,
! was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
! --emsg_silent;

if (text == NULL || did_emsg)
got_fdt_error = TRUE;

curwin = save_curwin;
curbuf = curwin->w_buffer;
}
last_lnum = lnum;
last_wp = wp;
--- 1940,1966 ----
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
set_vim_var_nr(VV_FOLDLEVEL, (long)level);

! // skip evaluating 'foldtext' on errors
if (!got_fdt_error)
{
! win_T *save_curwin = curwin;
! sctx_T saved_sctx = current_sctx;
!
curwin = wp;
curbuf = wp->w_buffer;
+ current_sctx = wp->w_p_script_ctx[WV_FDT];

! ++emsg_off; // handle exceptions, but don't display errors
text = eval_to_string_safe(wp->w_p_fdt,
! was_set_insecurely((char_u *)"foldtext", OPT_LOCAL), TRUE);
! --emsg_off;

if (text == NULL || did_emsg)
got_fdt_error = TRUE;

curwin = save_curwin;
curbuf = curwin->w_buffer;
+ current_sctx = saved_sctx;
}
last_lnum = lnum;
last_wp = wp;
*** ../vim-8.2.4178/src/buffer.c 2022-01-20 21:00:50.805143925 +0000
--- src/buffer.c 2022-01-22 13:25:21.276161873 +0000
***************
*** 4162,4168 ****
tv.vval.v_number = wp->w_id;
set_var((char_u *)"g:statusline_winid", &tv, FALSE);

! usefmt = eval_to_string_safe(fmt + 2, use_sandbox);
if (usefmt == NULL)
usefmt = fmt;

--- 4162,4168 ----
tv.vval.v_number = wp->w_id;
set_var((char_u *)"g:statusline_winid", &tv, FALSE);

! usefmt = eval_to_string_safe(fmt + 2, use_sandbox, FALSE);
if (usefmt == NULL)
usefmt = fmt;

***************
*** 4546,4552 ****
if (curwin != save_curwin)
VIsual_active = FALSE;

! str = eval_to_string_safe(p, use_sandbox);

curwin = save_curwin;
curbuf = save_curbuf;
--- 4546,4552 ----
if (curwin != save_curwin)
VIsual_active = FALSE;

! str = eval_to_string_safe(p, use_sandbox, FALSE);

curwin = save_curwin;
curbuf = save_curbuf;
*** ../vim-8.2.4178/src/eval.c 2022-01-21 16:31:06.299109897 +0000
--- src/eval.c 2022-01-22 13:25:48.855596577 +0000
***************
*** 555,568 ****
char_u *
eval_to_string_safe(
char_u *arg,
! int use_sandbox)
{
char_u *retval;
funccal_entry_T funccal_entry;
int save_sc_version = current_sctx.sc_version;
int save_garbage = may_garbage_collect;

! current_sctx.sc_version = 1;
save_funccal(&funccal_entry);
if (use_sandbox)
++sandbox;
--- 555,570 ----
char_u *
eval_to_string_safe(
char_u *arg,
! int use_sandbox,
! int keep_script_version)
{
char_u *retval;
funccal_entry_T funccal_entry;
int save_sc_version = current_sctx.sc_version;
int save_garbage = may_garbage_collect;

! if (!keep_script_version)
! current_sctx.sc_version = 1;
save_funccal(&funccal_entry);
if (use_sandbox)
++sandbox;
*** ../vim-8.2.4178/src/proto/eval.pro 2022-01-21 16:31:06.299109897 +0000
--- src/proto/eval.pro 2022-01-22 13:27:05.818022432 +0000
***************
*** 14,20 ****
char_u *typval2string(typval_T *tv, int convert);
char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
char_u *eval_to_string(char_u *arg, int convert);
! char_u *eval_to_string_safe(char_u *arg, int use_sandbox);
varnumber_T eval_to_number(char_u *expr);
typval_T *eval_expr(char_u *arg, exarg_T *eap);
int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
--- 14,20 ----
char_u *typval2string(typval_T *tv, int convert);
char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
char_u *eval_to_string(char_u *arg, int convert);
! char_u *eval_to_string_safe(char_u *arg, int use_sandbox, int keep_script_version);
varnumber_T eval_to_number(char_u *expr);
typval_T *eval_expr(char_u *arg, exarg_T *eap);
int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
*** ../vim-8.2.4178/src/findfile.c 2022-01-08 16:19:18.505639885 +0000
--- src/findfile.c 2022-01-22 13:26:33.326686429 +0000
***************
*** 2097,2103 ****

set_vim_var_string(VV_FNAME, ptr, len);
res = eval_to_string_safe(curbuf->b_p_inex,
! was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL));
set_vim_var_string(VV_FNAME, NULL, 0);
return res;
}
--- 2097,2103 ----

set_vim_var_string(VV_FNAME, ptr, len);
res = eval_to_string_safe(curbuf->b_p_inex,
! was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), FALSE);
set_vim_var_string(VV_FNAME, NULL, 0);
return res;
}
*** ../vim-8.2.4178/src/testdir/test_vim9_import.vim 2022-01-22 11:27:24.694028145 +0000
--- src/testdir/test_vim9_import.vim 2022-01-22 13:22:56.883133377 +0000
***************
*** 683,688 ****
--- 683,691 ----
export def Expr(): string
return getline(v:lnum) =~ '^#' ? '>1' : '1'
enddef
+ export def Text(): string
+ return 'fold text'
+ enddef
g:fold_loaded = 'yes'
END
writefile(lines, 'Xdir/autoload/fold.vim')
***************
*** 691,696 ****
--- 694,700 ----
vim9script
import autoload 'fold.vim'
&foldexpr = 'fold.Expr()'
+ &foldtext = 'fold.Text()'
&foldmethod = 'expr'
&debug = 'throw'
END
***************
*** 706,712 ****
edit! otherfile
redraw

! set foldexpr= foldmethod& debug=
bwipe!
delete('Xdir', 'rf')
&rtp = save_rtp
--- 710,716 ----
edit! otherfile
redraw

! set foldexpr= foldtext& foldmethod& debug=
bwipe!
delete('Xdir', 'rf')
&rtp = save_rtp
*** ../vim-8.2.4178/src/version.c 2022-01-22 12:27:00.823189193 +0000
--- src/version.c 2022-01-22 13:08:18.865237400 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4179,
/**/

--
BROTHER MAYNARD: Armaments Chapter Two Verses Nine to Twenty One.
ANOTHER MONK: And St. Attila raised his hand grenade up on high saying "O
Lord bless this thy hand grenade that with it thou mayest
blow thine enemies to tiny bits, in thy mercy. "and the Lord
did grin and people did feast upon the lambs and sloths and
carp and anchovies and orang-utans and breakfast cereals and
fruit bats and...
BROTHER MAYNARD: Skip a bit brother ...
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// 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