components/vim/vim72-patches/7.2.445
changeset 198 172fc01ce997
equal deleted inserted replaced
197:fd801ec0737c 198:172fc01ce997
       
     1 To: [email protected]
       
     2 Subject: Patch 7.2.445
       
     3 Fcc: outbox
       
     4 From: Bram Moolenaar <[email protected]>
       
     5 Mime-Version: 1.0
       
     6 Content-Type: text/plain; charset=UTF-8
       
     7 Content-Transfer-Encoding: 8bit
       
     8 ------------
       
     9 
       
    10 Patch 7.2.445
       
    11 Problem:    Crash when using undo/redo and a FileChangedRO autocmd event that
       
    12 	    reloads the buffer. (Dominique Pelle)
       
    13 Solution:   Do not allow autocommands while performing and undo or redo.
       
    14 Files:	    src/misc1.c, src/undo.c
       
    15 
       
    16 
       
    17 *** ../vim-7.2.444/src/misc1.c	2010-03-23 18:22:40.000000000 +0100
       
    18 --- src/misc1.c	2010-07-07 18:18:52.000000000 +0200
       
    19 ***************
       
    20 *** 2467,2476 ****
       
    21   }
       
    22   
       
    23   /*
       
    24 !  * changed() is called when something in the current buffer is changed.
       
    25    *
       
    26    * Most often called through changed_bytes() and changed_lines(), which also
       
    27    * mark the area of the display to be redrawn.
       
    28    */
       
    29       void
       
    30   changed()
       
    31 --- 2467,2478 ----
       
    32   }
       
    33   
       
    34   /*
       
    35 !  * Call this function when something in the current buffer is changed.
       
    36    *
       
    37    * Most often called through changed_bytes() and changed_lines(), which also
       
    38    * mark the area of the display to be redrawn.
       
    39 +  *
       
    40 +  * Careful: may trigger autocommands that reload the buffer.
       
    41    */
       
    42       void
       
    43   changed()
       
    44 ***************
       
    45 *** 2536,2541 ****
       
    46 --- 2538,2544 ----
       
    47    * - marks the windows on this buffer to be redisplayed
       
    48    * - marks the buffer changed by calling changed()
       
    49    * - invalidates cached values
       
    50 +  * Careful: may trigger autocommands that reload the buffer.
       
    51    */
       
    52       void
       
    53   changed_bytes(lnum, col)
       
    54 ***************
       
    55 *** 2649,2654 ****
       
    56 --- 2652,2658 ----
       
    57    * below the changed lines (BEFORE the change).
       
    58    * When only inserting lines, "lnum" and "lnume" are equal.
       
    59    * Takes care of calling changed() and updating b_mod_*.
       
    60 +  * Careful: may trigger autocommands that reload the buffer.
       
    61    */
       
    62       void
       
    63   changed_lines(lnum, col, lnume, xtra)
       
    64 ***************
       
    65 *** 2716,2721 ****
       
    66 --- 2720,2730 ----
       
    67       }
       
    68   }
       
    69   
       
    70 + /*
       
    71 +  * Common code for when a change is was made.
       
    72 +  * See changed_lines() for the arguments.
       
    73 +  * Careful: may trigger autocommands that reload the buffer.
       
    74 +  */
       
    75       static void
       
    76   changed_common(lnum, col, lnume, xtra)
       
    77       linenr_T	lnum;
       
    78 ***************
       
    79 *** 2966,2971 ****
       
    80 --- 2975,2981 ----
       
    81    * Don't use emsg(), because it flushes the macro buffer.
       
    82    * If we have undone all changes b_changed will be FALSE, but "b_did_warn"
       
    83    * will be TRUE.
       
    84 +  * Careful: may trigger autocommands that reload the buffer.
       
    85    */
       
    86       void
       
    87   change_warning(col)
       
    88 *** ../vim-7.2.444/src/undo.c	2010-05-30 16:55:17.000000000 +0200
       
    89 --- src/undo.c	2010-07-07 18:14:44.000000000 +0200
       
    90 ***************
       
    91 *** 185,191 ****
       
    92       }
       
    93   }
       
    94   
       
    95 !     void
       
    96   u_check(int newhead_may_be_NULL)
       
    97   {
       
    98       seen_b_u_newhead = 0;
       
    99 --- 185,191 ----
       
   100       }
       
   101   }
       
   102   
       
   103 !     static void
       
   104   u_check(int newhead_may_be_NULL)
       
   105   {
       
   106       seen_b_u_newhead = 0;
       
   107 ***************
       
   108 *** 320,325 ****
       
   109 --- 320,328 ----
       
   110       return TRUE;
       
   111   }
       
   112   
       
   113 + /*
       
   114 +  * Common code for various ways to save text before a change.
       
   115 +  */
       
   116       static int
       
   117   u_savecommon(top, bot, newbot)
       
   118       linenr_T	top, bot;
       
   119 ***************
       
   120 *** 374,380 ****
       
   121       size = bot - top - 1;
       
   122   
       
   123       /*
       
   124 !      * if curbuf->b_u_synced == TRUE make a new header
       
   125        */
       
   126       if (curbuf->b_u_synced)
       
   127       {
       
   128 --- 377,383 ----
       
   129       size = bot - top - 1;
       
   130   
       
   131       /*
       
   132 !      * If curbuf->b_u_synced == TRUE make a new header.
       
   133        */
       
   134       if (curbuf->b_u_synced)
       
   135       {
       
   136 ***************
       
   137 *** 709,714 ****
       
   138 --- 712,723 ----
       
   139   	u_oldcount = -1;
       
   140       while (count--)
       
   141       {
       
   142 + 	/* Do the change warning now, so that it triggers FileChangedRO when
       
   143 + 	 * needed.  This may cause the file to be reloaded, that must happen
       
   144 + 	 * before we do anything, because it may change curbuf->b_u_curhead
       
   145 + 	 * and more. */
       
   146 + 	change_warning(0);
       
   147 + 
       
   148   	if (undo_undoes)
       
   149   	{
       
   150   	    if (curbuf->b_u_curhead == NULL)		/* first undo */
       
   151 ***************
       
   152 *** 952,959 ****
       
   153   	/*
       
   154   	 * First go up the tree as much as needed.
       
   155   	 */
       
   156 ! 	for (;;)
       
   157   	{
       
   158   	    uhp = curbuf->b_u_curhead;
       
   159   	    if (uhp == NULL)
       
   160   		uhp = curbuf->b_u_newhead;
       
   161 --- 961,971 ----
       
   162   	/*
       
   163   	 * First go up the tree as much as needed.
       
   164   	 */
       
   165 ! 	while (!got_int)
       
   166   	{
       
   167 + 	    /* Do the change warning now, for the same reason as above. */
       
   168 + 	    change_warning(0);
       
   169 + 
       
   170   	    uhp = curbuf->b_u_curhead;
       
   171   	    if (uhp == NULL)
       
   172   		uhp = curbuf->b_u_newhead;
       
   173 ***************
       
   174 *** 970,978 ****
       
   175   	/*
       
   176   	 * And now go down the tree (redo), branching off where needed.
       
   177   	 */
       
   178 ! 	uhp = curbuf->b_u_curhead;
       
   179 ! 	while (uhp != NULL)
       
   180   	{
       
   181   	    /* Go back to the first branch with a mark. */
       
   182   	    while (uhp->uh_alt_prev != NULL
       
   183   					&& uhp->uh_alt_prev->uh_walk == mark)
       
   184 --- 982,996 ----
       
   185   	/*
       
   186   	 * And now go down the tree (redo), branching off where needed.
       
   187   	 */
       
   188 ! 	while (!got_int)
       
   189   	{
       
   190 + 	    /* Do the change warning now, for the same reason as above. */
       
   191 + 	    change_warning(0);
       
   192 + 
       
   193 + 	    uhp = curbuf->b_u_curhead;
       
   194 + 	    if (uhp == NULL)
       
   195 + 		break;
       
   196 + 
       
   197   	    /* Go back to the first branch with a mark. */
       
   198   	    while (uhp->uh_alt_prev != NULL
       
   199   					&& uhp->uh_alt_prev->uh_walk == mark)
       
   200 ***************
       
   201 *** 1070,1075 ****
       
   202 --- 1088,1099 ----
       
   203       int		empty_buffer;		    /* buffer became empty */
       
   204       u_header_T	*curhead = curbuf->b_u_curhead;
       
   205   
       
   206 + #ifdef FEAT_AUTOCMD
       
   207 +     /* Don't want autocommands using the undo structures here, they are
       
   208 +      * invalid till the end. */
       
   209 +     block_autocmds();
       
   210 + #endif
       
   211 + 
       
   212   #ifdef U_DEBUG
       
   213       u_check(FALSE);
       
   214   #endif
       
   215 ***************
       
   216 *** 1099,1104 ****
       
   217 --- 1123,1131 ----
       
   218   	if (top > curbuf->b_ml.ml_line_count || top >= bot
       
   219   				      || bot > curbuf->b_ml.ml_line_count + 1)
       
   220   	{
       
   221 + #ifdef FEAT_AUTOCMD
       
   222 + 	    unblock_autocmds();
       
   223 + #endif
       
   224   	    EMSG(_("E438: u_undo: line numbers wrong"));
       
   225   	    changed();		/* don't want UNCHANGED now */
       
   226   	    return;
       
   227 ***************
       
   228 *** 1304,1309 ****
       
   229 --- 1331,1340 ----
       
   230       /* The timestamp can be the same for multiple changes, just use the one of
       
   231        * the undone/redone change. */
       
   232       curbuf->b_u_seq_time = curhead->uh_time;
       
   233 + 
       
   234 + #ifdef FEAT_AUTOCMD
       
   235 +     unblock_autocmds();
       
   236 + #endif
       
   237   #ifdef U_DEBUG
       
   238       u_check(FALSE);
       
   239   #endif
       
   240 *** ../vim-7.2.444/src/version.c	2010-06-13 02:35:41.000000000 +0200
       
   241 --- src/version.c	2010-07-07 18:18:27.000000000 +0200
       
   242 ***************
       
   243 *** 683,684 ****
       
   244 --- 683,686 ----
       
   245   {   /* Add new patch number below this line */
       
   246 + /**/
       
   247 +     445,
       
   248   /**/
       
   249 
       
   250 -- 
       
   251     A KNIGHT rides into shot and hacks him to the ground.  He rides off.
       
   252     We stay for a moment on the glade.  A MIDDLE-AGED LADY in a C. & A.
       
   253     twin-set emerges from the trees and looks in horror at the body of her
       
   254     HUSBAND.
       
   255 MRS HISTORIAN: FRANK!
       
   256                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
       
   257 
       
   258  /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
       
   259 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
       
   260 \\\        download, build and distribute -- http://www.A-A-P.org        ///
       
   261  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///