robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

bfredlMerge pull request #35206 from bfredl/nopreproc_cleanup38986188ba

master
2.1 KiB75 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>  // IWYU pragma: keep
5#include <string.h>
6#include <time.h>  // IWYU pragma: keep
7
8#include "auto/config.h"
9#include "nvim/macros_defs.h"
10#include "nvim/memory_defs.h"  // IWYU pragma: keep
11
12/// `malloc()` function signature
13typedef void *(*MemMalloc)(size_t);
14
15/// `free()` function signature
16typedef void (*MemFree)(void *);
17
18/// `calloc()` function signature
19typedef void *(*MemCalloc)(size_t, size_t);
20
21/// `realloc()` function signature
22typedef void *(*MemRealloc)(void *, size_t);
23
24#ifdef UNIT_TESTING
25/// When unit testing: pointer to the `malloc()` function, may be altered
26extern MemMalloc mem_malloc;
27
28/// When unit testing: pointer to the `free()` function, may be altered
29extern MemFree mem_free;
30
31/// When unit testing: pointer to the `calloc()` function, may be altered
32extern MemCalloc mem_calloc;
33
34/// When unit testing: pointer to the `realloc()` function, may be altered
35extern MemRealloc mem_realloc;
36#endif
37
38#ifdef EXITFREE
39/// Indicates that free_all_mem function was or is running
40extern bool entered_free_all_mem;
41#endif
42
43typedef void *(*MergeSortGetFunc)(void *);
44typedef void (*MergeSortSetFunc)(void *, void *);
45typedef int (*MergeSortCompareFunc)(const void *, const void *);
46
47EXTERN size_t arena_alloc_count INIT( = 0);
48
49#define kv_fixsize_arena(a, v, s) \
50  ((v).capacity = (s), \
51   (v).items = (void *)arena_alloc(a, sizeof((v).items[0]) * (v).capacity, true))
52
53#include "memory.h.generated.h"
54
55#define XFREE_CLEAR(ptr) \
56  do { \
57    /* Take the address to avoid double evaluation. #1375 */ \
58    void **ptr_ = (void **)&(ptr); \
59    xfree(*ptr_); \
60    /* coverity[dead-store] */ \
61    *ptr_ = NULL; \
62    (void)(*ptr_); \
63  } while (0)
64
65#define CLEAR_FIELD(field)  memset(&(field), 0, sizeof(field))
66#define CLEAR_POINTER(ptr)  memset((ptr), 0, sizeof(*(ptr)))
67
68#ifndef HAVE_STRNLEN
69# define strnlen xstrnlen  // Older versions of SunOS may not have strnlen
70#endif
71
72#define STRCPY(d, s)        strcpy((char *)(d), (char *)(s))  // NOLINT(runtime/printf)
73
74// Like strcpy() but allows overlapped source and destination.
75#define STRMOVE(d, s)       memmove((d), (s), strlen(s) + 1)