Commit 85919f80 authored by antirez's avatar antirez
Browse files

Modules: avoid conflict between modules func pointers and dynamic symbols.

In modules we fill a set of function pointers defined in redismodule.h,
populating a set of APIs that are callable from the module. We use this
manual process instead of resorting to dynamic linking so that we have
exact control on how we pass the API to the module, and we can even pass
different functions for the same name, depending on the API version
declared by the module.

However if the function pointers in redismodule.h and the functions
defined in module.c have the same name, they conflict since the core
exports the symbols to the module.

There is probably some compiler flags trick to avoid this, but in order
to be safer in the future and be more easily compatible with different
builidng systems, this commit changes the internal function prefix from
RedisModule_ to RM_, so for example:

    RM_StringSet() will be exported as RedisModule_StringSet()
parent 60204694
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define REDISMODULE_H #define REDISMODULE_H
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h>
/* ---------------- Defines common between core and modules --------------- */ /* ---------------- Defines common between core and modules --------------- */
...@@ -98,7 +99,7 @@ int REDISMODULE_API_FUNC(RedisModule_StringTruncate)(RedisModuleKey *key, size_t ...@@ -98,7 +99,7 @@ int REDISMODULE_API_FUNC(RedisModule_StringTruncate)(RedisModuleKey *key, size_t
/* This is included inline inside each Redis module. */ /* This is included inline inside each Redis module. */
static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) {
void *getapifuncptr = ((void**)ctx)[0]; void *getapifuncptr = ((void**)ctx)[0];
RedisModule_GetApi = (int (*)(const char *, void *)) getapifuncptr; RedisModule_GetApi = (int (*)(const char *, void *)) (unsigned long)getapifuncptr;
REDISMODULE_GET_API(CreateCommand); REDISMODULE_GET_API(CreateCommand);
REDISMODULE_GET_API(SetModuleAttribs); REDISMODULE_GET_API(SetModuleAttribs);
REDISMODULE_GET_API(WrongArity); REDISMODULE_GET_API(WrongArity);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment