From cade8eb7a1fc11a66c210aeabeefd255f22cd0a7 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 11 Jun 2020 00:40:20 +0300 Subject: [PATCH] Add TCMALLOC_NO_NEW_DELETE_OVERRIDES/TCMALLOC_NO_C_ALLOC_OVERRIDES Since sometimes program already overwrites new/delete. --- tcmalloc/libc_override_gcc_and_weak.h | 4 ++++ tcmalloc/tcmalloc.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tcmalloc/libc_override_gcc_and_weak.h b/tcmalloc/libc_override_gcc_and_weak.h index 3954424b5..51fc3149e 100644 --- a/tcmalloc/libc_override_gcc_and_weak.h +++ b/tcmalloc/libc_override_gcc_and_weak.h @@ -36,6 +36,7 @@ #define TCMALLOC_ALIAS(tc_fn) \ __attribute__((alias(#tc_fn), visibility("default"))) +#ifndef TCMALLOC_NO_NEW_DELETE_OVERRIDES void* operator new(size_t size) noexcept(false) TCMALLOC_ALIAS(TCMallocInternalNew); void operator delete(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalDelete); @@ -81,7 +82,9 @@ void operator delete[](void* p, std::align_val_t alignment, void operator delete[](void* p, size_t size, std::align_val_t alignemnt) noexcept TCMALLOC_ALIAS(TCMallocInternalDeleteArraySizedAligned); +#endif // \TCMALLOC_NO_NEW_DELETE_OVERRIDES +#ifndef TCMALLOC_NO_C_ALLOC_OVERRIDES extern "C" { void* malloc(size_t size) noexcept TCMALLOC_ALIAS(TCMallocInternalMalloc); void free(void* ptr) noexcept TCMALLOC_ALIAS(TCMallocInternalFree); @@ -109,5 +112,6 @@ size_t malloc_size(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalMallocSize); size_t malloc_usable_size(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalMallocSize); } // extern "C" +#endif // \TCMALLOC_NO_C_ALLOC_OVERRIDES #endif // TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_ diff --git a/tcmalloc/tcmalloc.h b/tcmalloc/tcmalloc.h index d74e421ce..e1a24888b 100644 --- a/tcmalloc/tcmalloc.h +++ b/tcmalloc/tcmalloc.h @@ -24,9 +24,12 @@ #include #include +#include #include "absl/base/attributes.h" +#ifndef TCMALLOC_NO_NEW_DELETE_OVERRIDES #include "tcmalloc/internal/declarations.h" +#endif // __THROW is defined in glibc systems. It means, counter-intuitively, // "This function will never throw an exception." It's an optional