mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
refactor: make two functions used only in memory.c static (#34339)
After #29450 try_to_free_memory() is only used in memory.c. Also move do_outofmem_msg() closer to where it's used.
This commit is contained in:
@@ -42,7 +42,6 @@
|
|||||||
#include "nvim/ui_client.h"
|
#include "nvim/ui_client.h"
|
||||||
#include "nvim/ui_compositor.h"
|
#include "nvim/ui_compositor.h"
|
||||||
#include "nvim/usercmd.h"
|
#include "nvim/usercmd.h"
|
||||||
#include "nvim/vim_defs.h"
|
|
||||||
|
|
||||||
#ifdef UNIT_TESTING
|
#ifdef UNIT_TESTING
|
||||||
# define malloc(size) mem_malloc(size)
|
# define malloc(size) mem_malloc(size)
|
||||||
@@ -65,7 +64,7 @@ bool entered_free_all_mem = false;
|
|||||||
|
|
||||||
/// 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)
|
static void try_to_free_memory(void)
|
||||||
{
|
{
|
||||||
static bool trying_to_free = false;
|
static bool trying_to_free = false;
|
||||||
// avoid recursive calls
|
// avoid recursive calls
|
||||||
@@ -84,6 +83,24 @@ void try_to_free_memory(void)
|
|||||||
trying_to_free = false;
|
trying_to_free = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Avoid repeating the error message many times (they take 1 second each).
|
||||||
|
/// `did_outofmem_msg` is reset when a character is read.
|
||||||
|
static void do_outofmem_msg(size_t size)
|
||||||
|
{
|
||||||
|
if (did_outofmem_msg) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't hide this message
|
||||||
|
emsg_silent = 0;
|
||||||
|
|
||||||
|
// Must come first to avoid coming back here when printing the error
|
||||||
|
// message fails, e.g. when setting v:errmsg.
|
||||||
|
did_outofmem_msg = true;
|
||||||
|
|
||||||
|
semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size);
|
||||||
|
}
|
||||||
|
|
||||||
/// malloc() wrapper
|
/// malloc() wrapper
|
||||||
///
|
///
|
||||||
/// try_malloc() is a malloc() wrapper that tries to free some memory before
|
/// try_malloc() is a malloc() wrapper that tries to free some memory before
|
||||||
@@ -540,24 +557,6 @@ bool strnequal(const char *a, const char *b, size_t n)
|
|||||||
return (a == NULL && b == NULL) || (a && b && strncmp(a, b, n) == 0);
|
return (a == NULL && b == NULL) || (a && b && strncmp(a, b, n) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid repeating the error message many times (they take 1 second each).
|
|
||||||
// Did_outofmem_msg is reset when a character is read.
|
|
||||||
void do_outofmem_msg(size_t size)
|
|
||||||
{
|
|
||||||
if (did_outofmem_msg) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't hide this message
|
|
||||||
emsg_silent = 0;
|
|
||||||
|
|
||||||
// Must come first to avoid coming back here when printing the error
|
|
||||||
// message fails, e.g. when setting v:errmsg.
|
|
||||||
did_outofmem_msg = true;
|
|
||||||
|
|
||||||
semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Writes time_t to "buf[8]".
|
/// Writes time_t to "buf[8]".
|
||||||
void time_to_bytes(time_t time_, uint8_t buf[8])
|
void time_to_bytes(time_t time_, uint8_t buf[8])
|
||||||
{
|
{
|
||||||
|
@@ -21,10 +21,6 @@ typedef void *(*MemCalloc)(size_t, size_t);
|
|||||||
/// `realloc()` function signature
|
/// `realloc()` function signature
|
||||||
typedef void *(*MemRealloc)(void *, size_t);
|
typedef void *(*MemRealloc)(void *, size_t);
|
||||||
|
|
||||||
typedef void *(*MergeSortGetFunc)(void *);
|
|
||||||
typedef void (*MergeSortSetFunc)(void *, void *);
|
|
||||||
typedef int (*MergeSortCompareFunc)(const void *, const void *);
|
|
||||||
|
|
||||||
#ifdef UNIT_TESTING
|
#ifdef UNIT_TESTING
|
||||||
/// When unit testing: pointer to the `malloc()` function, may be altered
|
/// When unit testing: pointer to the `malloc()` function, may be altered
|
||||||
extern MemMalloc mem_malloc;
|
extern MemMalloc mem_malloc;
|
||||||
@@ -44,6 +40,10 @@ extern MemRealloc mem_realloc;
|
|||||||
extern bool entered_free_all_mem;
|
extern bool entered_free_all_mem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void *(*MergeSortGetFunc)(void *);
|
||||||
|
typedef void (*MergeSortSetFunc)(void *, void *);
|
||||||
|
typedef int (*MergeSortCompareFunc)(const void *, const void *);
|
||||||
|
|
||||||
EXTERN size_t arena_alloc_count INIT( = 0);
|
EXTERN size_t arena_alloc_count INIT( = 0);
|
||||||
|
|
||||||
#define kv_fixsize_arena(a, v, s) \
|
#define kv_fixsize_arena(a, v, s) \
|
||||||
|
Reference in New Issue
Block a user