13#include "lix/libutil/checked-arithmetic.hh"
18#include <gc/gc_allocator.h>
22#define LIX_GC_CALLOC(size) GC_MALLOC(size)
25#define LIX_GC_STRDUP(str) GC_STRDUP(str)
28#define LIX_GC_MALLOC_ATOMIC(size) GC_MALLOC_ATOMIC(size)
34using TraceableAllocator = traceable_allocator<T>;
43#define LIX_GC_CALLOC(size) calloc(size, 1)
46#define LIX_GC_STRDUP(str) strdup(str)
50#define LIX_GC_MALLOC_ATOMIC(size) malloc(size)
56using TraceableAllocator = std::allocator<T>;
67template<
typename KeyT,
typename ValueT>
68using GcMap = std::map<
72 TraceableAllocator<std::pair<KeyT const, ValueT>>
77template<
typename ItemT>
78using GcVector = std::vector<ItemT, TraceableAllocator<ItemT>>;
82template<
typename ItemT>
83using GcList = std::list<ItemT, TraceableAllocator<ItemT>>;
86inline void * gcAllocBytes(
size_t n)
90 void * ptr = LIX_GC_CALLOC(n);
92 throw std::bad_alloc();
103[[gnu::always_inline]]
104inline T * gcAllocType(
size_t howMany = 1)
114 size_t sz = checkedSz.valueWrapping();
115 if (checkedSz.overflowed()) {
117 throw std::bad_alloc();
120 return static_cast<T *
>(gcAllocBytes(sz));
127inline char * gcAllocString(
size_t size)
129 char * cstr =
static_cast<char *
>(LIX_GC_MALLOC_ATOMIC(size));
130 if (cstr ==
nullptr) {
131 throw std::bad_alloc();
138char const * gcCopyStringIfNeeded(std::string_view toCopyFrom);
Definition checked-arithmetic.hh:25