Chromium Code Reviews| Index: base/allocator/tcmalloc_unittest.cc |
| diff --git a/base/allocator/tcmalloc_unittest.cc b/base/allocator/tcmalloc_unittest.cc |
| index 37c0ef61eff7dd2744cbd1c257c56af97c260495..5313bfdf65270f45db2d98783a3cf34286c06ea6 100644 |
| --- a/base/allocator/tcmalloc_unittest.cc |
| +++ b/base/allocator/tcmalloc_unittest.cc |
| @@ -5,28 +5,27 @@ |
| #include <stddef.h> |
| #include <stdio.h> |
| +#include "base/compiler_specific.h" |
| #include "base/logging.h" |
| #include "base/process/process_metrics.h" |
| #include "build/build_config.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #if defined(USE_TCMALLOC) |
| -extern "C" { |
| -void* tc_malloc(size_t size); |
| -void tc_free(void*); |
| -} |
| - |
| namespace { |
| using std::min; |
| #ifdef NDEBUG |
| -void* TCMallocDoMallocForTest(size_t size) { |
| - return tc_malloc(size); |
| +// We wrap malloc and free in noinline functions to ensure that we test the real |
| +// implementation of the allocator. Otherwise, the compiler may specifically |
| +// recognize the calls to malloc and free in our tests and optimize them away. |
| +NOINLINE void* TCMallocDoMallocForTest(size_t size) { |
|
Primiano Tucci (use gerrit)
2016/06/01 20:29:06
Oh, I would have never thought to this. right.
|
| + return malloc(size); |
| } |
| -void TCMallocDoFreeForTest(void* ptr) { |
| - tc_free(ptr); |
| +NOINLINE void TCMallocDoFreeForTest(void* ptr) { |
| + free(ptr); |
| } |
| #endif |