AuroraRuntime/Include/AuroraAlloc.cpp

120 lines
3.1 KiB
C++

#include <AuroraCommon.hpp>
#include <AuroraRuntime.hpp>
#define BODY(...) __VA_ARGS__
#define ANNOYING_THROW(prefix, def, body) \
prefix def noexcept(false) \
body
#define ANNOYING_NOEXCEPT(prefix, def, body) \
prefix def, const std::nothrow_t& tag) noexcept(true) \
body \
prefix def) noexcept(true) \
body
#define ANNOYING_TAGONLY(prefix, def, body) \
prefix def, const std::nothrow_t& tag) noexcept(true) \
body
#define PROTOTYPE_FORMER(...) ( __VA_ARGS__ )
#define PROTOTYPE_LATTER(...) ( __VA_ARGS__
ANNOYING_THROW(void *operator new, PROTOTYPE_FORMER(std::size_t n), BODY(
{
void *buffer = Aurora::Memory::FAlloc<void *>(n);
if (buffer == nullptr)
{
throw std::bad_alloc();
}
return buffer;
}));
ANNOYING_TAGONLY(void *operator new, PROTOTYPE_LATTER(std::size_t n), BODY(
{
return Aurora::Memory::ZAlloc<void *>(n);
}));
ANNOYING_THROW(void *operator new, PROTOTYPE_FORMER(std::size_t n, std::align_val_t al), BODY(
{
void *buffer = Aurora::Memory::FAlloc<void *>(n, Aurora::Types::size_t(al));
if (buffer == nullptr)
{
throw std::bad_alloc();
}
return buffer;
}));
ANNOYING_TAGONLY(void *operator new, PROTOTYPE_LATTER(std::size_t n, std::align_val_t al), BODY(
{
return Aurora::Memory::ZAlloc<void *>(n, Aurora::Types::size_t(al));
}));
ANNOYING_NOEXCEPT(void operator delete, PROTOTYPE_LATTER(void *p), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_NOEXCEPT(void operator delete, PROTOTYPE_LATTER(void *p, std::align_val_t al), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_NOEXCEPT(void operator delete, PROTOTYPE_LATTER(void *p, std::size_t idc, std::align_val_t al), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_NOEXCEPT(void operator delete[], PROTOTYPE_LATTER(void *p), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_NOEXCEPT(void operator delete[], PROTOTYPE_LATTER(void *p, std::align_val_t al), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_NOEXCEPT(void operator delete[], PROTOTYPE_LATTER(void *p, std::size_t idc, std::align_val_t al), BODY(
{
Aurora::Memory::Free(p);
}));
ANNOYING_THROW(void *operator new[], PROTOTYPE_FORMER(std::size_t s), BODY(
{
void *buffer = Aurora::Memory::FAlloc<void *>(s);
if (buffer == nullptr)
{
throw std::bad_alloc();
}
return buffer;
}));
ANNOYING_TAGONLY(void *operator new[], PROTOTYPE_LATTER(std::size_t s), BODY(
{
return Aurora::Memory::FAlloc<void *>(s);
}));
ANNOYING_THROW(void *operator new[], PROTOTYPE_FORMER(std::size_t s, std::align_val_t al), BODY(
{
void *buffer = Aurora::Memory::FAlloc<void *>(s, Aurora::Types::size_t(al));
if (buffer == nullptr)
{
throw std::bad_alloc();
}
return buffer;
}));
ANNOYING_TAGONLY(void *operator new[], PROTOTYPE_LATTER(std::size_t s, std::align_val_t al), BODY(
{
return Aurora::Memory::FAlloc<void *>(s, Aurora::Types::size_t(al));
}));
/*
Applications migrating to AuroraRuntime 2.0 should include an empty file with the following
#if defined(_AUHAS_AURORARUNTIME)
#include <AuroraAlloc.cpp>
#endif
*/