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
6#include <stdlib.h>
7
10
11ZERO_SIZED(stdalloc);
12
13static stdalloc* NS(stdalloc, get)() {
14 static stdalloc instance = {};
15 return &instance;
16}
17
18static void* NS(stdalloc, malloc)(stdalloc* self, size_t size) {
19 ASSUME(self);
20 return malloc(size);
21}
22
23static void* NS(stdalloc, realloc)(stdalloc* self, void* ptr, size_t size) {
24 ASSUME(self);
25 if (ptr) {
26 return realloc(ptr, size);
27 }
28 return NS(stdalloc, malloc)(self, size);
29}
30
31static void* NS(stdalloc, calloc)(stdalloc* self, size_t count, size_t size) {
32 ASSUME(self);
33 return calloc(count, size);
34}
35
36static void NS(stdalloc, free)(stdalloc* self, void* ptr) {
37 ASSUME(self);
38 ASSUME(ptr);
39 free(ptr);
40}
41
42TRAIT_ALLOC(stdalloc);
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
static void * calloc(stdalloc *self, size_t count, size_t size)
Definition std.h:31
static void free(stdalloc *self, void *ptr)
Definition std.h:36
static void * realloc(stdalloc *self, void *ptr, size_t size)
Definition std.h:23
static void * malloc(stdalloc *self, size_t size)
Definition std.h:18
#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 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