Karsten Hopp c29414
To: vim-dev@vim.org
Karsten Hopp c29414
Subject: patch 7.0.192
Karsten Hopp c29414
Fcc: outbox
Karsten Hopp c29414
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp c29414
Mime-Version: 1.0
Karsten Hopp c29414
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp c29414
Content-Transfer-Encoding: 8bit
Karsten Hopp c29414
------------
Karsten Hopp c29414
Karsten Hopp c29414
Patch 7.0.192
Karsten Hopp c29414
Problem:    When 'swapfile' is switched off in an empty file it is possible
Karsten Hopp c29414
            that not all blocks are loaded into memory, causing ml_get errors
Karsten Hopp c29414
            later.
Karsten Hopp c29414
Solution:   Rename "dont_release" to "mf_dont_release" and also use it to
Karsten Hopp c29414
            avoid using the cached line and locked block. 
Karsten Hopp c29414
Files:      src/globals.h, src/memfile.c, src/memline.c
Karsten Hopp c29414
Karsten Hopp c29414
Karsten Hopp c29414
*** ../vim-7.0.191/src/globals.h	Tue Jan  9 15:15:36 2007
Karsten Hopp c29414
--- src/globals.h	Wed Feb  7 03:29:52 2007
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 554,559 ****
Karsten Hopp c29414
--- 554,563 ----
Karsten Hopp c29414
  EXTERN buf_T	*firstbuf INIT(= NULL);	/* first buffer */
Karsten Hopp c29414
  EXTERN buf_T	*lastbuf INIT(= NULL);	/* last buffer */
Karsten Hopp c29414
  EXTERN buf_T	*curbuf INIT(= NULL);	/* currently active buffer */
Karsten Hopp c29414
+ 
Karsten Hopp c29414
+ /* Flag that is set when switching off 'swapfile'.  It means that all blocks
Karsten Hopp c29414
+  * are to be loaded into memory.  Shouldn't be global... */
Karsten Hopp c29414
+ EXTERN int	mf_dont_release INIT(= FALSE);	/* don't release blocks */
Karsten Hopp c29414
  
Karsten Hopp c29414
  /*
Karsten Hopp c29414
   * List of files being edited (global argument list).  curwin->w_alist points
Karsten Hopp c29414
*** ../vim-7.0.191/src/memfile.c	Tue Nov  7 18:02:19 2006
Karsten Hopp c29414
--- src/memfile.c	Wed Feb  7 03:22:11 2007
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 76,82 ****
Karsten Hopp c29414
  #define MEMFILE_PAGE_SIZE 4096		/* default page size */
Karsten Hopp c29414
  
Karsten Hopp c29414
  static long_u	total_mem_used = 0;	/* total memory used for memfiles */
Karsten Hopp c29414
- static int	dont_release = FALSE;	/* don't release blocks */
Karsten Hopp c29414
  
Karsten Hopp c29414
  static void mf_ins_hash __ARGS((memfile_T *, bhdr_T *));
Karsten Hopp c29414
  static void mf_rem_hash __ARGS((memfile_T *, bhdr_T *));
Karsten Hopp c29414
--- 76,81 ----
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 279,288 ****
Karsten Hopp c29414
      if (getlines)
Karsten Hopp c29414
      {
Karsten Hopp c29414
  	/* get all blocks in memory by accessing all lines (clumsy!) */
Karsten Hopp c29414
! 	dont_release = TRUE;
Karsten Hopp c29414
  	for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
Karsten Hopp c29414
  	    (void)ml_get_buf(buf, lnum, FALSE);
Karsten Hopp c29414
! 	dont_release = FALSE;
Karsten Hopp c29414
  	/* TODO: should check if all blocks are really in core */
Karsten Hopp c29414
      }
Karsten Hopp c29414
  
Karsten Hopp c29414
--- 278,287 ----
Karsten Hopp c29414
      if (getlines)
Karsten Hopp c29414
      {
Karsten Hopp c29414
  	/* get all blocks in memory by accessing all lines (clumsy!) */
Karsten Hopp c29414
! 	mf_dont_release = TRUE;
Karsten Hopp c29414
  	for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
Karsten Hopp c29414
  	    (void)ml_get_buf(buf, lnum, FALSE);
Karsten Hopp c29414
! 	mf_dont_release = FALSE;
Karsten Hopp c29414
  	/* TODO: should check if all blocks are really in core */
Karsten Hopp c29414
      }
Karsten Hopp c29414
  
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 830,836 ****
Karsten Hopp c29414
      buf_T	*buf;
Karsten Hopp c29414
  
Karsten Hopp c29414
      /* don't release while in mf_close_file() */
Karsten Hopp c29414
!     if (dont_release)
Karsten Hopp c29414
  	return NULL;
Karsten Hopp c29414
  
