Derive-C
Loading...
Searching...
No Matches
null.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 (nullalloc)
 An allocator for the standard allocator, which only has global state,.
static nullalloc get ()
static void * malloc (nullalloc *self, size_t size)
static void * realloc (nullalloc *self, void *ptr, size_t size)
static void * calloc (nullalloc *self, size_t count, size_t size)
static void free (nullalloc *self, void *ptr)
static void debug (nullalloc const *self, dc_debug_fmt fmt, FILE *stream)
 DC_TRAIT_ALLOC (nullalloc)

Function Documentation

◆ calloc()

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

Definition at line 29 of file null.h.

29 {
30 (void)count;
31 (void)size;
32 DC_ASSUME(self);
33 return NULL;
34}
static INDEX_TYPE size(SELF const *self)
Definition template.h:252
#define DC_ASSUME(expr,...)
Definition panic.h:56

◆ DC_TRAIT_ALLOC()

DC_TRAIT_ALLOC ( nullalloc )

◆ DC_ZERO_SIZED()

DC_ZERO_SIZED ( nullalloc )

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

◆ debug()

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

Definition at line 42 of file null.h.

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

◆ free()

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

Definition at line 36 of file null.h.

36 {
37 (void)ptr;
38 DC_ASSUME(self);
39 DC_PANIC("Not possible to free memory from the null allocator, as it allocates nothing")
40}
#define DC_PANIC(...)
Definition panic.h:28

◆ get()

nullalloc get ( )
static

Definition at line 14 of file null.h.

14{ return (nullalloc){}; }

◆ malloc()

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

Definition at line 16 of file null.h.

16 {
17 (void)size;
18 DC_ASSUME(self);
19 return NULL;
20}

◆ realloc()

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

Definition at line 22 of file null.h.

22 {
23 (void)size;
24 DC_ASSUME(self);
25 DC_ASSUME(ptr);
26 return NULL;
27}