Derive-C
Loading...
Searching...
No Matches
null.h
Go to the documentation of this file.
1
2// and just uses malloc/calloc/free.
3
4#pragma once
5
8#include <stdlib.h>
9
10#if defined __cplusplus
11struct nullalloc {
12 char UNUSED(_dummy_cpp_object_size_compatibility);
13};
14#else
15typedef struct {
16} nullalloc;
17#endif
18
19static nullalloc NS(nullalloc, get)() { return (nullalloc){}; }
20
21static void* NS(nullalloc, malloc)(nullalloc* DEBUG_UNUSED(self), size_t UNUSED(size)) {
22 DEBUG_ASSERT(self);
23 return NULL;
24}
25
26static void* NS(nullalloc, realloc)(nullalloc* DEBUG_UNUSED(self), void* DEBUG_UNUSED(ptr),
27 size_t UNUSED(size)) {
28 DEBUG_ASSERT(self);
29 DEBUG_ASSERT(ptr);
30 return NULL;
31}
32
33static void* NS(nullalloc, calloc)(nullalloc* DEBUG_UNUSED(self), size_t UNUSED(count),
34 size_t UNUSED(size)) {
35 DEBUG_ASSERT(self);
36 return NULL;
37}
38
39static void NS(nullalloc, free)(nullalloc* DEBUG_UNUSED(self), void* UNUSED(ptr)) {
40 DEBUG_ASSERT(self);
41 PANIC("Not possible to free memory from the null allocator, as it allocates nothing")
42}
static void free(SELF *self, void *ptr)
Definition template.h:56
static void * realloc(SELF *self, void *ptr, size_t size)
Definition template.h:45
static void * malloc(SELF *self, size_t size)
Definition template.h:23
static void * calloc(SELF *self, size_t count, size_t size)
Definition template.h:34
#define UNUSED(ident)
Definition helpers.h:16
#define NS(pre, post)
Definition helpers.h:6
#define DEBUG_UNUSED(ident)
Definition helpers.h:11
static nullalloc get()
Definition null.h:19
#define DEBUG_ASSERT(expr)
Definition panic.h:34
#define PANIC(...)
Definition panic.h:7
An allocator for the standard allocator, which only has global state,.
Definition null.h:15
static INDEX_TYPE size(SELF const *self)
Definition template.h:220