123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #ifndef HIREDIS_ALLOC_H
- #define HIREDIS_ALLOC_H
- #include <stddef.h> /* for size_t */
- #include <stdint.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct hiredisAllocFuncs {
- void *(*mallocFn)(size_t);
- void *(*callocFn)(size_t,size_t);
- void *(*reallocFn)(void*,size_t);
- char *(*strdupFn)(const char*);
- void (*freeFn)(void*);
- } hiredisAllocFuncs;
- hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha);
- void hiredisResetAllocators(void);
- #ifndef _WIN32
- extern hiredisAllocFuncs hiredisAllocFns;
- static inline void *hi_malloc(size_t size) {
- return hiredisAllocFns.mallocFn(size);
- }
- static inline void *hi_calloc(size_t nmemb, size_t size) {
-
- if (SIZE_MAX / size < nmemb)
- return NULL;
- return hiredisAllocFns.callocFn(nmemb, size);
- }
- static inline void *hi_realloc(void *ptr, size_t size) {
- return hiredisAllocFns.reallocFn(ptr, size);
- }
- static inline char *hi_strdup(const char *str) {
- return hiredisAllocFns.strdupFn(str);
- }
- static inline void hi_free(void *ptr) {
- hiredisAllocFns.freeFn(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
|