mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 02:46:31 +00:00

Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers.
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
#ifndef NVIM_MEMORY_H
|
|
#define NVIM_MEMORY_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#include "nvim/macros.h"
|
|
|
|
/// `malloc()` function signature
|
|
typedef void *(*MemMalloc)(size_t);
|
|
|
|
/// `free()` function signature
|
|
typedef void (*MemFree)(void *);
|
|
|
|
/// `calloc()` function signature
|
|
typedef void *(*MemCalloc)(size_t, size_t);
|
|
|
|
/// `realloc()` function signature
|
|
typedef void *(*MemRealloc)(void *, size_t);
|
|
|
|
#ifdef UNIT_TESTING
|
|
/// When unit testing: pointer to the `malloc()` function, may be altered
|
|
extern MemMalloc mem_malloc;
|
|
|
|
/// When unit testing: pointer to the `free()` function, may be altered
|
|
extern MemFree mem_free;
|
|
|
|
/// When unit testing: pointer to the `calloc()` function, may be altered
|
|
extern MemCalloc mem_calloc;
|
|
|
|
/// When unit testing: pointer to the `realloc()` function, may be altered
|
|
extern MemRealloc mem_realloc;
|
|
#endif
|
|
|
|
#ifdef EXITFREE
|
|
/// Indicates that free_all_mem function was or is running
|
|
extern bool entered_free_all_mem;
|
|
#endif
|
|
|
|
EXTERN size_t arena_alloc_count INIT(= 0);
|
|
|
|
typedef struct consumed_blk {
|
|
struct consumed_blk *prev;
|
|
} *ArenaMem;
|
|
|
|
#define ARENA_ALIGN MAX(sizeof(void *), sizeof(double))
|
|
|
|
typedef struct {
|
|
char *cur_blk;
|
|
size_t pos, size;
|
|
} Arena;
|
|
|
|
// inits an empty arena.
|
|
#define ARENA_EMPTY { .cur_blk = NULL, .pos = 0, .size = 0 }
|
|
|
|
#define kv_fixsize_arena(a, v, s) \
|
|
((v).capacity = (s), \
|
|
(v).items = (void *)arena_alloc(a, sizeof((v).items[0]) * (v).capacity, true))
|
|
|
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
|
# include "memory.h.generated.h"
|
|
#endif
|
|
|
|
#define XFREE_CLEAR(ptr) \
|
|
do { \
|
|
/* Take the address to avoid double evaluation. #1375 */ \
|
|
void **ptr_ = (void **)&(ptr); \
|
|
xfree(*ptr_); \
|
|
/* coverity[dead-store] */ \
|
|
*ptr_ = NULL; \
|
|
(void)(*ptr_); \
|
|
} while (0)
|
|
|
|
#endif // NVIM_MEMORY_H
|