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
6#include <stdlib.h>
7
10
11ZERO_SIZED(nullalloc);
12
13static nullalloc NS(nullalloc, get)() { return (nullalloc){}; }
14
15static void* NS(nullalloc, malloc)(nullalloc* self, size_t size) {
16 (void)size;
17 ASSUME(self);
18 return NULL;
19}
20
21static void* NS(nullalloc, realloc)(nullalloc* self, void* ptr, size_t size) {
22 (void)size;
23 ASSUME(self);
24 ASSUME(ptr);
25 return NULL;
26}
27
28static void* NS(nullalloc, calloc)(nullalloc* self, size_t count, size_t size) {
29 (void)count;
30 (void)size;
31 ASSUME(self);
32 return NULL;
33}
34
35static void NS(nullalloc, free)(nullalloc* self, void* ptr) {
36 (void)ptr;
37 ASSUME(self);
38 PANIC("Not possible to free memory from the null allocator, as it allocates nothing")
39}
40
41TRAIT_ALLOC(nullalloc);
static void free(SELF *self, void *ptr)
Definition template.h:58
static void * realloc(SELF *self, void *ptr, size_t size)
Definition template.h:47
static void * malloc(SELF *self, size_t size)
Definition template.h:25
static void * calloc(SELF *self, size_t count, size_t size)
Definition template.h:36
#define TRAIT_ALLOC(SELF)
Definition trait.h:4
static INDEX_TYPE size(SELF const *self)
Definition template.h:275
#define ASSUME(expr,...)
Definition macros.h:62
#define PANIC(...)
Definition macros.h:34
#define NS(pre, post)
Definition namespace.h:4
static nullalloc get()
Definition null.h:13
#define ZERO_SIZED(TYPE)
Zero sized types are useful as markers (e.g. for gdb printing, or to replace debug info structs.
Definition zerosized.h:15