[libc++] Move the definition of std::new_handler out of new.cpp
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 14 Jun 2023 20:37:57 +0000 (13:37 -0700)
committerLouis Dionne <ldionne.2@gmail.com>
Thu, 15 Jun 2023 15:14:14 +0000 (11:14 -0400)
This reduces the difference between libc++'s new.cpp and libc++abi's
stdlib_new_delete.cpp files, which are essentially copies of each other.

Differential Revision: https://reviews.llvm.org/D152956

libcxx/src/CMakeLists.txt
libcxx/src/new.cpp
libcxx/src/new_handler.cpp [moved from libcxx/src/support/runtime/new_handler_fallback.ipp with 52% similarity]
libcxx/utils/data/ignore_format.txt

index 21cc9a5..358a61e 100644 (file)
@@ -35,6 +35,7 @@ set(LIBCXX_SOURCES
   mutex.cpp
   mutex_destructor.cpp
   new.cpp
+  new_handler.cpp
   optional.cpp
   random_shuffle.cpp
   ryu/d2fixed.cpp
@@ -52,7 +53,6 @@ set(LIBCXX_SOURCES
   support/runtime/exception_pointer_glibcxx.ipp
   support/runtime/exception_pointer_msvc.ipp
   support/runtime/exception_pointer_unimplemented.ipp
-  support/runtime/new_handler_fallback.ipp
   support/runtime/stdexcept_default.ipp
   support/runtime/stdexcept_vcruntime.ipp
   system_error.cpp
index 3c3d1dc..923b3db 100644 (file)
 #include <new>
 #include <stdlib.h>
 
-#include "include/atomic_support.h"
-
-#if defined(_LIBCPP_ABI_MICROSOFT)
-#   if !defined(_LIBCPP_ABI_VCRUNTIME)
-#       include "support/runtime/new_handler_fallback.ipp"
-#   endif
-#elif defined(LIBCXX_BUILDING_LIBCXXABI)
-#   include <cxxabi.h>
-#elif defined(LIBCXXRT)
-#   include <cxxabi.h>
-#   include "support/runtime/new_handler_fallback.ipp"
-#elif defined(__GLIBCXX__)
-    // nothing to do
-#else
-#   include "support/runtime/new_handler_fallback.ipp"
-#endif
-
 namespace std
 {
 
similarity index 52%
rename from libcxx/src/support/runtime/new_handler_fallback.ipp
rename to libcxx/src/new_handler.cpp
index 2ec4083..37cde7a 100644 (file)
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,7 +6,27 @@
 //
 //===----------------------------------------------------------------------===//
 
-namespace std {
+#include <new>
+
+#include "include/atomic_support.h"
+
+#if defined(_LIBCPP_ABI_MICROSOFT)
+#   if !defined(_LIBCPP_ABI_VCRUNTIME)
+#       define _LIBPCPP_DEFINE_NEW_HANDLER
+#   endif
+#elif defined(LIBCXX_BUILDING_LIBCXXABI)
+    // nothing to do, we use the one from libc++abi
+#elif defined(LIBCXXRT)
+#   define _LIBPCPP_DEFINE_NEW_HANDLER
+#elif defined(__GLIBCXX__)
+    // nothing to do, we use the one from libstdc++/libsupc++
+#else
+#   define _LIBPCPP_DEFINE_NEW_HANDLER
+#endif
+
+#if defined(_LIBPCPP_DEFINE_NEW_HANDLER)
+
+namespace std { // purposefully not versioned
 
 static constinit std::new_handler __new_handler = nullptr;
 
@@ -24,3 +43,5 @@ get_new_handler() noexcept
 }
 
 } // namespace std
+
+#endif // _LIBPCPP_DEFINE_NEW_HANDLER
index 4da365b..48d7beb 100644 (file)
@@ -809,6 +809,7 @@ libcxx/src/memory.cpp
 libcxx/src/mutex.cpp
 libcxx/src/mutex_destructor.cpp
 libcxx/src/new.cpp
+libcxx/src/new_handler.cpp
 libcxx/src/optional.cpp
 libcxx/src/random.cpp
 libcxx/src/random_shuffle.cpp
@@ -830,7 +831,6 @@ libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
 libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
 libcxx/src/support/runtime/exception_pointer_msvc.ipp
 libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
-libcxx/src/support/runtime/new_handler_fallback.ipp
 libcxx/src/support/runtime/stdexcept_default.ipp
 libcxx/src/support/runtime/stdexcept_vcruntime.ipp
 libcxx/src/support/win32/locale_win32.cpp