From b47cfec5d01fd8c848b7539e5b43884257dba613 Mon Sep 17 00:00:00 2001 From: Huisheng Liu Date: Fri, 14 Jun 2019 11:24:02 -0700 Subject: [PATCH] fix compilation error on MSVC (#5458) Summary: "__attribute__((__weak__))" was introduced in port\jemalloc_helper.h. It's not supported by Microsoft VS 2015, resulting in compile error. This fix adds a #if branch to work around the compile issue. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5458 Differential Revision: D15827285 fbshipit-source-id: 8c5f7ad31de1ac677bd96f16c4450767de834beb --- port/jemalloc_helper.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/port/jemalloc_helper.h b/port/jemalloc_helper.h index 0c216face..26e5fb663 100644 --- a/port/jemalloc_helper.h +++ b/port/jemalloc_helper.h @@ -16,6 +16,14 @@ #define JEMALLOC_CXX_THROW #endif +#if defined(OS_WIN) && defined(_MSC_VER) + +// MSVC does not have weak symbol support. As long as ROCKSDB_JEMALLOC is defined, +// Jemalloc memory allocator is used. +static inline bool HasJemalloc() { return true; } + +#else + // Declare non-standard jemalloc APIs as weak symbols. We can null-check these // symbols to detect whether jemalloc is linked with the binary. extern "C" void* mallocx(size_t, int) __attribute__((__weak__)); @@ -50,4 +58,6 @@ static inline bool HasJemalloc() { malloc_stats_print != nullptr && malloc_usable_size != nullptr; } +#endif + #endif // ROCKSDB_JEMALLOC