Karsten Hopp c29414
      /*
Karsten Hopp c29414
--- 829,835 ----
Karsten Hopp c29414
      buf_T	*buf;
Karsten Hopp c29414
  
Karsten Hopp c29414
      /* don't release while in mf_close_file() */
Karsten Hopp c29414
!     if (mf_dont_release)
Karsten Hopp c29414
  	return NULL;
Karsten Hopp c29414
  
Karsten Hopp c29414
      /*
Karsten Hopp c29414
*** ../vim-7.0.191/src/memline.c	Tue Jan  9 15:15:36 2007
Karsten Hopp c29414
--- src/memline.c	Wed Feb  7 03:29:31 2007
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 2074,2081 ****
Karsten Hopp c29414
  /*
Karsten Hopp c29414
   * See if it is the same line as requested last time.
Karsten Hopp c29414
   * Otherwise may need to flush last used line.
Karsten Hopp c29414
   */
Karsten Hopp c29414
!     if (buf->b_ml.ml_line_lnum != lnum)
Karsten Hopp c29414
      {
Karsten Hopp c29414
  	ml_flush_line(buf);
Karsten Hopp c29414
  
Karsten Hopp c29414
--- 2074,2083 ----
Karsten Hopp c29414
  /*
Karsten Hopp c29414
   * See if it is the same line as requested last time.
Karsten Hopp c29414
   * Otherwise may need to flush last used line.
Karsten Hopp c29414
+  * Don't use the last used line when 'swapfile' is reset, need to load all
Karsten Hopp c29414
+  * blocks.
Karsten Hopp c29414
   */
Karsten Hopp c29414
!     if (buf->b_ml.ml_line_lnum != lnum || mf_dont_release)
Karsten Hopp c29414
      {
Karsten Hopp c29414
  	ml_flush_line(buf);
Karsten Hopp c29414
  
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 3200,3212 ****
Karsten Hopp c29414
       * If not, flush and release the locked block.
Karsten Hopp c29414
       * Don't do this for ML_INSERT_SAME, because the stack need to be updated.
Karsten Hopp c29414
       * Don't do this for ML_FLUSH, because we want to flush the locked block.
Karsten Hopp c29414
       */
Karsten Hopp c29414
      if (buf->b_ml.ml_locked)
Karsten Hopp c29414
      {
Karsten Hopp c29414
! 	if (ML_SIMPLE(action) && buf->b_ml.ml_locked_low <= lnum
Karsten Hopp c29414
! 					  && buf->b_ml.ml_locked_high >= lnum)
Karsten Hopp c29414
  	{
Karsten Hopp c29414
! 		/* remember to update pointer blocks and stack later */
Karsten Hopp c29414
  	    if (action == ML_INSERT)
Karsten Hopp c29414
  	    {
Karsten Hopp c29414
  		++(buf->b_ml.ml_locked_lineadd);
Karsten Hopp c29414
--- 3202,3217 ----
Karsten Hopp c29414
       * If not, flush and release the locked block.
Karsten Hopp c29414
       * Don't do this for ML_INSERT_SAME, because the stack need to be updated.
Karsten Hopp c29414
       * Don't do this for ML_FLUSH, because we want to flush the locked block.
Karsten Hopp c29414
+      * Don't do this when 'swapfile' is reset, we want to load all the blocks.
Karsten Hopp c29414
       */
Karsten Hopp c29414
      if (buf->b_ml.ml_locked)
Karsten Hopp c29414
      {
Karsten Hopp c29414
! 	if (ML_SIMPLE(action)
Karsten Hopp c29414
! 		&& buf->b_ml.ml_locked_low <= lnum
Karsten Hopp c29414
! 		&& buf->b_ml.ml_locked_high >= lnum
Karsten Hopp c29414
! 		&& !mf_dont_release)
Karsten Hopp c29414
  	{
Karsten Hopp c29414
! 	    /* remember to update pointer blocks and stack later */
Karsten Hopp c29414
  	    if (action == ML_INSERT)
Karsten Hopp c29414
  	    {
Karsten Hopp c29414
  		++(buf->b_ml.ml_locked_lineadd);
Karsten Hopp c29414
*** ../vim-7.0.191/src/version.c	Sun Feb  4 02:59:04 2007
Karsten Hopp c29414
--- src/version.c	Wed Feb  7 03:40:28 2007
Karsten Hopp c29414
***************
Karsten Hopp c29414
*** 668,669 ****
Karsten Hopp c29414
--- 668,671 ----
Karsten Hopp c29414
  {   /* Add new patch number below this line */
Karsten Hopp c29414
+ /**/
Karsten Hopp c29414
+     192,
Karsten Hopp c29414
  /**/
Karsten Hopp c29414
Karsten Hopp c29414
-- 
Karsten Hopp c29414
From "know your smileys":
Karsten Hopp c29414
 %-)	After staring at screen for 15 hours
Karsten Hopp c29414
Karsten Hopp c29414
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp c29414
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp c29414
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp c29414
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///