aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Platto <hinidu@gmail.com>2015-01-20 20:03:39 +0200
committerPavel Platto <hinidu@gmail.com>2015-01-20 21:09:45 +0200
commit85f342a110358358608c05aa1c5c6b433d0cea9a (patch)
treeee27b2801238c324c953d0866bc328b8d0f1f36a /src
parentda43f70ba726cc6dfcf3bc8c73b86a5be713cb47 (diff)
downloadrneovim-85f342a110358358608c05aa1c5c6b433d0cea9a.tar.gz
rneovim-85f342a110358358608c05aa1c5c6b433d0cea9a.tar.bz2
rneovim-85f342a110358358608c05aa1c5c6b433d0cea9a.zip
vim-patch:7.4.446
Problem: In some situations, when setting up an environment to trigger an autocommand, the environment is not properly restored. Solution: Check the return value of switch_win() and call restore_win() always. (Daniel Hahler) https://code.google.com/p/vim/source/detail?r=v7-4-446
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c51
-rw-r--r--src/nvim/memory.c3
-rw-r--r--src/nvim/version.c2
-rw-r--r--src/nvim/window.c7
4 files changed, 30 insertions, 33 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 8db473d4be..87a5ed80e7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -9604,7 +9604,7 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv)
tabpage_T *tp, *oldtabpage;
dictitem_T *v;
char_u *varname;
- int done = FALSE;
+ bool done = false;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -9614,14 +9614,14 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv)
if (tp != NULL && varname != NULL) {
/* Set tp to be our tabpage, temporarily. Also set the window to the
* first window in the tabpage, otherwise the window is not valid. */
- switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE);
-
- /* look up the variable */
- /* Let gettabvar({nr}, "") return the "t:" dictionary. */
- v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE);
- if (v != NULL) {
- copy_tv(&v->di_tv, rettv);
- done = TRUE;
+ if (switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE) == OK) {
+ // look up the variable
+ // Let gettabvar({nr}, "") return the "t:" dictionary.
+ v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE);
+ if (v != NULL) {
+ copy_tv(&v->di_tv, rettv);
+ done = true;
+ }
}
/* restore previous notion of curwin */
@@ -9712,7 +9712,7 @@ getwinvar (
dictitem_T *v;
tabpage_T *tp = NULL;
tabpage_T *oldtabpage = NULL;
- int done = FALSE;
+ bool done = false;
if (off == 1)
tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
@@ -9728,18 +9728,18 @@ getwinvar (
if (win != NULL && varname != NULL) {
/* Set curwin to be our win, temporarily. Also set the tabpage,
* otherwise the window is not valid. */
- switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE);
-
- if (*varname == '&') { /* window-local-option */
- if (get_option_tv(&varname, rettv, 1) == OK)
- done = TRUE;
- } else {
- /* Look up the variable. */
- /* Let getwinvar({nr}, "") return the "w:" dictionary. */
- v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE);
- if (v != NULL) {
- copy_tv(&v->di_tv, rettv);
- done = TRUE;
+ if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) {
+ if (*varname == '&') { /* window-local-option */
+ if (get_option_tv(&varname, rettv, 1) == OK)
+ done = true;
+ } else {
+ // Look up the variable.
+ // Let getwinvar({nr}, "") return the "w:" dictionary.
+ v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE);
+ if (v != NULL) {
+ copy_tv(&v->di_tv, rettv);
+ done = true;
+ }
}
}
@@ -13494,10 +13494,8 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
varname = get_tv_string_chk(&argvars[off + 1]);
varp = &argvars[off + 2];
- if (win != NULL && varname != NULL && varp != NULL) {
- if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == FAIL)
- return;
-
+ if (win != NULL && varname != NULL && varp != NULL
+ && switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) {
if (*varname == '&') {
long numval;
char_u *strval;
@@ -13515,7 +13513,6 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
set_var(winvarname, varp, TRUE);
free(winvarname);
}
-
restore_win(save_curwin, save_curtab, TRUE);
}
}
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index a2274a25fe..c954ab3c7b 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -489,7 +489,8 @@ void free_all_mem(void)
return;
entered = true;
- block_autocmds(); /* don't want to trigger autocommands here */
+ // Don't want to trigger autocommands from here on.
+ block_autocmds();
/* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */
p_ea = FALSE;
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 5e3331317d..bb988a1012 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -299,7 +299,7 @@ static int included_patches[] = {
449,
//448 NA
447,
- //446,
+ 446,
//445,
444,
//443 NA
diff --git a/src/nvim/window.c b/src/nvim/window.c
index cf0977e280..52a1853f4b 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1024,7 +1024,7 @@ static void win_init(win_T *newp, win_T *oldp, int flags)
}
/*
- * Initialize window "newp" from window"old".
+ * Initialize window "newp" from window "old".
* Only the essential things are copied.
*/
static void win_init_some(win_T *newp, win_T *oldp)
@@ -5190,8 +5190,8 @@ static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr)
/*
* Set "win" to be the curwin and "tp" to be the current tab page.
- * restore_win() MUST be called to undo.
- * No autocommands will be executed.
+ * restore_win() MUST be called to undo, also when FAIL is returned.
+ * No autocommands will be executed until restore_win() is called.
* When "no_display" is TRUE the display won't be affected, no redraw is
* triggered, another tabpage access is limited.
* Returns FAIL if switching to "win" failed.
@@ -5212,7 +5212,6 @@ int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage
goto_tabpage_tp(tp, FALSE, FALSE);
}
if (!win_valid(win)) {
- unblock_autocmds();
return FAIL;
}
curwin = win;