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#ifndef STDALLOC_H
5#define STDALLOC_H
6
7#include <derive-c/core.h>
8#include <derive-c/panic.h>
9#include <stdlib.h>
10
11#ifdef __cplusplus
12struct stdalloc {
13 char UNUSED(_dummy_cpp_object_size_compatibility);
14};
15#else
16typedef struct {
17} stdalloc;
18#endif
19
21 static stdalloc instance = {};
22 return &instance;
23}
24
25static void* NAME(stdalloc, malloc)(stdalloc* DEBUG_UNUSED(self), size_t size) {
26 DEBUG_ASSERT(self);
27 return malloc(size);
28}
29
30static void* NAME(stdalloc, realloc)(stdalloc* DEBUG_UNUSED(self), void* ptr, size_t size) {
31 DEBUG_ASSERT(self);
32 DEBUG_ASSERT(ptr);
33 return realloc(ptr, size);
34}
35
36static void* NAME(stdalloc, calloc)(stdalloc* DEBUG_UNUSED(self), size_t count, size_t size) {
37 DEBUG_ASSERT(self);
38 return calloc(count, size);
39}
40
41static void NAME(stdalloc, free)(stdalloc* DEBUG_UNUSED(self), void* ptr) {
42 DEBUG_ASSERT(self);
43 DEBUG_ASSERT(ptr);
44 free(ptr);
45}
46
47#endif
static void free(SELF *self, void *ptr)
Definition template.h:62
static void * realloc(SELF *self, void *ptr, size_t size)
Definition template.h:51
static void * malloc(SELF *self, size_t size)
Definition template.h:29
static void * calloc(SELF *self, size_t count, size_t size)
Definition template.h:40
static void free(stdalloc *DEBUG_UNUSED(self), void *ptr)
Definition std.h:41
static void * malloc(stdalloc *DEBUG_UNUSED(self), size_t size)
Definition std.h:25
static void * calloc(stdalloc *DEBUG_UNUSED(self), size_t count, size_t size)
Definition std.h:36
static void * realloc(stdalloc *DEBUG_UNUSED(self), void *ptr, size_t size)
Definition std.h:30
#define UNUSED(ident)
Definition core.h:13
#define DEBUG_UNUSED(ident)
Definition core.h:8
#define NAME(pre, post)
Definition core.h:5
static nullalloc get()
Definition null.h:20
#define DEBUG_ASSERT(expr)
Definition panic.h:23
An allocator for the standard allocator, which only has global state,.
Definition std.h:16
static INDEX_TYPE size(SELF const *self)
Definition template.h:207