memory.h
Go to the documentation of this file.
1 #ifndef NVIM_MEMORY_H
2 #define NVIM_MEMORY_H
3 
4 #include <stdbool.h> // for bool
5 #include <stddef.h> // for size_t
6 #include <stdint.h> // for uint8_t
7 #include <time.h> // for time_t
8 
10 typedef void *(*MemMalloc)(size_t);
11 
13 typedef void (*MemFree)(void *);
14 
16 typedef void *(*MemCalloc)(size_t, size_t);
17 
19 typedef void *(*MemRealloc)(void *, size_t);
20 
21 #ifdef UNIT_TESTING
22 extern MemMalloc mem_malloc;
24 
26 extern MemFree mem_free;
27 
29 extern MemCalloc mem_calloc;
30 
32 extern MemRealloc mem_realloc;
33 #endif
34 
35 #ifdef EXITFREE
36 extern bool entered_free_all_mem;
38 #endif
39 
40 typedef struct consumed_blk {
41  struct consumed_blk *prev;
42 } *ArenaMem;
43 
44 #define ARENA_ALIGN sizeof(void *)
45 
46 typedef struct {
47  char *cur_blk;
48  size_t pos, size;
49 } Arena;
50 
51 // inits an empty arena. use arena_start() to actually allocate space!
52 #define ARENA_EMPTY { .cur_blk = NULL, .pos = 0, .size = 0 }
53 
54 #define kv_fixsize_arena(a, v, s) \
55  ((v).capacity = (s), \
56  (v).items = (void *)arena_alloc(a, sizeof((v).items[0]) * (v).capacity, true))
57 
58 #ifdef INCLUDE_GENERATED_DECLARATIONS
59 # include "memory.h.generated.h"
60 #endif
61 
62 #define XFREE_CLEAR(ptr) \
63  do { \
64  /* Take the address to avoid double evaluation. #1375 */ \
65  void **ptr_ = (void **)&(ptr); \
66  xfree(*ptr_); \
67  /* coverity[dead-store] */ \
68  *ptr_ = NULL; \
69  (void)(*ptr_); \
70  } while (0)
71 
72 #endif // NVIM_MEMORY_H
MemCalloc
void *(* MemCalloc)(size_t, size_t)
calloc() function signature
Definition: memory.h:16
Arena::size
size_t size
Definition: memory.h:48
Arena
Definition: memory.h:46
MemRealloc
void *(* MemRealloc)(void *, size_t)
realloc() function signature
Definition: memory.h:19
void
void(WINAPI *pClosePseudoConsole)(HPCON)
ArenaMem
struct consumed_blk * ArenaMem
MemFree
void(* MemFree)(void *)
free() function signature
Definition: memory.h:13
pos
pos_T pos
Definition: funcs.c:8214
MemMalloc
void *(* MemMalloc)(size_t)
malloc() function signature
Definition: memory.h:10
consumed_blk::prev
struct consumed_blk * prev
Definition: memory.h:41
consumed_blk
Definition: memory.h:40
Arena::cur_blk
char * cur_blk
Definition: memory.h:47
entered_free_all_mem
#define entered_free_all_mem
Definition: ui.c:76