[C++]
authorThomas Faber <thomas.faber@reactos.org>
Tue, 5 May 2015 02:44:17 +0000 (02:44 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 5 May 2015 02:44:17 +0000 (02:44 +0000)
- Add nothrow versions of new/delete operators
- Add <cassert>
- Fix a TODO and add missing dependency to <exception> header

svn path=/trunk/; revision=67555

reactos/include/c++/cassert [new file with mode: 0644]
reactos/include/c++/exception
reactos/lib/sdk/cpprt/CMakeLists.txt
reactos/lib/sdk/cpprt/i386/cpprt.s
reactos/lib/sdk/cpprt/new_nothrow.cpp [new file with mode: 0644]
reactos/lib/sdk/cpprt/typeinfo.cpp

diff --git a/reactos/include/c++/cassert b/reactos/include/c++/cassert
new file mode 100644 (file)
index 0000000..e7b0b74
--- /dev/null
@@ -0,0 +1,5 @@
+// C++ forwarding C assert header.
+
+#pragma once
+
+#include <assert.h>
index 76af754..a99775c 100644 (file)
@@ -3,6 +3,8 @@
 #ifndef __EXCEPTION__\r
 #define __EXCEPTION__\r
 \r
+#include <crtdefs.h>\r
+\r
 extern "C++" {\r
 \r
 class exception\r
index eb2947d..338265b 100644 (file)
@@ -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")
index f5fe642..cfc3dc9 100644 (file)
@@ -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 (file)
index 0000000..2ba640f
--- /dev/null
@@ -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 <new>
+
+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;
+    }
+}
index ac03b2d..09a18fc 100644 (file)
@@ -5,14 +5,7 @@
  * PROGRAMMER:      Thomas Faber (thomas.faber@reactos.org)
  */
 
-/* TODO: #include <exception> instead */
-class type_info {
-public:
-    __declspec(dllimport) virtual ~type_info();
-private:
-    type_info(const type_info &);
-    type_info &operator=(const type_info &);
-};
+#include <typeinfo>
 
 /* 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