feat(aucmd_win): allow crazy things with hidden buffers (#21250)

Problem:    Crash when doing crazy things with hidden buffers.
Solution:   Dynamically allocate the list of autocommand windows.
This commit is contained in:
zeertzjq
2022-12-02 20:39:24 +08:00
committed by GitHub
parent 805c83f43e
commit 1145a9b248
12 changed files with 134 additions and 153 deletions

View File

@@ -422,19 +422,18 @@ EXTERN win_T *prevwin INIT(= NULL); // previous window
EXTERN win_T *curwin; // currently active window
/// When executing autocommands for a buffer that is not in any window, a
/// special window is created to handle the side effects. When autocommands
/// nest we may need more than one. Allow for up to five, if more are needed
/// something crazy is happening.
enum { AUCMD_WIN_COUNT = 5, };
typedef struct {
win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the
///< window has been allocated.
bool auc_win_used; ///< This auc_win is being used.
} aucmdwin_T;
EXTERN aucmdwin_T aucmd_win[AUCMD_WIN_COUNT];
/// When executing autocommands for a buffer that is not in any window, a
/// special window is created to handle the side effects. When autocommands
/// nest we may need more than one.
EXTERN kvec_t(aucmdwin_T) aucmd_win_vec INIT(= KV_INITIAL_VALUE);
#define aucmd_win (aucmd_win_vec.items)
#define AUCMD_WIN_COUNT ((int)aucmd_win_vec.size)
// The window layout is kept in a tree of frames. topframe points to the top
// of the tree.