mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
added RM_Calloc implementation
This commit is contained in:
parent
0b4b7ebd95
commit
dc7f3fefad
11
src/module.c
11
src/module.c
@ -172,11 +172,19 @@ void RM_ZsetRangeStop(RedisModuleKey *key);
|
|||||||
/* Use like malloc(). Memory allocated with this function is reported in
|
/* Use like malloc(). Memory allocated with this function is reported in
|
||||||
* Redis INFO memory, used for keys eviction according to maxmemory settings
|
* Redis INFO memory, used for keys eviction according to maxmemory settings
|
||||||
* and in general is taken into account as memory allocated by Redis.
|
* 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) {
|
void *RM_Alloc(size_t bytes) {
|
||||||
return zmalloc(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(). */
|
/* Use like realloc() for memory obtained with RedisModule_Alloc(). */
|
||||||
void* RM_Realloc(void *ptr, size_t bytes) {
|
void* RM_Realloc(void *ptr, size_t bytes) {
|
||||||
return zrealloc(ptr,bytes);
|
return zrealloc(ptr,bytes);
|
||||||
@ -2791,6 +2799,7 @@ int moduleRegisterApi(const char *funcname, void *funcptr) {
|
|||||||
void moduleRegisterCoreAPI(void) {
|
void moduleRegisterCoreAPI(void) {
|
||||||
server.moduleapi = dictCreate(&moduleAPIDictType,NULL);
|
server.moduleapi = dictCreate(&moduleAPIDictType,NULL);
|
||||||
REGISTER_API(Alloc);
|
REGISTER_API(Alloc);
|
||||||
|
REGISTER_API(Calloc);
|
||||||
REGISTER_API(Realloc);
|
REGISTER_API(Realloc);
|
||||||
REGISTER_API(Free);
|
REGISTER_API(Free);
|
||||||
REGISTER_API(Strdup);
|
REGISTER_API(Strdup);
|
||||||
|
@ -96,9 +96,11 @@ typedef void (*RedisModuleTypeFreeFunc)(void *value);
|
|||||||
|
|
||||||
#define REDISMODULE_API_FUNC(x) (*x)
|
#define REDISMODULE_API_FUNC(x) (*x)
|
||||||
|
|
||||||
|
|
||||||
void *REDISMODULE_API_FUNC(RedisModule_Alloc)(size_t bytes);
|
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_Realloc)(void *ptr, size_t bytes);
|
||||||
void REDISMODULE_API_FUNC(RedisModule_Free)(void *ptr);
|
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);
|
char *REDISMODULE_API_FUNC(RedisModule_Strdup)(const char *str);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_GetApi)(const char *, void *);
|
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);
|
int REDISMODULE_API_FUNC(RedisModule_CreateCommand)(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep);
|
||||||
@ -187,6 +189,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
|
|||||||
void *getapifuncptr = ((void**)ctx)[0];
|
void *getapifuncptr = ((void**)ctx)[0];
|
||||||
RedisModule_GetApi = (int (*)(const char *, void *)) (unsigned long)getapifuncptr;
|
RedisModule_GetApi = (int (*)(const char *, void *)) (unsigned long)getapifuncptr;
|
||||||
REDISMODULE_GET_API(Alloc);
|
REDISMODULE_GET_API(Alloc);
|
||||||
|
REDISMODULE_GET_API(Calloc);
|
||||||
REDISMODULE_GET_API(Free);
|
REDISMODULE_GET_API(Free);
|
||||||
REDISMODULE_GET_API(Realloc);
|
REDISMODULE_GET_API(Realloc);
|
||||||
REDISMODULE_GET_API(Strdup);
|
REDISMODULE_GET_API(Strdup);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user