diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2016-06-23 16:19:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-23 16:19:14 +0200 |
commit | 3a0b776b94eedcaec9e69e2efb1c6ee354de00bd (patch) | |
tree | c1ee30bf143a2153fa2d5358fb9fc7d4be8bf80b | |
parent | c026b5cd3e41aa2bfeb15b34b07bcedd6bced153 (diff) | |
parent | dc7f3fefad5f136c0655734a35ae624758d73845 (diff) | |
download | redis-3a0b776b94eedcaec9e69e2efb1c6ee354de00bd.tar.gz |
Merge pull request #3335 from dvirsky/rm_calloc
added RM_Calloc implementation
-rw-r--r-- | src/module.c | 11 | ||||
-rw-r--r-- | src/redismodule.h | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/module.c b/src/module.c index 13a2f6667..e3603e1d7 100644 --- a/src/module.c +++ b/src/module.c @@ -173,11 +173,19 @@ static void zsetKeyReset(RedisModuleKey *key); /* Use like malloc(). Memory allocated with this function is reported in * Redis INFO memory, used for keys eviction according to maxmemory settings * and in general is taken into account as memory allocated by Redis. - * You should avoid to use malloc(). */ + * You should avoid using malloc(). */ void *RM_Alloc(size_t bytes) { return zmalloc(bytes); } +/* Use like calloc(). Memory allocated with this function is reported in + * Redis INFO memory, used for keys eviction according to maxmemory settings + * and in general is taken into account as memory allocated by Redis. + * You should avoid using calloc() directly. */ +void *RM_Calloc(size_t nmemb, size_t size) { + return zcalloc(nmemb*size); +} + /* Use like realloc() for memory obtained with RedisModule_Alloc(). */ void* RM_Realloc(void *ptr, size_t bytes) { return zrealloc(ptr,bytes); @@ -2861,6 +2869,7 @@ int moduleRegisterApi(const char *funcname, void *funcptr) { void moduleRegisterCoreAPI(void) { server.moduleapi = dictCreate(&moduleAPIDictType,NULL); REGISTER_API(Alloc); + REGISTER_API(Calloc); REGISTER_API(Realloc); REGISTER_API(Free); REGISTER_API(Strdup); diff --git a/src/redismodule.h b/src/redismodule.h index fae0f3d09..f1aaea49b 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -96,9 +96,11 @@ typedef void (*RedisModuleTypeFreeFunc)(void *value); #define REDISMODULE_API_FUNC(x) (*x) + void *REDISMODULE_API_FUNC(RedisModule_Alloc)(size_t bytes); void *REDISMODULE_API_FUNC(RedisModule_Realloc)(void *ptr, size_t bytes); void REDISMODULE_API_FUNC(RedisModule_Free)(void *ptr); +void REDISMODULE_API_FUNC(RedisModule_Calloc)(size_t nmemb, size_t size); char *REDISMODULE_API_FUNC(RedisModule_Strdup)(const char *str); int REDISMODULE_API_FUNC(RedisModule_GetApi)(const char *, void *); int REDISMODULE_API_FUNC(RedisModule_CreateCommand)(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep); @@ -189,6 +191,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int void *getapifuncptr = ((void**)ctx)[0]; RedisModule_GetApi = (int (*)(const char *, void *)) (unsigned long)getapifuncptr; REDISMODULE_GET_API(Alloc); + REDISMODULE_GET_API(Calloc); REDISMODULE_GET_API(Free); REDISMODULE_GET_API(Realloc); REDISMODULE_GET_API(Strdup); |