Skip to content

Commit

Permalink
Add TCMALLOC_NO_NEW_DELETE_OVERRIDES/TCMALLOC_NO_C_ALLOC_OVERRIDES
Browse files Browse the repository at this point in the history
Since sometimes program already overwrites new/delete.
  • Loading branch information
azat committed Jun 20, 2020
1 parent df10c10 commit cade8eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tcmalloc/libc_override_gcc_and_weak.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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_
3 changes: 3 additions & 0 deletions tcmalloc/tcmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

#include <malloc.h>
#include <stddef.h>
#include <new>

#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
Expand Down

0 comments on commit cade8eb

Please sign in to comment.