Derive-C
Loading...
Searching...
No Matches
std.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <derive-c/alloc/trait.h>
#include <derive-c/core/prelude.h>

Go to the source code of this file.

Functions

 DC_ZERO_SIZED (stdalloc)
 An allocator for the standard allocator, which only has global state,.
static stdalloc * get ()
static void * malloc (stdalloc *self, size_t size)
static void * realloc (stdalloc *self, void *ptr, size_t size)
static void * calloc (stdalloc *self, size_t count, size_t size)
static void free (stdalloc *self, void *ptr)
static void debug (stdalloc const *self, dc_debug_fmt fmt, FILE *stream)
 DC_TRAIT_ALLOC (stdalloc)

Function Documentation

◆ calloc()

void * calloc ( stdalloc * self,
size_t count,
size_t size )
static

Definition at line 32 of file std.h.

32 {
33 DC_ASSUME(self);
34 return calloc(count, size);
35}
static INDEX_TYPE size(SELF const *self)
Definition template.h:252
#define DC_ASSUME(expr,...)
Definition panic.h:56
static void * calloc(stdalloc *self, size_t count, size_t size)
Definition std.h:32

◆ DC_TRAIT_ALLOC()

DC_TRAIT_ALLOC ( stdalloc )

◆ DC_ZERO_SIZED()

DC_ZERO_SIZED ( stdalloc )

An allocator for the standard allocator, which only has global state,.

◆ debug()

void debug ( stdalloc const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 43 of file std.h.

43 {
44 (void)fmt;
45 fprintf(stream, "stdalloc@%p { }", self);
46}
static FILE * stream(SELF *self)
Opens a file for.
Definition template.h:107

◆ free()

void free ( stdalloc * self,
void * ptr )
static

Definition at line 37 of file std.h.

37 {
38 DC_ASSUME(self);
39 DC_ASSUME(ptr);
40 free(ptr);
41}
static void free(stdalloc *self, void *ptr)
Definition std.h:37

◆ get()

stdalloc * get ( )
static

Definition at line 14 of file std.h.

14 {
15 static stdalloc instance = {};
16 return &instance;
17}

◆ malloc()

void * malloc ( stdalloc * self,
size_t size )
static

Definition at line 19 of file std.h.

19 {
20 DC_ASSUME(self);
21 return malloc(size);
22}
static void * malloc(stdalloc *self, size_t size)
Definition std.h:19

◆ realloc()

void * realloc ( stdalloc * self,
void * ptr,
size_t size )
static

Definition at line 24 of file std.h.

24 {
25 DC_ASSUME(self);
26 if (ptr) {
27 return realloc(ptr, size);
28 }
29 return NS(stdalloc, malloc)(self, size);
30}
static void * malloc(SELF *self, size_t size)
Definition template.h:23
#define NS(pre, post)
Definition namespace.h:4
static void * realloc(stdalloc *self, void *ptr, size_t size)
Definition std.h:24