diff options
Diffstat (limited to 'alloc.h')
-rw-r--r-- | alloc.h | 50 |
1 files changed, 44 insertions, 6 deletions
@@ -31,23 +31,61 @@ #ifndef HIREDIS_ALLOC_H #define HIREDIS_ALLOC_H -#include <stdlib.h> /* for size_t */ - -#ifndef HIREDIS_OOM_HANDLER -#define HIREDIS_OOM_HANDLER abort() -#endif +#include <stddef.h> /* for size_t */ #ifdef __cplusplus extern "C" { #endif +/* Structure pointing to our actually configured allocators */ +typedef struct hiredisAllocFuncs { + void *(*malloc)(size_t); + void *(*calloc)(size_t,size_t); + void *(*realloc)(void*,size_t); + char *(*strdup)(const char*); + void (*free)(void*); +} hiredisAllocFuncs; + +hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha); +void hiredisResetAllocators(void); + +#ifndef _WIN32 + +/* Hiredis' configured allocator function pointer struct */ +extern hiredisAllocFuncs hiredisAllocFns; + +static inline void *hi_malloc(size_t size) { + return hiredisAllocFns.malloc(size); +} + +static inline void *hi_calloc(size_t nmemb, size_t size) { + return hiredisAllocFns.calloc(nmemb, size); +} + +static inline void *hi_realloc(void *ptr, size_t size) { + return hiredisAllocFns.realloc(ptr, size); +} + +static inline char *hi_strdup(const char *str) { + return hiredisAllocFns.strdup(str); +} + +static inline void hi_free(void *ptr) { + hiredisAllocFns.free(ptr); +} + +#else + void *hi_malloc(size_t size); void *hi_calloc(size_t nmemb, size_t size); void *hi_realloc(void *ptr, size_t size); char *hi_strdup(const char *str); +void hi_free(void *ptr); + +#endif #ifdef __cplusplus } #endif -#endif /* HIREDIS_ALLOC_H */ +#endif /* HIREDIS_ALLOC_H */ |