Skip to content

Commit 80e4cca

Browse files
committed
[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
1 parent 77f8f40 commit 80e4cca

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

libcxx/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(LIBCXX_SOURCES
3535
mutex.cpp
3636
mutex_destructor.cpp
3737
new.cpp
38+
new_handler.cpp
3839
optional.cpp
3940
random_shuffle.cpp
4041
ryu/d2fixed.cpp
@@ -52,7 +53,6 @@ set(LIBCXX_SOURCES
5253
support/runtime/exception_pointer_glibcxx.ipp
5354
support/runtime/exception_pointer_msvc.ipp
5455
support/runtime/exception_pointer_unimplemented.ipp
55-
support/runtime/new_handler_fallback.ipp
5656
support/runtime/stdexcept_default.ipp
5757
support/runtime/stdexcept_vcruntime.ipp
5858
system_error.cpp

libcxx/src/new.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@
1010
#include <new>
1111
#include <stdlib.h>
1212

13-
#include "include/atomic_support.h"
14-
15-
#if defined(_LIBCPP_ABI_MICROSOFT)
16-
# if !defined(_LIBCPP_ABI_VCRUNTIME)
17-
# include "support/runtime/new_handler_fallback.ipp"
18-
# endif
19-
#elif defined(LIBCXX_BUILDING_LIBCXXABI)
20-
# include <cxxabi.h>
21-
#elif defined(LIBCXXRT)
22-
# include <cxxabi.h>
23-
# include "support/runtime/new_handler_fallback.ipp"
24-
#elif defined(__GLIBCXX__)
25-
// nothing to do
26-
#else
27-
# include "support/runtime/new_handler_fallback.ipp"
28-
#endif
29-
3013
namespace std
3114
{
3215

libcxx/src/support/runtime/new_handler_fallback.ipp renamed to libcxx/src/new_handler.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- C++ -*-
21
//===----------------------------------------------------------------------===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,7 +6,27 @@
76
//
87
//===----------------------------------------------------------------------===//
98

10-
namespace std {
9+
#include <new>
10+
11+
#include "include/atomic_support.h"
12+
13+
#if defined(_LIBCPP_ABI_MICROSOFT)
14+
# if !defined(_LIBCPP_ABI_VCRUNTIME)
15+
# define _LIBPCPP_DEFINE_NEW_HANDLER
16+
# endif
17+
#elif defined(LIBCXX_BUILDING_LIBCXXABI)
18+
// nothing to do, we use the one from libc++abi
19+
#elif defined(LIBCXXRT)
20+
# define _LIBPCPP_DEFINE_NEW_HANDLER
21+
#elif defined(__GLIBCXX__)
22+
// nothing to do, we use the one from libstdc++/libsupc++
23+
#else
24+
# define _LIBPCPP_DEFINE_NEW_HANDLER
25+
#endif
26+
27+
#if defined(_LIBPCPP_DEFINE_NEW_HANDLER)
28+
29+
namespace std { // purposefully not versioned
1130

1231
static constinit std::new_handler __new_handler = nullptr;
1332

@@ -24,3 +43,5 @@ get_new_handler() noexcept
2443
}
2544

2645
} // namespace std
46+
47+
#endif // _LIBPCPP_DEFINE_NEW_HANDLER

libcxx/utils/data/ignore_format.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ libcxx/src/memory.cpp
809809
libcxx/src/mutex.cpp
810810
libcxx/src/mutex_destructor.cpp
811811
libcxx/src/new.cpp
812+
libcxx/src/new_handler.cpp
812813
libcxx/src/optional.cpp
813814
libcxx/src/random.cpp
814815
libcxx/src/random_shuffle.cpp
@@ -830,7 +831,6 @@ libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
830831
libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
831832
libcxx/src/support/runtime/exception_pointer_msvc.ipp
832833
libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
833-
libcxx/src/support/runtime/new_handler_fallback.ipp
834834
libcxx/src/support/runtime/stdexcept_default.ipp
835835
libcxx/src/support/runtime/stdexcept_vcruntime.ipp
836836
libcxx/src/support/win32/locale_win32.cpp

0 commit comments

Comments
 (0)