[libcxx-commits] [libcxx] 80e4cca - [libc++] Move the definition of std::new_handler out of new.cpp

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 15 08:14:21 PDT 2023


Author: Louis Dionne
Date: 2023-06-15T11:14:14-04:00
New Revision: 80e4ccab794c81a7cb3e052cb4e0d85ba66158a0

URL: https://github.com/llvm/llvm-project/commit/80e4ccab794c81a7cb3e052cb4e0d85ba66158a0
DIFF: https://github.com/llvm/llvm-project/commit/80e4ccab794c81a7cb3e052cb4e0d85ba66158a0.diff

LOG: [libc++] Move the definition of std::new_handler out of new.cpp

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

Added: 
    libcxx/src/new_handler.cpp

Modified: 
    libcxx/src/CMakeLists.txt
    libcxx/src/new.cpp
    libcxx/utils/data/ignore_format.txt

Removed: 
    libcxx/src/support/runtime/new_handler_fallback.ipp


################################################################################
diff  --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 21cc9a50096c9..358a61e4a0351 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -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

diff  --git a/libcxx/src/new.cpp b/libcxx/src/new.cpp
index 3c3d1dc7f56b6..923b3dbdc273d 100644
--- a/libcxx/src/new.cpp
+++ b/libcxx/src/new.cpp
@@ -10,23 +10,6 @@
 #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
 {
 

diff  --git a/libcxx/src/support/runtime/new_handler_fallback.ipp b/libcxx/src/new_handler.cpp
similarity index 52%
rename from libcxx/src/support/runtime/new_handler_fallback.ipp
rename to libcxx/src/new_handler.cpp
index 2ec408327d64d..37cde7a8f149b 100644
--- a/libcxx/src/support/runtime/new_handler_fallback.ipp
+++ b/libcxx/src/new_handler.cpp
@@ -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

diff  --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt
index 4da365b1ac9ad..48d7bebf343ff 100644
--- a/libcxx/utils/data/ignore_format.txt
+++ b/libcxx/utils/data/ignore_format.txt
@@ -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


        


More information about the libcxx-commits mailing list