File tree Expand file tree Collapse file tree 4 files changed +29
-7
lines changed
Expand file tree Collapse file tree 4 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 3232#endif
3333
3434#if defined(_LIBCPP_ABI_VCRUNTIME)
35- # include < new .h>
35+ #include < vcruntime_new .h>
3636#else
3737[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void * operator new (std::size_t __sz) _THROW_BAD_ALLOC;
3838[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void * operator new (std::size_t __sz, const std::nothrow_t &) _NOEXCEPT
Original file line number Diff line number Diff line change 1616#endif
1717
1818#if defined(_LIBCPP_ABI_VCRUNTIME )
19- # include <new .h>
19+ #include <vcruntime_new .h>
2020#else
2121_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2222struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
Original file line number Diff line number Diff line change 1717#endif
1818
1919#if defined(_LIBCPP_ABI_VCRUNTIME)
20- # include < new .h>
20+ #include < vcruntime_new .h>
2121#else
2222[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void *
2323operator new (std::size_t , void * __p) _NOEXCEPT {
Original file line number Diff line number Diff line change 2424
2525#if defined(_LIBPCPP_DEFINE_NEW_HANDLER)
2626
27- namespace std { // purposefully not versioned
28-
2927static constinit std::new_handler __new_handler = nullptr ;
3028
31- new_handler set_new_handler (new_handler handler) noexcept { return __libcpp_atomic_exchange (&__new_handler, handler); }
29+ #ifdef _LIBCPP_ABI_VCRUNTIME
30+ // to avoid including <new.h>
31+ using _new_h = int (__cdecl*)(size_t );
32+ extern " C" _new_h __cdecl _set_new_handler (_new_h);
33+
34+ namespace {
35+ // adapter for _callnewh
36+ int __cdecl _new_handler_adapter (size_t ) {
37+ std::__libcpp_atomic_load (&__new_handler)();
38+ return 1 ;
39+ }
40+ }
41+ #endif
42+
43+ namespace std { // purposefully not versioned
44+
45+ new_handler set_new_handler (new_handler handler) noexcept {
46+ #ifdef _LIBCPP_ABI_VCRUNTIME
47+ auto old = __libcpp_atomic_exchange (&__new_handler, handler);
48+ _set_new_handler (handler ? _new_handler_adapter: nullptr );
49+ return old;
50+ #else
51+ return __libcpp_atomic_exchange (&__new_handler, handler);
52+ #endif
53+ }
3254
33- new_handler get_new_handler () noexcept { return __libcpp_atomic_load (&__new_handler); }
55+ new_handler get_new_handler () noexcept {return __libcpp_atomic_load (&__new_handler);}
3456
3557} // namespace std
3658
You can’t perform that action at this time.
0 commit comments