]> granicus.if.org Git - vim/commitdiff
patch 7.4.2021 v7.4.2021
authorBram Moolenaar <Bram@vim.org>
Sun, 10 Jul 2016 17:03:57 +0000 (19:03 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 10 Jul 2016 17:03:57 +0000 (19:03 +0200)
Problem:    Still too many buf_valid() calls.
Solution:   Make au_new_curbuf a bufref.  Use bufref_valid() in more places.

src/buffer.c
src/ex_cmds.c
src/globals.h
src/version.c

index 3507f94ca855de7e056ae48498824c58a8ea88e3..409564b96656af60e0173baf6344f7c7f78b38ba 100644 (file)
@@ -1293,7 +1293,7 @@ do_buffer(
         * Deleting the current buffer: Need to find another buffer to go to.
         * There should be another, otherwise it would have been handled
         * above.  However, autocommands may have deleted all buffers.
-        * First use au_new_curbuf, if it is valid.
+        * First use au_new_curbuf.br_buf, if it is valid.
         * Then prefer the buffer we most recently visited.
         * Else try to find one that is loaded, after the current buffer,
         * then before the current buffer.
@@ -1302,8 +1302,8 @@ do_buffer(
        buf = NULL;     /* selected buffer */
        bp = NULL;      /* used when no loaded buffer found */
 #ifdef FEAT_AUTOCMD
-       if (au_new_curbuf != NULL && buf_valid(au_new_curbuf))
-           buf = au_new_curbuf;
+       if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf))
+           buf = au_new_curbuf.br_buf;
 # ifdef FEAT_JUMPLIST
        else
 # endif
index d93a7ec7fcf476d3642f31d0f0747aefec4520e1..3e29d7689242f2414c9a8ce559f79ca7fdb9d7b9 100644 (file)
@@ -3447,11 +3447,16 @@ do_wqall(exarg_T *eap)
            }
            else
            {
+#ifdef FEAT_AUTOCMD
+               bufref_T bufref;
+
+               set_bufref(&bufref, buf);
+#endif
                if (buf_write_all(buf, eap->forceit) == FAIL)
                    ++error;
 #ifdef FEAT_AUTOCMD
                /* an autocommand may have deleted the buffer */
-               if (!buf_valid(buf))
+               if (!bufref_valid(&bufref))
                    buf = firstbuf;
 #endif
            }
@@ -3659,6 +3664,7 @@ do_ecmd(
     int                did_set_swapcommand = FALSE;
 #endif
     buf_T      *buf;
+    bufref_T   bufref;
 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
     buf_T      *old_curbuf = curbuf;
 #endif
@@ -3863,10 +3869,11 @@ do_ecmd(
        else                                    /* existing memfile */
        {
            oldbuf = TRUE;
+           set_bufref(&bufref, buf);
            (void)buf_check_timestamp(buf, FALSE);
            /* Check if autocommands made buffer invalid or changed the current
             * buffer. */
-           if (!buf_valid(buf)
+           if (!bufref_valid(&bufref)
 #ifdef FEAT_AUTOCMD
                    || curbuf != old_curbuf
 #endif
@@ -3908,10 +3915,11 @@ do_ecmd(
             */
            if (buf->b_fname != NULL)
                new_name = vim_strsave(buf->b_fname);
-           au_new_curbuf = buf;
+           set_bufref(&au_new_curbuf, buf);
            apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
-           if (!buf_valid(buf))        /* new buffer has been deleted */
+           if (!bufref_valid(&au_new_curbuf))
            {
+               /* new buffer has been deleted */
                delbuf_msg(new_name);   /* frees new_name */
                goto theend;
            }
@@ -3951,8 +3959,9 @@ do_ecmd(
                }
 # endif
                /* Be careful again, like above. */
-               if (!buf_valid(buf))    /* new buffer has been deleted */
+               if (!bufref_valid(&au_new_curbuf))
                {
+                   /* new buffer has been deleted */
                    delbuf_msg(new_name);       /* frees new_name */
                    goto theend;
                }
@@ -3995,7 +4004,7 @@ do_ecmd(
 #ifdef FEAT_AUTOCMD
            }
            vim_free(new_name);
-           au_new_curbuf = NULL;
+           au_new_curbuf.br_buf = NULL;
 #endif
        }
 
@@ -4071,6 +4080,7 @@ do_ecmd(
            new_name = vim_strsave(buf->b_fname);
        else
            new_name = NULL;
+       set_bufref(&bufref, buf);
 #endif
        if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur)
        {
@@ -4091,7 +4101,7 @@ do_ecmd(
 #ifdef FEAT_AUTOCMD
        /* If autocommands deleted the buffer we were going to re-edit, give
         * up and jump to the end. */
-       if (!buf_valid(buf))
+       if (!bufref_valid(&bufref))
        {
            delbuf_msg(new_name);       /* frees new_name */
            goto theend;
@@ -4375,7 +4385,7 @@ delbuf_msg(char_u *name)
     EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"),
            name == NULL ? (char_u *)"" : name);
     vim_free(name);
-    au_new_curbuf = NULL;
+    au_new_curbuf.br_buf = NULL;
 }
 #endif
 
index 879255cd5739a1b5987a6c0c0c2c593427022a08..566d6e13bb7bc58f15c4b4c754c4197d805bb7b1 100644 (file)
@@ -386,7 +386,7 @@ EXTERN int  keep_filetype INIT(= FALSE);    /* value for did_filetype when
 
 /* When deleting the current buffer, another one must be loaded.  If we know
  * which one is preferred, au_new_curbuf is set to it */
-EXTERN buf_T   *au_new_curbuf INIT(= NULL);
+EXTERN bufref_T        au_new_curbuf INIT(= {NULL});
 
 /* When deleting a buffer/window and autocmd_busy is TRUE, do not free the
  * buffer/window. but link it in the list starting with
index ebaef410d6ca940137563398f700b1ccc17864f4..04b7c017891de578294b8f4485bf913c0f6692d0 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2021,
 /**/
     2020,
 /**/