073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.446
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.446
073263
Problem:    In some situations, when setting up an environment to trigger an
073263
	    autocommand, the environment is not properly restored.
073263
Solution:   Check the return value of switch_win() and call restore_win()
073263
	    always.  (Daniel Hahler)
073263
Files:	    src/eval.c, src/misc2.c, src/window.c
073263
073263
073263
*** ../vim-7.4.445/src/eval.c	2014-09-09 23:11:46.368586569 +0200
073263
--- src/eval.c	2014-09-19 14:09:27.238402767 +0200
073263
***************
073263
*** 12086,12100 ****
073263
      {
073263
  	/* Set tp to be our tabpage, temporarily.  Also set the window to the
073263
  	 * first window in the tabpage, otherwise the window is not valid. */
073263
! 	switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE);
073263
! 
073263
! 	/* look up the variable */
073263
! 	/* Let gettabvar({nr}, "") return the "t:" dictionary. */
073263
! 	v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE);
073263
! 	if (v != NULL)
073263
  	{
073263
! 	    copy_tv(&v->di_tv, rettv);
073263
! 	    done = TRUE;
073263
  	}
073263
  
073263
  	/* restore previous notion of curwin */
073263
--- 12086,12102 ----
073263
      {
073263
  	/* Set tp to be our tabpage, temporarily.  Also set the window to the
073263
  	 * first window in the tabpage, otherwise the window is not valid. */
073263
! 	if (switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE)
073263
! 									== OK)
073263
  	{
073263
! 	    /* look up the variable */
073263
! 	    /* Let gettabvar({nr}, "") return the "t:" dictionary. */
073263
! 	    v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE);
073263
! 	    if (v != NULL)
073263
! 	    {
073263
! 		copy_tv(&v->di_tv, rettv);
073263
! 		done = TRUE;
073263
! 	    }
073263
  	}
073263
  
073263
  	/* restore previous notion of curwin */
073263
***************
073263
*** 12233,12254 ****
073263
      {
073263
  	/* Set curwin to be our win, temporarily.  Also set the tabpage,
073263
  	 * otherwise the window is not valid. */
073263
! 	switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE);
073263
! 
073263
! 	if (*varname == '&')	/* window-local-option */
073263
! 	{
073263
! 	    if (get_option_tv(&varname, rettv, 1) == OK)
073263
! 		done = TRUE;
073263
! 	}
073263
! 	else
073263
  	{
073263
! 	    /* Look up the variable. */
073263
! 	    /* Let getwinvar({nr}, "") return the "w:" dictionary. */
073263
! 	    v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE);
073263
! 	    if (v != NULL)
073263
  	    {
073263
! 		copy_tv(&v->di_tv, rettv);
073263
! 		done = TRUE;
073263
  	    }
073263
  	}
073263
  
073263
--- 12235,12258 ----
073263
      {
073263
  	/* Set curwin to be our win, temporarily.  Also set the tabpage,
073263
  	 * otherwise the window is not valid. */
073263
! 	if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK)
073263
  	{
073263
! 	    if (*varname == '&')	/* window-local-option */
073263
  	    {
073263
! 		if (get_option_tv(&varname, rettv, 1) == OK)
073263
! 		    done = TRUE;
073263
! 	    }
073263
! 	    else
073263
! 	    {
073263
! 		/* Look up the variable. */
073263
! 		/* Let getwinvar({nr}, "") return the "w:" dictionary. */
073263
! 		v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w',
073263
! 							      varname, FALSE);
073263
! 		if (v != NULL)
073263
! 		{
073263
! 		    copy_tv(&v->di_tv, rettv);
073263
! 		    done = TRUE;
073263
! 		}
073263
  	    }
073263
  	}
073263
  
073263
***************
073263
*** 17252,17285 ****
073263
      if (win != NULL && varname != NULL && varp != NULL)
073263
      {
073263
  #ifdef FEAT_WINDOWS
073263
! 	if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == FAIL)
073263
! 	    return;
073263
  #endif
073263
- 
073263
- 	if (*varname == '&')
073263
  	{
073263
! 	    long	numval;
073263
! 	    char_u	*strval;
073263
! 	    int		error = FALSE;
073263
  
073263
! 	    ++varname;
073263
! 	    numval = get_tv_number_chk(varp, &error);
073263
! 	    strval = get_tv_string_buf_chk(varp, nbuf);
073263
! 	    if (!error && strval != NULL)
073263
! 		set_option_value(varname, numval, strval, OPT_LOCAL);
073263
! 	}
073263
! 	else
073263
! 	{
073263
! 	    winvarname = alloc((unsigned)STRLEN(varname) + 3);
073263
! 	    if (winvarname != NULL)
073263
  	    {
073263
! 		STRCPY(winvarname, "w:");
073263
! 		STRCPY(winvarname + 2, varname);
073263
! 		set_var(winvarname, varp, TRUE);
073263
! 		vim_free(winvarname);
073263
  	    }
073263
  	}
