// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
#undef new
//==================================================================================================
static PVOID Allocate(SIZE_T size, $CI_REF $required ) $null_on_failure;
//==================================================================================================

PVOID operator new (std::size_t size) $fatal_error_on_failure
{
   return Allocate( size, $$ );
}
PVOID operator new (std::size_t size, $CI_REF ) $fatal_error_on_failure
{
   return Allocate( size, $$CI );
}

//--------------------------------------------------------------------------------------------------

void operator delete (PVOID pointer $not_null) $fatal_error_on_failure
{
   $$VERIFY_POINTER_ARG_( pointer );
   RuntimeForStatic::$Memory::Free( pointer );
}
/*
void operator delete (PVOID pointer $not_null, $CI_REF ) $fatal_error_on_failure $not_implemented
{
   $NOT_IMPLEMENTED_FAILURE();
}
*/
void operator delete[] (PVOID pointer $not_null) $fatal_error_on_failure
{
   $$VERIFY_POINTER_ARG_( pointer );
   RuntimeForStatic::$Memory::Free( pointer );
}
/*
void operator delete[] (PVOID pointer $not_null, $CI_REF ) $fatal_error_on_failure $not_implemented
{
   $NOT_IMPLEMENTED_FAILURE();
}
*/
//==================================================================================================

static PVOID Allocate(SIZE_T size, $CI_REF $required ) $null_on_failure
{
///*
   if ( !size )
      $INCORRECT_ARGUMENT_WITH_MESSAGE( size, $TEXT(
         L"Requested allocation size for operator new must not be equal to zero.",
         L"Запрашиваемый размер памяти для оператора new не должен равняться нулю." ));
//*/
   if ( size > INT_MAX )
      $INCORRECT_ARGUMENT_WITH_MESSAGE_1( size, $TEXT(
         L"Requested allocation size for operator new must not be greater than %d byte(s) "
         L"(INT_MAX).",
         L"Запрашиваемый размер памяти для оператора new не должен превышать %d байта(ов) "
         L"(INT_MAX)."
      ), INT_MAX );
#ifdef _DEBUG
   return std::_malloc_dbg( size, $ALLOCATION_BLOCK, $ci.SourceFileA, $ci.LineNo );
#else
   return std::malloc( size );
#endif // _DEBUG
}

//==================================================================================================
