Derive-C
Loading...
Searching...
No Matches
std.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 stdalloc {
12 char UNUSED(_dummy_cpp_object_size_compatibility);
13};
14#else
15typedef struct {
16} stdalloc;
17#endif
18
19static stdalloc* NS(stdalloc, get)() {
20 static stdalloc instance = {};
21 return &instance;
22}
23
24static void* NS(stdalloc, malloc)(stdalloc* DEBUG_UNUSED(self), size_t size) {
25 DEBUG_ASSERT(self);
26 return malloc(size);
27}
28
29static void* NS(stdalloc, realloc)(stdalloc* DEBUG_UNUSED(self), void* ptr, size_t size) {
30 DEBUG_ASSERT(self);
31 if (ptr) {
32 return realloc(ptr, size);
33 }
34 return NS(stdalloc, malloc)(self, size);
35}
36
37static void* NS(stdalloc, calloc)(stdalloc* DEBUG_UNUSED(self), size_t count, size_t size) {
38 DEBUG_ASSERT(self);
39 return calloc(count, size);
40}
41
42static void NS(stdalloc, free)(stdalloc* DEBUG_UNUSED(self), void* ptr) {
43 DEBUG_ASSERT(self);
44 DEBUG_ASSERT(ptr);
45 free(ptr);
46}
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
static void free(stdalloc *DEBUG_UNUSED(self), void *ptr)
Definition std.h:42
static void * malloc(stdalloc *DEBUG_UNUSED(self), size_t size)
Definition std.h:24
static void * calloc(stdalloc *DEBUG_UNUSED(self), size_t count, size_t size)
Definition std.h:37
static void * realloc(stdalloc *DEBUG_UNUSED(self), void *ptr, size_t size)
Definition std.h:29
#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
An allocator for the standard allocator, which only has global state,.
Definition std.h:15
static INDEX_TYPE size(SELF const *self)
Definition template.h:220