Skip to content

Commit 04222ef

Browse files
committed
Add TCMALLOC_NO_NEW_DELETE_OVERRIDES/TCMALLOC_NO_C_ALLOC_OVERRIDES
Since sometimes program already overwrites new/delete.
1 parent 8738f27 commit 04222ef

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

tcmalloc/libc_override_gcc_and_weak.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define TCMALLOC_ALIAS(tc_fn) \
3737
__attribute__((alias(#tc_fn), visibility("default")))
3838

39+
#ifndef TCMALLOC_NO_NEW_DELETE_OVERRIDES
3940
void* operator new(size_t size) noexcept(false)
4041
TCMALLOC_ALIAS(TCMallocInternalNew);
4142
void operator delete(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalDelete);
@@ -81,7 +82,9 @@ void operator delete[](void* p, std::align_val_t alignment,
8182
void operator delete[](void* p, size_t size,
8283
std::align_val_t alignemnt) noexcept
8384
TCMALLOC_ALIAS(TCMallocInternalDeleteArraySizedAligned);
85+
#endif // \TCMALLOC_NO_NEW_DELETE_OVERRIDES
8486

87+
#ifndef TCMALLOC_NO_C_ALLOC_OVERRIDES
8588
extern "C" {
8689
void* malloc(size_t size) noexcept TCMALLOC_ALIAS(TCMallocInternalMalloc);
8790
void free(void* ptr) noexcept TCMALLOC_ALIAS(TCMallocInternalFree);
@@ -109,5 +112,6 @@ size_t malloc_size(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalMallocSize);
109112
size_t malloc_usable_size(void* p) noexcept
110113
TCMALLOC_ALIAS(TCMallocInternalMallocSize);
111114
} // extern "C"
115+
#endif // \TCMALLOC_NO_C_ALLOC_OVERRIDES
112116

113117
#endif // TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_

tcmalloc/tcmalloc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424

2525
#include <malloc.h>
2626
#include <stddef.h>
27+
#include <new>
2728

2829
#include "absl/base/attributes.h"
30+
#ifndef TCMALLOC_NO_NEW_DELETE_OVERRIDES
2931
#include "tcmalloc/internal/declarations.h"
32+
#endif
3033

3134
// __THROW is defined in glibc systems. It means, counter-intuitively,
3235
// "This function will never throw an exception." It's an optional

0 commit comments

Comments
 (0)