memory: Restore entered_free_all_mem functionality

This commit is contained in:
ZyX 2017-01-07 17:52:53 +03:00
parent 9a09ffa883
commit 35416e89bc
4 changed files with 19 additions and 11 deletions

View File

@ -21665,9 +21665,12 @@ void func_unref(char_u *name)
fp = find_func(name); fp = find_func(name);
if (fp == NULL) { if (fp == NULL) {
#ifdef EXITFREE #ifdef EXITFREE
if (!entered_free_all_mem) // NOLINT(readability/braces) if (!entered_free_all_mem) {
#endif
EMSG2(_(e_intern2), "func_unref()"); EMSG2(_(e_intern2), "func_unref()");
}
#else
EMSG2(_(e_intern2), "func_unref()");
#endif
} else { } else {
user_func_unref(fp); user_func_unref(fp);
} }

View File

@ -632,10 +632,6 @@ EXTERN int exiting INIT(= FALSE);
/* TRUE when planning to exit Vim. Might /* TRUE when planning to exit Vim. Might
* still keep on running if there is a changed * still keep on running if there is a changed
* buffer. */ * buffer. */
#if defined(EXITFREE)
// true when in or after free_all_mem()
EXTERN bool entered_free_all_mem INIT(= false);
#endif
// volatile because it is used in signal handler deathtrap(). // volatile because it is used in signal handler deathtrap().
EXTERN volatile int full_screen INIT(= false); EXTERN volatile int full_screen INIT(= false);
// TRUE when doing full-screen output // TRUE when doing full-screen output

View File

@ -48,6 +48,11 @@ MemRealloc mem_realloc = &realloc;
# include "memory.c.generated.h" # include "memory.c.generated.h"
#endif #endif
#ifdef EXITFREE
/// Indicates that free_all_mem function was or is running
bool entered_free_all_mem = false;
#endif
/// Try to free memory. Used when trying to recover from out of memory errors. /// Try to free memory. Used when trying to recover from out of memory errors.
/// @see {xmalloc} /// @see {xmalloc}
void try_to_free_memory(void) void try_to_free_memory(void)
@ -511,13 +516,13 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
void free_all_mem(void) void free_all_mem(void)
{ {
buf_T *buf, *nextbuf; buf_T *buf, *nextbuf;
static bool entered = false;
/* When we cause a crash here it is caught and Vim tries to exit cleanly. // When we cause a crash here it is caught and Vim tries to exit cleanly.
* Don't try freeing everything again. */ // Don't try freeing everything again.
if (entered) if (entered_free_all_mem) {
return; return;
entered = true; }
entered_free_all_mem = true;
// Don't want to trigger autocommands from here on. // Don't want to trigger autocommands from here on.
block_autocmds(); block_autocmds();

View File

@ -15,6 +15,10 @@ extern MemFree mem_free;
extern MemCalloc mem_calloc; extern MemCalloc mem_calloc;
extern MemRealloc mem_realloc; extern MemRealloc mem_realloc;
#ifdef EXITFREE
extern bool entered_free_all_mem;
#endif
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "memory.h.generated.h" # include "memory.h.generated.h"
#endif #endif