Readded C++17 allocators

This commit is contained in:
Reece Wilson 2021-06-27 23:53:04 +01:00
parent 4f399b7e01
commit f1445c63bb
3 changed files with 133 additions and 0 deletions

120
Include/AuroraAlloc.cpp Normal file
View File

@ -0,0 +1,120 @@
#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
*/

10
Source/Alloc.cpp Normal file
View File

@ -0,0 +1,10 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Alloc.cpp
Date: 2021-6-27
Author: Reece
***/
#if defined(_AUHAS_AURORARUNTIME) || defined(AURORA_ENGINE_RUNTIME) || defined(AURORA_ENGINE_KERNEL)
#include <AuroraAlloc.cpp>
#endif

View File

@ -16,6 +16,8 @@
#include "IO/FS/FS.hpp"
#include "Hashing/Hashing.hpp"
#include "Debug/Debug.hpp"
#include "Async/Async.hpp"
static void Init()
{
@ -28,6 +30,7 @@ static void Init()
Aurora::Processes::Init();
Aurora::RNG::Init();
Aurora::Hashing::InitHashing();
Aurora::Async::InitAsync();
}
static void Pump()