Karsten Hopp 31422c
To: vim_dev@googlegroups.com
Karsten Hopp 31422c
Subject: Patch 7.3.528
Karsten Hopp 31422c
Fcc: outbox
Karsten Hopp 31422c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 31422c
Mime-Version: 1.0
Karsten Hopp 31422c
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 31422c
Content-Transfer-Encoding: 8bit
Karsten Hopp 31422c
------------
Karsten Hopp 31422c
Karsten Hopp 31422c
Patch 7.3.528
Karsten Hopp 31422c
Problem:    Crash when closing last window in a tab. (Alex Efros)
Karsten Hopp 31422c
Solution:   Use common code in close_last_window_tabpage(). (Christian
Karsten Hopp 31422c
	    Brabandt)
Karsten Hopp 31422c
Files:	    src/window.c
Karsten Hopp 31422c
Karsten Hopp 31422c
Karsten Hopp 31422c
*** ../vim-7.3.527/src/window.c	2012-03-16 19:07:54.000000000 +0100
Karsten Hopp 31422c
--- src/window.c	2012-05-25 12:25:16.000000000 +0200
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 23,28 ****
Karsten Hopp 31422c
--- 23,29 ----
Karsten Hopp 31422c
  static void win_totop __ARGS((int size, int flags));
Karsten Hopp 31422c
  static void win_equal_rec __ARGS((win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height));
Karsten Hopp 31422c
  static int last_window __ARGS((void));
Karsten Hopp 31422c
+ static int close_last_window_tabpage __ARGS((win_T *win, int free_buf, tabpage_T *prev_curtab));
Karsten Hopp 31422c
  static win_T *win_free_mem __ARGS((win_T *win, int *dirp, tabpage_T *tp));
Karsten Hopp 31422c
  static frame_T *win_altframe __ARGS((win_T *win, tabpage_T *tp));
Karsten Hopp 31422c
  static tabpage_T *alt_tabpage __ARGS((void));
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 2105,2110 ****
Karsten Hopp 31422c
--- 2106,2147 ----
Karsten Hopp 31422c
  }
Karsten Hopp 31422c
  
Karsten Hopp 31422c
  /*
Karsten Hopp 31422c
+  * Close the possibly last window in a tab page.
Karsten Hopp 31422c
+  * Returns TRUE when the window was closed already.
Karsten Hopp 31422c
+  */
Karsten Hopp 31422c
+     static int
Karsten Hopp 31422c
+ close_last_window_tabpage(win, free_buf, prev_curtab)
Karsten Hopp 31422c
+     win_T	*win;
Karsten Hopp 31422c
+     int		free_buf;
Karsten Hopp 31422c
+     tabpage_T   *prev_curtab;
Karsten Hopp 31422c
+ {
Karsten Hopp 31422c
+     if (firstwin == lastwin)
Karsten Hopp 31422c
+     {
Karsten Hopp 31422c
+ 	/*
Karsten Hopp 31422c
+ 	 * Closing the last window in a tab page.  First go to another tab
Karsten Hopp 31422c
+ 	 * page and then close the window and the tab page.  This avoids that
Karsten Hopp 31422c
+ 	 * curwin and curtab are invalid while we are freeing memory, they may
Karsten Hopp 31422c
+ 	 * be used in GUI events.
Karsten Hopp 31422c
+ 	 */
Karsten Hopp 31422c
+ 	goto_tabpage_tp(alt_tabpage());
Karsten Hopp 31422c
+ 	redraw_tabline = TRUE;
Karsten Hopp 31422c
+ 
Karsten Hopp 31422c
+ 	/* Safety check: Autocommands may have closed the window when jumping
Karsten Hopp 31422c
+ 	 * to the other tab page. */
Karsten Hopp 31422c
+ 	if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
Karsten Hopp 31422c
+ 	{
Karsten Hopp 31422c
+ 	    int	    h = tabline_height();
Karsten Hopp 31422c
+ 
Karsten Hopp 31422c
+ 	    win_close_othertab(win, free_buf, prev_curtab);
Karsten Hopp 31422c
+ 	    if (h != tabline_height())
Karsten Hopp 31422c
+ 		shell_new_rows();
Karsten Hopp 31422c
+ 	}
Karsten Hopp 31422c
+ 	return TRUE;
Karsten Hopp 31422c
+     }
Karsten Hopp 31422c
+     return FALSE;
Karsten Hopp 31422c
+ }
Karsten Hopp 31422c
+ 
Karsten Hopp 31422c
+ /*
Karsten Hopp 31422c
   * Close window "win".  Only works for the current tab page.
Karsten Hopp 31422c
   * If "free_buf" is TRUE related buffer may be unloaded.
Karsten Hopp 31422c
   *
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 2143,2171 ****
Karsten Hopp 31422c
      }
Karsten Hopp 31422c
  #endif
Karsten Hopp 31422c
  
Karsten Hopp 31422c
!     /*
Karsten Hopp 31422c
!      * When closing the last window in a tab page first go to another tab
Karsten Hopp 31422c
!      * page and then close the window and the tab page.  This avoids that
Karsten Hopp 31422c
!      * curwin and curtab are not invalid while we are freeing memory, they may
Karsten Hopp 31422c
!      * be used in GUI events.
Karsten Hopp 31422c
!      */
Karsten Hopp 31422c
!     if (firstwin == lastwin)
Karsten Hopp 31422c
!     {
Karsten Hopp 31422c
! 	goto_tabpage_tp(alt_tabpage());
Karsten Hopp 31422c
! 	redraw_tabline = TRUE;
Karsten Hopp 31422c
! 
Karsten Hopp 31422c
! 	/* Safety check: Autocommands may have closed the window when jumping
Karsten Hopp 31422c
! 	 * to the other tab page. */
Karsten Hopp 31422c
! 	if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
Karsten Hopp 31422c
! 	{
Karsten Hopp 31422c
! 	    int	    h = tabline_height();
Karsten Hopp 31422c
! 
Karsten Hopp 31422c
! 	    win_close_othertab(win, free_buf, prev_curtab);
Karsten Hopp 31422c
! 	    if (h != tabline_height())
Karsten Hopp 31422c
! 		shell_new_rows();
Karsten Hopp 31422c
! 	}
Karsten Hopp 31422c
! 	return;
Karsten Hopp 31422c
!     }
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* When closing the help window, try restoring a snapshot after closing
Karsten Hopp 31422c
       * the window.  Otherwise clear the snapshot, it's now invalid. */
