Derive-C
Loading...
Searching...
No Matches
trait.h File Reference

Go to the source code of this file.

Macros

#define DC_TRAIT_ALLOC(SELF)

Macro Definition Documentation

◆ DC_TRAIT_ALLOC

#define DC_TRAIT_ALLOC ( SELF)
Value:
DC_REQUIRE_METHOD(void*, SELF, allocate_uninit, (NS(SELF, ref), size_t size)); \
DC_REQUIRE_METHOD(void*, SELF, allocate_zeroed, (NS(SELF, ref), size_t size)); \
DC_REQUIRE_METHOD(void*, SELF, reallocate, \
(NS(SELF, ref), void* ptr, size_t old_size, size_t new_size)); \
DC_REQUIRE_METHOD(void, SELF, deallocate, (NS(SELF, ref), void* ptr, size_t size)); \
DC_TRAIT_REFERENCABLE(SELF); \
DC_TRAIT_DELETABLE(SELF); \
DC_TRAIT_DEBUGABLE(SELF)
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
Definition template.h:127
static DC_PUBLIC void * allocate_zeroed(SELF *self, size_t size)
Definition template.h:117
static DC_PUBLIC void * allocate_uninit(SELF *self, size_t size)
Definition template.h:92
static DC_PUBLIC void * reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
Definition template.h:137
static DC_PUBLIC size_t size(SELF const *self)
Definition template.h:252
#define SELF
Definition def.h:52
#define NS(pre, post)
Definition namespace.h:14
#define DC_REQUIRE_METHOD(ret, obj, name, args)
Definition require.h:18

The trait for derive-c allocators. Behaviour is more restrictive that the standard allocator, and provides additional information.

  • The user is trusted to store, or correctly infer (e.g. via types) the size of the allocation

Additiona poisoning is done.

  • For msan, we set bytes removed by reallocating smaller. (not done by normal allocator, and The behaviour is stricter than the malloc/calloc/realloc/free:
  • Throws on allocating zero sized
  • Never returns null pointers from realloc, malloc, calloc
  • Throws on freeing a nullptr
  • Throws on reallocating to zero size

Definition at line 18 of file trait.h.

18#define DC_TRAIT_ALLOC(SELF) \
19 DC_REQUIRE_METHOD(void*, SELF, allocate_uninit, (NS(SELF, ref), size_t size)); \
20 DC_REQUIRE_METHOD(void*, SELF, allocate_zeroed, (NS(SELF, ref), size_t size)); \
21 DC_REQUIRE_METHOD(void*, SELF, reallocate, \
22 (NS(SELF, ref), void* ptr, size_t old_size, size_t new_size)); \
23 DC_REQUIRE_METHOD(void, SELF, deallocate, (NS(SELF, ref), void* ptr, size_t size)); \
24 DC_TRAIT_REFERENCABLE(SELF); \
25 DC_TRAIT_DELETABLE(SELF); \
26 DC_TRAIT_DEBUGABLE(SELF)