From b70d2af4abd8721abd29a5ed1171acedda81d435 Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 15 Jun 2020 13:23:44 +0300 Subject: [PATCH] crlib: avoid including --- ext/crlib/cr-alloc.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ext/crlib/cr-alloc.h b/ext/crlib/cr-alloc.h index 09ee431..40ddf6d 100644 --- a/ext/crlib/cr-alloc.h +++ b/ext/crlib/cr-alloc.h @@ -15,12 +15,15 @@ #pragma once -#include - #include #include #include +// provide placment new to avoid stdc++ header +inline void *operator new (const size_t, void *ptr) noexcept { + return ptr; +} + CR_NAMESPACE_BEGIN // default allocator for cr-objects @@ -31,12 +34,12 @@ public: public: template T *allocate (const size_t length = 1) { - auto ptr = reinterpret_cast (malloc (length * sizeof (T))); + auto memory = reinterpret_cast (malloc (length * sizeof (T))); - if (!ptr) { + if (!memory) { plat.abort (); } - return ptr; + return memory; } template void deallocate (T *memory) { @@ -55,10 +58,10 @@ public: public: template T *create (Args &&...args) { - auto d = allocate (); - new (d) T (cr::forward (args)...); + auto memory = allocate (); + new (memory) T (cr::forward (args)...); - return d; + return memory; } template T *createArray (const size_t amount) {