Karsten Hopp 31422c
--- 2180,2190 ----
Karsten Hopp 31422c
      }
Karsten Hopp 31422c
  #endif
Karsten Hopp 31422c
  
Karsten Hopp 31422c
!     /* When closing the last window in a tab page first go to another tab page
Karsten Hopp 31422c
!      * and then close the window and the tab page to avoid that curwin and
Karsten Hopp 31422c
!      * curtab are invalid while we are freeing memory. */
Karsten Hopp 31422c
!     if (close_last_window_tabpage(win, free_buf, prev_curtab))
Karsten Hopp 31422c
!       return;
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* When closing the help window, try restoring a snapshot after closing
Karsten Hopp 31422c
       * the window.  Otherwise clear the snapshot, it's now invalid. */
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 2225,2231 ****
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* Autocommands may have closed the window already, or closed the only
Karsten Hopp 31422c
       * other window or moved to another tab page. */
Karsten Hopp 31422c
!     if (!win_valid(win) || last_window() || curtab != prev_curtab)
Karsten Hopp 31422c
  	return;
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* Free the memory used for the window and get the window that received
Karsten Hopp 31422c
--- 2244,2251 ----
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* Autocommands may have closed the window already, or closed the only
Karsten Hopp 31422c
       * other window or moved to another tab page. */
Karsten Hopp 31422c
!     if (!win_valid(win) || last_window() || curtab != prev_curtab
Karsten Hopp 31422c
! 	    || close_last_window_tabpage(win, free_buf, prev_curtab))
Karsten Hopp 31422c
  	return;
Karsten Hopp 31422c
  
Karsten Hopp 31422c
      /* Free the memory used for the window and get the window that received
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 2310,2316 ****
Karsten Hopp 31422c
  
Karsten Hopp 31422c
  /*
Karsten Hopp 31422c
   * Close window "win" in tab page "tp", which is not the current tab page.
Karsten Hopp 31422c
!  * This may be the last window ih that tab page and result in closing the tab,
Karsten Hopp 31422c
   * thus "tp" may become invalid!
Karsten Hopp 31422c
   * Caller must check if buffer is hidden and whether the tabline needs to be
Karsten Hopp 31422c
   * updated.
Karsten Hopp 31422c
--- 2330,2336 ----
Karsten Hopp 31422c
  
Karsten Hopp 31422c
  /*
Karsten Hopp 31422c
   * Close window "win" in tab page "tp", which is not the current tab page.
Karsten Hopp 31422c
!  * This may be the last window in that tab page and result in closing the tab,
Karsten Hopp 31422c
   * thus "tp" may become invalid!
Karsten Hopp 31422c
   * Caller must check if buffer is hidden and whether the tabline needs to be
Karsten Hopp 31422c
   * updated.
Karsten Hopp 31422c
*** ../vim-7.3.527/src/version.c	2012-05-25 11:56:06.000000000 +0200
Karsten Hopp 31422c
--- src/version.c	2012-05-25 12:38:25.000000000 +0200
Karsten Hopp 31422c
***************
Karsten Hopp 31422c
*** 716,717 ****
Karsten Hopp 31422c
--- 716,719 ----
Karsten Hopp 31422c
  {   /* Add new patch number below this line */
Karsten Hopp 31422c
+ /**/
Karsten Hopp 31422c
+     528,
Karsten Hopp 31422c
  /**/
Karsten Hopp 31422c
Karsten Hopp 31422c
-- 
Karsten Hopp 31422c
For society, it's probably a good thing that engineers value function over
Karsten Hopp 31422c
appearance.  For example, you wouldn't want engineers to build nuclear power
Karsten Hopp 31422c
plants that only _look_ like they would keep all the radiation inside.
Karsten Hopp 31422c
				(Scott Adams - The Dilbert principle)
Karsten Hopp 31422c
Karsten Hopp 31422c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 31422c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 31422c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 31422c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///