Skip to content

Commit

Permalink
Make operators new and delete weak symbols by default
Browse files Browse the repository at this point in the history
Signed-off-by: delphi <[email protected]>
  • Loading branch information
asmfreak authored and salkinium committed Oct 14, 2021
1 parent 2ef7a29 commit fb0c97b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ext/gcc/new_delete.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,40 @@ new_assert(size_t size)
}

// ----------------------------------------------------------------------------
modm_weak
void* operator new (std::size_t size) { return new_assert<false>(size); }
modm_weak
void* operator new[](std::size_t size) { return new_assert<false>(size); }

modm_weak
void* operator new (std::size_t size, const std::nothrow_t&) noexcept { return malloc(size); }
modm_weak
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept { return malloc(size); }

%% if with_memory_traits
modm_weak
void* operator new (std::size_t size, modm::MemoryTraits traits) { return new_assert<true>(size, traits); }
modm_weak
void* operator new[](std::size_t size, modm::MemoryTraits traits) { return new_assert<true>(size, traits); }

modm_weak
void* operator new (std::size_t size, modm::MemoryTraits traits, const std::nothrow_t&) noexcept { return malloc_traits(size, traits.value); }
modm_weak
void* operator new[](std::size_t size, modm::MemoryTraits traits, const std::nothrow_t&) noexcept { return malloc_traits(size, traits.value); }
%% endif

// ----------------------------------------------------------------------------
modm_weak
void operator delete (void *ptr) noexcept { free(ptr); }
modm_weak
void operator delete[](void* ptr) noexcept { free(ptr); }

modm_weak
void operator delete (void* ptr, std::size_t) noexcept { free(ptr); }
modm_weak
void operator delete[](void* ptr, std::size_t) noexcept { free(ptr); }

modm_weak
void operator delete (void* ptr, const std::nothrow_t&) noexcept { free(ptr); }
modm_weak
void operator delete[](void* ptr, const std::nothrow_t&) noexcept { free(ptr); }

0 comments on commit fb0c97b

Please sign in to comment.