summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-06-22 15:24:51 +0200
committerantirez <antirez@gmail.com>2016-06-22 15:24:51 +0200
commit4e10b08fb3ead01e305b65f47180b44334bf9b8a (patch)
treeb2d8fa81834564097a9086cc0042008b81d01cf3 /src/modules
parent0b4b7ebd957448cb59cf3e3c365772b29067ede7 (diff)
downloadredis-4e10b08fb3ead01e305b65f47180b44334bf9b8a.tar.gz
Modules doc: hint about replacing libc malloc calls.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/TYPES.md16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/modules/TYPES.md b/src/modules/TYPES.md
index cd870c141..1c31950fa 100644
--- a/src/modules/TYPES.md
+++ b/src/modules/TYPES.md
@@ -354,4 +354,18 @@ allocation functions provided by the module API is exactly compatible with
`malloc()`, `realloc()`, `free()` and `strdup()`, so converting the libraries
in order to use these functions should be trivial.
-
+In case you have an external library that uses libc `malloc()`, and you want
+to avoid replacing manually all the calls with the Redis Modules API calls,
+an approach could be to use simple macros in order to replace the libc calls
+with the Redis API calls. Something like this could work:
+
+ #define malloc RedisModule_Alloc
+ #define realloc RedisModule_Realloc
+ #define free RedisModule_Free
+ #define strdup RedisModule_Strdup
+
+However take in mind that mixing libc calls with Redis API calls will result
+into troubles and crashes, so if you replace calls using macros, you need to
+make sure that all the calls are correctly replaced, and that the code with
+the substituted calls will never, for example, attempt to call
+`RedisModule_Free()` with a pointer allocated using libc `malloc()`.