1#ifndef NVIM_MEMORY_H
2#define NVIM_MEMORY_H
3
4#include <stdbool.h> // for bool
5#include <stdint.h> // for uint8_t
6#include <stddef.h> // for size_t
7#include <time.h> // for time_t
8
9/// `malloc()` function signature
10typedef void *(*MemMalloc)(size_t);
11
12/// `free()` function signature
13typedef void (*MemFree)(void *);
14
15/// `calloc()` function signature
16typedef void *(*MemCalloc)(size_t, size_t);
17
18/// `realloc()` function signature
19typedef void *(*MemRealloc)(void *, size_t);
20
21#ifdef UNIT_TESTING
22/// When unit testing: pointer to the `malloc()` function, may be altered
23extern MemMalloc mem_malloc;
24
25/// When unit testing: pointer to the `free()` function, may be altered
26extern MemFree mem_free;
27
28/// When unit testing: pointer to the `calloc()` function, may be altered
29extern MemCalloc mem_calloc;
30
31/// When unit testing: pointer to the `realloc()` function, may be altered
32extern MemRealloc mem_realloc;
33#endif
34
35#ifdef EXITFREE
36/// Indicates that free_all_mem function was or is running
37extern bool entered_free_all_mem;
38#endif
39
40#ifdef INCLUDE_GENERATED_DECLARATIONS
41# include "memory.h.generated.h"
42#endif
43
44#define XFREE_CLEAR(ptr) \
45 do { \
46 /* Take the address to avoid double evaluation. #1375 */ \
47 void **ptr_ = (void **)&(ptr); \
48 xfree(*ptr_); \
49 /* coverity[dead-store] */ \
50 *ptr_ = NULL; \
51 (void)(*ptr_); \
52 } while (0)
53
54#endif // NVIM_MEMORY_H
55