Skip to content

Commit

Permalink
mem: adds error output message in allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jan 30, 2024
1 parent 65642be commit 26a737e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/include/irritator/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct e_json {
e_json() noexcept = default;

e_json(long long unsigned int offset_, std::string_view str) noexcept
: offset(offset_)
{
const auto len =
str.size() > sizeof error_code ? sizeof error_code : str.size();
Expand Down
20 changes: 16 additions & 4 deletions lib/src/memory-resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,34 @@ void* malloc_memory_resource::do_allocate(std::size_t bytes,

using fn = void* (*)(std::size_t, std::size_t) noexcept;

#ifdef _WIN32
#if defined(_MSC_VER)
fn call = reinterpret_cast<fn>(::_aligned_malloc);
auto* first = call(bytes, alignment);
#elif defined(__APPLE__)
void* first;
if (::posix_memalign(&p, alignment, bytes) != 0)
p = nullptr;
#else
fn call = reinterpret_cast<fn>(std::aligned_alloc);
auto* first = call(alignment, bytes);
#endif

if (not first)
if (not first) {
#if defined(IRRITATOR_ENABLE_DEBUG)
std::fprintf(
stderr,
"Irritator shutdown: Unable to allocate memory %zu alignment %zu\n",
bytes,
alignment);
#endif
std::abort();
}

return first;
}

void malloc_memory_resource::do_deallocate(void* pointer,
std::size_t bytes) noexcept
void malloc_memory_resource::do_deallocate(void* pointer,
std::size_t /* bytes */) noexcept
{
#ifdef _WIN32
if (pointer)
Expand Down

0 comments on commit 26a737e

Please sign in to comment.