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 <stdio.h>
7#include <stdlib.h>
8
11
12DC_ZERO_SIZED(stdalloc);
13
14static stdalloc* NS(stdalloc, get)() {
15 static stdalloc instance = {};
16 return &instance;
17}
18
19static void* NS(stdalloc, malloc)(stdalloc* self, size_t size) {
20 DC_ASSUME(self);
21 return malloc(size);
22}
23
24static void* NS(stdalloc, realloc)(stdalloc* self, void* ptr, size_t size) {
25 DC_ASSUME(self);
26 if (ptr) {
27 return realloc(ptr, size);
28 }
29 return NS(stdalloc, malloc)(self, size);
30}
31
32static void* NS(stdalloc, calloc)(stdalloc* self, size_t count, size_t size) {
33 DC_ASSUME(self);
34 return calloc(count, size);
35}
36
37static void NS(stdalloc, free)(stdalloc* self, void* ptr) {
38 DC_ASSUME(self);
39 DC_ASSUME(ptr);
40 free(ptr);
41}
42
43static void NS(stdalloc, debug)(stdalloc const* self, dc_debug_fmt fmt, FILE* stream) {
44 (void)fmt;
45 fprintf(stream, "stdalloc@%p { }", self);
46}
47
static void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
Definition template.h:62
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 DC_TRAIT_ALLOC(SELF)
Definition trait.h:5
static INDEX_TYPE size(SELF const *self)
Definition template.h:252
#define NS(pre, post)
Definition namespace.h:4
static nullalloc get()
Definition null.h:14
#define DC_ASSUME(expr,...)
Definition panic.h:56
static void * calloc(stdalloc *self, size_t count, size_t size)
Definition std.h:32
static void free(stdalloc *self, void *ptr)
Definition std.h:37
static void * realloc(stdalloc *self, void *ptr, size_t size)
Definition std.h:24
static void * malloc(stdalloc *self, size_t size)
Definition std.h:19
Debug format helpers for debug printin data structures.
Definition fmt.h:10
static FILE * stream(SELF *self)
Opens a file for.
Definition template.h:107
#define DC_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