[libcxx-commits] [libcxx] [libc++][NFC] Refactor the core logic of operator new into helper functions (PR #69407)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 18 02:35:47 PDT 2023
================
@@ -20,30 +20,34 @@
// in this shared library, so that they can be overridden by programs
// that define non-weak copies of the functions.
-_LIBCPP_WEAK
-void *
-operator new(std::size_t size) _THROW_BAD_ALLOC
-{
+static void* operator_new_impl(std::size_t size) noexcept {
if (size == 0)
size = 1;
void* p;
- while ((p = std::malloc(size)) == nullptr)
- {
+ while ((p = std::malloc(size)) == nullptr) {
// If malloc fails and there is a new_handler,
// call it to try free up memory.
std::new_handler nh = std::get_new_handler();
if (nh)
nh();
else
-#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
- throw std::bad_alloc();
-#else
break;
-#endif
}
return p;
}
+_LIBCPP_WEAK
----------------
philnik777 wrote:
Might as-well clang-format this?
https://github.com/llvm/llvm-project/pull/69407
More information about the libcxx-commits
mailing list