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