diff options
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | config/CMakeLists.txt | 4 | ||||
-rw-r--r-- | config/config.h.in | 5 | ||||
-rw-r--r-- | src/nvim/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/nvim/memory.c | 18 | ||||
-rw-r--r-- | src/nvim/version.c | 20 | ||||
-rw-r--r-- | third-party/cmake/BuildJeMalloc.cmake | 4 |
7 files changed, 36 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fe58ca6dc6..5e176a540d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,23 +201,14 @@ include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS}) option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF) if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang") - message(WARNING "SANITIZE is only supported for Clang ... disabling") + message(WARNING "SANITIZE is only supported for Clang, disabling") set(SANITIZE OFF) endif() -if(SANITIZE) - option(USE_JEMALLOC "Use jemalloc" OFF) -else() - option(USE_JEMALLOC "Use jemalloc" ON) -endif() - -if(USE_JEMALLOC) +if(NOT SANITIZE) find_package(JeMalloc) if(JEMALLOC_FOUND) - message(STATUS "Using jemalloc instead of libc allocator") include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS}) - else() - set(USE_JEMALLOC OFF) endif() endif() diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index ed1f422070..cdf31a8966 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -46,6 +46,10 @@ if(Iconv_FOUND) set(HAVE_ICONV 1) endif() +if(JEMALLOC_FOUND) + set(HAVE_JEMALLOC 1) +endif() + check_function_exists(lstat HAVE_LSTAT) if(NOT HAVE_LSTAT) # os_unix.c uses lstat.c diff --git a/config/config.h.in b/config/config.h.in index 9b2abfa19d..0419451e26 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -66,6 +66,9 @@ #define FEAT_BROWSE #define FEAT_CSCOPE #define FEAT_MOUSE -#cmakedefine USE_JEMALLOC + +#ifndef UNIT_TESTING +#cmakedefine HAVE_JEMALLOC +#endif #endif // AUTO_CONFIG_H diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index fa1f81cdd1..810809ea17 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -171,8 +171,8 @@ list(APPEND NVIM_LINK_LIBRARIES set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES}) -if(USE_JEMALLOC) - # dont use jemalloc in the unit test library +# Don't use jemalloc in the unit test library. +if(JEMALLOC_FOUND) list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES}) endif() diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 2d4259a238..8628661a98 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -14,16 +14,18 @@ #include "nvim/misc1.h" #include "nvim/ui.h" -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "memory.c.generated.h" +#ifdef HAVE_JEMALLOC +// Force je_ prefix on jemalloc functions. +# define JEMALLOC_NO_DEMANGLE +# include <jemalloc/jemalloc.h> +# define malloc(size) je_malloc(size) +# define calloc(count, size) je_calloc(count, size) +# define realloc(ptr, size) je_realloc(ptr, size) +# define free(ptr) je_free(ptr) #endif -#if defined(USE_JEMALLOC) && !defined(UNIT_TESTING) -#include "jemalloc/jemalloc.h" -#define malloc(size) je_malloc(size) -#define calloc(count, size) je_calloc(count, size) -#define realloc(ptr, size) je_realloc(ptr, size) -#define free(ptr) je_free(ptr) +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memory.c.generated.h" #endif /// Try to free memory. Used when trying to recover from out of memory errors. diff --git a/src/nvim/version.c b/src/nvim/version.c index 3ca0b254f4..4b4d28dcc2 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -47,21 +47,25 @@ char *version_cflags = "Compilation: " NVIM_VERSION_CFLAGS; static char *features[] = { #ifdef HAVE_ACL "+acl", -#else // ifdef HAVE_ACL +#else "-acl", -#endif // ifdef HAVE_ACL +#endif #if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) || defined(DYNAMIC_ICONV) # ifdef DYNAMIC_ICONV "+iconv/dyn", -# else // ifdef DYNAMIC_ICONV +# else "+iconv", -# endif // ifdef DYNAMIC_ICONV -#else // if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) - // ||defined(DYNAMIC_ICONV) +# endif +#else "-iconv", -#endif // if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) - // || defined(DYNAMIC_ICONV) +#endif + +#ifdef HAVE_JEMALLOC + "+jemalloc", +#else + "-jemalloc", +#endif NULL }; diff --git a/third-party/cmake/BuildJeMalloc.cmake b/third-party/cmake/BuildJeMalloc.cmake index ceb7de41e9..c3a0d890fc 100644 --- a/third-party/cmake/BuildJeMalloc.cmake +++ b/third-party/cmake/BuildJeMalloc.cmake @@ -11,8 +11,8 @@ ExternalProject_Add(jemalloc -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake BUILD_IN_SOURCE 1 CONFIGURE_COMMAND sh ${DEPS_BUILD_DIR}/src/jemalloc/autogen.sh && - ${DEPS_BUILD_DIR}/src/jemalloc/configure --with-jemalloc-prefix=je_ - --enable-cc-silence CC=${DEPS_C_COMPILER} --prefix=${DEPS_INSTALL_DIR} + ${DEPS_BUILD_DIR}/src/jemalloc/configure --enable-cc-silence + CC=${DEPS_C_COMPILER} --prefix=${DEPS_INSTALL_DIR} BUILD_COMMAND "" INSTALL_COMMAND ${MAKE_PRG} install_include install_lib) |