From 6e72d71daad1cc42d3fb5af5bb5ff1ad6dca172f Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Tue, 5 May 2015 02:44:17 +0000 Subject: [PATCH] [C++] - Add nothrow versions of new/delete operators - Add - Fix a TODO and add missing dependency to header svn path=/trunk/; revision=67555 --- reactos/include/c++/cassert | 5 ++++ reactos/include/c++/exception | 2 ++ reactos/lib/sdk/cpprt/CMakeLists.txt | 5 +++- reactos/lib/sdk/cpprt/i386/cpprt.s | 6 +++++ reactos/lib/sdk/cpprt/new_nothrow.cpp | 37 +++++++++++++++++++++++++++ reactos/lib/sdk/cpprt/typeinfo.cpp | 9 +------ 6 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 reactos/include/c++/cassert create mode 100644 reactos/lib/sdk/cpprt/new_nothrow.cpp diff --git a/reactos/include/c++/cassert b/reactos/include/c++/cassert new file mode 100644 index 00000000000..e7b0b74362a --- /dev/null +++ b/reactos/include/c++/cassert @@ -0,0 +1,5 @@ +// C++ forwarding C assert header. + +#pragma once + +#include diff --git a/reactos/include/c++/exception b/reactos/include/c++/exception index 76af754457d..a99775c6e2c 100644 --- a/reactos/include/c++/exception +++ b/reactos/include/c++/exception @@ -3,6 +3,8 @@ #ifndef __EXCEPTION__ #define __EXCEPTION__ +#include + extern "C++" { class exception diff --git a/reactos/lib/sdk/cpprt/CMakeLists.txt b/reactos/lib/sdk/cpprt/CMakeLists.txt index eb2947d756d..338265bd99a 100644 --- a/reactos/lib/sdk/cpprt/CMakeLists.txt +++ b/reactos/lib/sdk/cpprt/CMakeLists.txt @@ -1,10 +1,13 @@ set_cpp(WITH_EXCEPTIONS) -include_directories(${REACTOS_SOURCE_DIR}/lib/sdk/crt/include) +include_directories( + ${REACTOS_SOURCE_DIR}/lib/sdk/crt/include + ${REACTOS_SOURCE_DIR}/include/c++) list(APPEND SOURCE ehvec.cpp + new_nothrow.cpp typeinfo.cpp) if(ARCH STREQUAL "i386") diff --git a/reactos/lib/sdk/cpprt/i386/cpprt.s b/reactos/lib/sdk/cpprt/i386/cpprt.s index f5fe642b095..cfc3dc9e9cf 100644 --- a/reactos/lib/sdk/cpprt/i386/cpprt.s +++ b/reactos/lib/sdk/cpprt/i386/cpprt.s @@ -39,4 +39,10 @@ DEFINE_ALIAS ??_M@YGXPAXIIP6EX0@Z@Z, ?MSVCRTEX_eh_vector_destructor_iterator@@YG ; void __cdecl operator delete(void *,unsigned int) DEFINE_ALIAS ??3@YAXPAXI@Z, ??3@YAXPAX@Z +; void __cdecl operator delete(void *,struct std::nothrow_t const &) +DEFINE_ALIAS ??3@YAXPAXABUnothrow_t@std@@@Z, ??3@YAXPAX@Z + +; void __cdecl operator delete[](void *,struct std::nothrow_t const &) +DEFINE_ALIAS ??_V@YAXPAXABUnothrow_t@std@@@Z, ??3@YAXPAX@Z + END diff --git a/reactos/lib/sdk/cpprt/new_nothrow.cpp b/reactos/lib/sdk/cpprt/new_nothrow.cpp new file mode 100644 index 00000000000..2ba640f06a6 --- /dev/null +++ b/reactos/lib/sdk/cpprt/new_nothrow.cpp @@ -0,0 +1,37 @@ +/* + * PROJECT: ReactOS C++ runtime library + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: nothrow version of the new operators + * PROGRAMMER: Thomas Faber (thomas.faber@reactos.org) + */ + +#include + +void* operator new (std::size_t) throw(std::bad_alloc); +void* operator new[] (std::size_t) throw(std::bad_alloc); + +const std::nothrow_t std::nothrow; + +void* operator new (std::size_t size, const std::nothrow_t& nothrow_constant) throw() +{ + try + { + return operator new (size); + } + catch (std::bad_alloc) + { + return NULL; + } +} + +void* operator new[] (std::size_t size, const std::nothrow_t& nothrow_constant) throw() +{ + try + { + return operator new[] (size); + } + catch (std::bad_alloc) + { + return NULL; + } +} diff --git a/reactos/lib/sdk/cpprt/typeinfo.cpp b/reactos/lib/sdk/cpprt/typeinfo.cpp index ac03b2d747c..09a18fcb8b6 100644 --- a/reactos/lib/sdk/cpprt/typeinfo.cpp +++ b/reactos/lib/sdk/cpprt/typeinfo.cpp @@ -5,14 +5,7 @@ * PROGRAMMER: Thomas Faber (thomas.faber@reactos.org) */ -/* TODO: #include instead */ -class type_info { -public: - __declspec(dllimport) virtual ~type_info(); -private: - type_info(const type_info &); - type_info &operator=(const type_info &); -}; +#include /* These stubs don't need to do anything (those private functions are never * called). They need to be in cpprt, though, in order to have the vtable