Patch 7.4.2021
Problem: Still too many buf_valid() calls.
Solution: Make au_new_curbuf a bufref. Use bufref_valid() in more places.
Files: src/ex_cmds.c, src/buffer.c, src/globals.h
*** ../vim-7.4.2020/src/ex_cmds.c 2016-07-09 23:40:29.831039214 +0200
--- src/ex_cmds.c 2016-07-10 18:56:04.366146885 +0200
***************
*** 3447,3457 ****
}
else
{
if (buf_write_all(buf, eap->forceit) == FAIL)
++error;
#ifdef FEAT_AUTOCMD
/* an autocommand may have deleted the buffer */
! if (!buf_valid(buf))
buf = firstbuf;
#endif
}
--- 3447,3462 ----
}
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 (!bufref_valid(&bufref))
buf = firstbuf;
#endif
}
***************
*** 3659,3664 ****
--- 3664,3670 ----
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,3872 ****
else /* existing memfile */
{
oldbuf = TRUE;
(void)buf_check_timestamp(buf, FALSE);
/* Check if autocommands made buffer invalid or changed the current
* buffer. */
! if (!buf_valid(buf)
#ifdef FEAT_AUTOCMD
|| curbuf != old_curbuf
#endif
--- 3869,3879 ----
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 (!bufref_valid(&bufref)
#ifdef FEAT_AUTOCMD
|| curbuf != old_curbuf
#endif
***************
*** 3908,3917 ****
*/
if (buf->b_fname != NULL)
new_name = vim_strsave(buf->b_fname);
! au_new_curbuf = buf;
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
! if (!buf_valid(buf)) /* new buffer has been deleted */
{
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
--- 3915,3925 ----
*/
if (buf->b_fname != NULL)
new_name = vim_strsave(buf->b_fname);
! set_bufref(&au_new_curbuf, buf);
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
! if (!bufref_valid(&au_new_curbuf))
{
+ /* new buffer has been deleted */
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
***************
*** 3951,3958 ****
}
# endif
/* Be careful again, like above. */
! if (!buf_valid(buf)) /* new buffer has been deleted */
{
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
--- 3959,3967 ----
}
# endif
/* Be careful again, like above. */
! if (!bufref_valid(&au_new_curbuf))
{
+ /* new buffer has been deleted */
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
***************
*** 3995,4001 ****
#ifdef FEAT_AUTOCMD
}
vim_free(new_name);
! au_new_curbuf = NULL;
#endif
}
--- 4004,4010 ----
#ifdef FEAT_AUTOCMD
}
vim_free(new_name);
! au_new_curbuf.br_buf = NULL;
#endif
}
***************
*** 4071,4076 ****
--- 4080,4086 ----
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,4097 ****
#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))
{
delbuf_msg(new_name); /* frees new_name */
goto theend;
--- 4101,4107 ----
#ifdef FEAT_AUTOCMD
/* If autocommands deleted the buffer we were going to re-edit, give
* up and jump to the end. */
! if (!bufref_valid(&bufref))
{
delbuf_msg(new_name); /* frees new_name */
goto theend;
***************
*** 4375,4381 ****
EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"),
name == NULL ? (char_u *)"" : name);
vim_free(name);
! au_new_curbuf = NULL;
}
#endif
--- 4385,4391 ----
EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"),
name == NULL ? (char_u *)"" : name);
vim_free(name);
! au_new_curbuf.br_buf = NULL;
}
#endif
*** ../vim-7.4.2020/src/buffer.c 2016-07-10 18:33:55.822012755 +0200
--- src/buffer.c 2016-07-10 18:47:53.325503203 +0200
***************
*** 1293,1299 ****
* 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.
* 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.
--- 1293,1299 ----
* 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.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,1309 ****
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;
# ifdef FEAT_JUMPLIST
else
# endif
--- 1302,1309 ----
buf = NULL; /* selected buffer */
bp = NULL; /* used when no loaded buffer found */
#ifdef FEAT_AUTOCMD
! if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf))
! buf = au_new_curbuf.br_buf;
# ifdef FEAT_JUMPLIST
else
# endif
*** ../vim-7.4.2020/src/globals.h 2016-07-09 23:40:29.839039098 +0200
--- src/globals.h 2016-07-10 18:54:40.711399545 +0200
***************
*** 386,392 ****
/* 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);
/* When deleting a buffer/window and autocmd_busy is TRUE, do not free the
* buffer/window. but link it in the list starting with
--- 386,392 ----
/* 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 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
*** ../vim-7.4.2020/src/version.c 2016-07-10 18:33:55.826012695 +0200
--- src/version.c 2016-07-10 19:02:08.236700637 +0200
***************
*** 760,761 ****
--- 760,763 ----
{ /* Add new patch number below this line */
+ /**/
+ 2021,
/**/
--
Two fish in a tank. One says to the other:
"Do you know how to drive this thing?"
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.