From: Pieter Noordhuis Date: Sat, 23 Oct 2010 07:59:28 +0000 (+0200) Subject: Don't use prefix when malloc_size() can be called X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/7cdc98b6305bb65aee5f5973e8123246755dac7d?hp=da47440d444cfe023f339e0f7d6056101a332a48 Don't use prefix when malloc_size() can be called Also, use tcmalloc functions explicitly via macros to prevent symbol lookups to resolve to native malloc/free on OSX. --- diff --git a/src/config.h b/src/config.h index e2d84818..62f808f5 100644 --- a/src/config.h +++ b/src/config.h @@ -5,8 +5,17 @@ #include #endif -/* test for malloc_size() */ -#ifdef __APPLE__ +/* use tcmalloc's malloc_size() when available */ +#if defined(USE_TCMALLOC) +#include +#if TC_VERSION_MAJOR >= 1 && TC_VERSION_MINOR >= 6 +#define HAVE_MALLOC_SIZE 1 +#define redis_malloc_size(p) tc_malloc_size(p) +#endif +#endif + +/* fallback to native malloc_size() for osx */ +#if defined(__APPLE__) && !defined(HAVE_MALLOC_SIZE) #include #define HAVE_MALLOC_SIZE 1 #define redis_malloc_size(p) malloc_size(p) diff --git a/src/zmalloc.c b/src/zmalloc.c index 544155e7..8cfb18d9 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -32,13 +32,24 @@ #include #include #include - #include "config.h" +#ifdef HAVE_MALLOC_SIZE +#define PREFIX_SIZE (0) +#else #if defined(__sun) -#define PREFIX_SIZE sizeof(long long) +#define PREFIX_SIZE (sizeof(long long)) #else -#define PREFIX_SIZE sizeof(size_t) +#define PREFIX_SIZE (sizeof(size_t)) +#endif +#endif + +/* Explicitly override malloc/free etc when using tcmalloc. */ +#if defined(USE_TCMALLOC) +#define malloc(size) tc_malloc(size) +#define calloc(count,size) tc_calloc(count,size) +#define realloc(ptr,size) tc_realloc(ptr,size) +#define free(ptr) tc_free(ptr) #endif #define increment_used_memory(__n) do { \