073263
- 
073263
  #ifdef FEAT_WINDOWS
073263
  	restore_win(save_curwin, save_curtab, TRUE);
073263
  #endif
073263
--- 17256,17288 ----
073263
      if (win != NULL && varname != NULL && varp != NULL)
073263
      {
073263
  #ifdef FEAT_WINDOWS
073263
! 	if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
073263
  #endif
073263
  	{
073263
! 	    if (*varname == '&')
073263
! 	    {
073263
! 		long	numval;
073263
! 		char_u	*strval;
073263
! 		int		error = FALSE;
073263
  
073263
! 		++varname;
073263
! 		numval = get_tv_number_chk(varp, &error);
073263
! 		strval = get_tv_string_buf_chk(varp, nbuf);
073263
! 		if (!error && strval != NULL)
073263
! 		    set_option_value(varname, numval, strval, OPT_LOCAL);
073263
! 	    }
073263
! 	    else
073263
  	    {
073263
! 		winvarname = alloc((unsigned)STRLEN(varname) + 3);
073263
! 		if (winvarname != NULL)
073263
! 		{
073263
! 		    STRCPY(winvarname, "w:");
073263
! 		    STRCPY(winvarname + 2, varname);
073263
! 		    set_var(winvarname, varp, TRUE);
073263
! 		    vim_free(winvarname);
073263
! 		}
073263
  	    }
073263
  	}
073263
  #ifdef FEAT_WINDOWS
073263
  	restore_win(save_curwin, save_curtab, TRUE);
073263
  #endif
073263
*** ../vim-7.4.445/src/misc2.c	2014-08-10 13:34:59.060785459 +0200
073263
--- src/misc2.c	2014-09-19 14:03:24.314401974 +0200
073263
***************
073263
*** 1040,1046 ****
073263
      entered = TRUE;
073263
  
073263
  # ifdef FEAT_AUTOCMD
073263
!     block_autocmds();	    /* don't want to trigger autocommands here */
073263
  # endif
073263
  
073263
  # ifdef FEAT_WINDOWS
073263
--- 1040,1047 ----
073263
      entered = TRUE;
073263
  
073263
  # ifdef FEAT_AUTOCMD
073263
!     /* Don't want to trigger autocommands from here on. */
073263
!     block_autocmds();
073263
  # endif
073263
  
073263
  # ifdef FEAT_WINDOWS
073263
*** ../vim-7.4.445/src/window.c	2014-07-30 14:04:49.131603494 +0200
073263
--- src/window.c	2014-09-19 14:06:52.538402429 +0200
073263
***************
073263
*** 1271,1277 ****
073263
  }
073263
  
073263
  /*
073263
!  * Initialize window "newp" from window"old".
073263
   * Only the essential things are copied.
073263
   */
073263
      static void
073263
--- 1271,1277 ----
073263
  }
073263
  
073263
  /*
073263
!  * Initialize window "newp" from window "old".
073263
   * Only the essential things are copied.
073263
   */
073263
      static void
073263
***************
073263
*** 6662,6669 ****
073263
  	|| defined(PROTO)
073263
  /*
073263
   * Set "win" to be the curwin and "tp" to be the current tab page.
073263
!  * restore_win() MUST be called to undo.
073263
!  * No autocommands will be executed.
073263
   * When "no_display" is TRUE the display won't be affected, no redraw is
073263
   * triggered, another tabpage access is limited.
073263
   * Returns FAIL if switching to "win" failed.
073263
--- 6662,6669 ----
073263
  	|| defined(PROTO)
073263
  /*
073263
   * Set "win" to be the curwin and "tp" to be the current tab page.
073263
!  * restore_win() MUST be called to undo, also when FAIL is returned.
073263
!  * No autocommands will be executed until restore_win() is called.
073263
   * When "no_display" is TRUE the display won't be affected, no redraw is
073263
   * triggered, another tabpage access is limited.
073263
   * Returns FAIL if switching to "win" failed.
073263
***************
073263
*** 6696,6707 ****
073263
  	    goto_tabpage_tp(tp, FALSE, FALSE);
073263
      }
073263
      if (!win_valid(win))
073263
-     {
073263
- # ifdef FEAT_AUTOCMD
073263
- 	unblock_autocmds();
073263
- # endif
073263
  	return FAIL;
073263
-     }
073263
      curwin = win;
073263
      curbuf = curwin->w_buffer;
073263
  # endif
073263
--- 6696,6702 ----
073263
*** ../vim-7.4.445/src/version.c	2014-09-19 13:46:49.550399801 +0200
073263
--- src/version.c	2014-09-19 14:25:34.674404880 +0200
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     446,
073263
  /**/
073263
073263
-- 
073263
hundred-and-one symptoms of being an internet addict:
073263
160. You get in the elevator and double-click the button for the floor
073263
     you want.
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///