16 #if !defined(SKIP_INCLUDES)
25 #define ALLOCATIONS_MAP NS(NAME, allocations)
27 #pragma push_macro("ALLOC")
31 #define ALLOC stdalloc
33 #define KEY_HASH(ptr) ((size_t)(*(ptr)))
34 #define KEY_DEBUG dc_void_ptr_debug
36 #define INTERNAL_NAME ALLOCATIONS_MAP
39 #pragma pop_macro("ALLOC")
48 .alloc_ref = alloc_ref,
55 return &self->allocations;
73 "Got zeroed allocation, that is already allocated at %p (attempted size: %zu)", ptr,
83 "Got uninit allocation, that is already allocated at %p (attempted size: %zu)", ptr,
94 DC_ASSERT(tracked_size != NULL,
"Reallocating pointer that is not allocated");
96 "Incorrect size provided for reallocation of %p (was %zu, but expected %zu)", old_ptr,
97 old_size, *tracked_size);
100 void* new_ptr =
NS(
ALLOC,
reallocate)(self->alloc_ref, old_ptr, old_size, new_size);
104 "Got new reallocation, that is already allocated at %p (attempted size: %zu)",
116 "Attempted to deallocate %p (size: %zu), but was not already allocated", ptr,
size);
118 "Incorrect size passed on %p deallocation (was: %zu, expected: %zu)", ptr,
119 *tracked_size,
size);
130 (
void*)
NS(
NS(
ALLOC, ref), deref)(self->alloc_ref));
140 #undef ALLOCATIONS_MAP
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
static DC_PUBLIC void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC void * allocate_zeroed(SELF *self, size_t size)
static DC_PUBLIC void * allocate_uninit(SELF *self, size_t size)
static DC_PUBLIC void * reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
static DC_PUBLIC ALLOCATIONS_MAP const * get_allocations(SELF const *self)
#define ALLOCATIONS_MAP
For unit tests expected to throw, as C has no unwind, we cannot free allocated memory....
static DC_PUBLIC void unleak(SELF *self)
#define DC_TRAIT_ALLOC(SELF)
static DC_PUBLIC VALUE const * try_read(SELF const *self, INDEX index)
static DC_PUBLIC size_t size(SELF const *self)
static DC_PUBLIC void delete_entry(SELF *self, KEY key)
static DC_PUBLIC VALUE * try_insert(SELF *self, KEY key, VALUE value)
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
#define DC_FOR(TYPE, INSTANCE, ITER, ITEM)
#define DC_EXPAND_STRING(NAME)
#define DC_ASSERT(expr,...)
#define DC_ASSUME(expr,...)
#define DC_TRAIT_REFERENCABLE_BY_PTR(SELF)
ALLOCATIONS_MAP allocations
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)