Compare commits

...

5 commits

Author SHA1 Message Date
Eduard Voronkin
453eb34f8e
Merge fd5ab9f1f3 into fae61ed946 2025-04-14 10:09:15 +02:00
Daan
fae61ed946 fix assertion in mi_free_size (issue #754) 2025-04-13 19:56:49 -07:00
Daan
a5298dd48f Merge remote-tracking branch 'refs/remotes/origin/dev' into dev 2025-04-13 19:50:59 -07:00
Daan
7543e8989a validate pointer before assertion in mi_free_size (issue #754) 2025-04-13 19:49:47 -07:00
Eduard Voronkin
fd5ab9f1f3 fix new/delete overrides
apparently, even if MI_USE_CXX is OFF, mimalloc still provides mangled definitions of new/delete operators. It causes inability to statically link mimaloc in our scenario, since we want to have our own overrides of new/delete functions.
2024-11-06 12:02:22 -08:00
2 changed files with 6 additions and 3 deletions

View file

@ -189,9 +189,8 @@ typedef void* mi_nothrow_t;
void* operator new[]( std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); } void* operator new[]( std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); }
void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); } void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); } void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
#endif
#elif (defined(__GNUC__) || defined(__clang__)) #elif (defined(__GNUC__) || defined(__clang__))
// ------------------------------------------------------ // ------------------------------------------------------
// Override by defining the mangled C++ names of the operators (as // Override by defining the mangled C++ names of the operators (as
// used by GCC and CLang). // used by GCC and CLang).
@ -234,6 +233,7 @@ typedef void* mi_nothrow_t;
#else #else
#error "define overloads for new/delete for this platform (just for performance, can be skipped)" #error "define overloads for new/delete for this platform (just for performance, can be skipped)"
#endif #endif
#endif
#endif // __cplusplus #endif // __cplusplus
// ------------------------------------------------------ // ------------------------------------------------------

View file

@ -340,7 +340,10 @@ mi_decl_nodiscard size_t mi_usable_size(const void* p) mi_attr_noexcept {
void mi_free_size(void* p, size_t size) mi_attr_noexcept { void mi_free_size(void* p, size_t size) mi_attr_noexcept {
MI_UNUSED_RELEASE(size); MI_UNUSED_RELEASE(size);
mi_assert(p == NULL || size <= _mi_usable_size(p,"mi_free_size")); #if MI_DEBUG
const size_t available = _mi_usable_size(p,"mi_free_size");
mi_assert(p == NULL || size <= available || available == 0 /* invalid pointer */ );
#endif
mi_free(p); mi_free(p);
} }