mirror of
https://github.com/redis/redis.git
synced 2026-05-28 04:02:46 -04:00
feat: add RedisModule_FreeStringSafe() NULL-safe macro
Add a convenience macro in redismodule.h that wraps RedisModule_FreeString with a NULL check. This avoids the need for modules to guard every FreeString call with an explicit NULL test. Since it is a macro compiled into the module, it works transparently with any Redis server version (no API registration change needed). Closes #10887 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com> Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
This commit is contained in:
parent
2432f55278
commit
1de2c26802
1 changed files with 7 additions and 0 deletions
|
|
@ -1492,6 +1492,13 @@ REDISMODULE_API int (*RedisModule_GetKeyMeta)(RedisModuleKeyMetaClassId id, Redi
|
|||
|
||||
#define RedisModule_IsAOFClient(id) ((id) == UINT64_MAX)
|
||||
|
||||
/* NULL-safe wrapper for RedisModule_FreeString. Modules can use this macro
|
||||
* to avoid explicit NULL checks before freeing optional strings.
|
||||
* This macro is compiled into the module, so it works with any Redis version. */
|
||||
#define RedisModule_FreeStringSafe(ctx, str) do { \
|
||||
if ((str) != NULL) RedisModule_FreeString((ctx), (str)); \
|
||||
} while (0)
|
||||
|
||||
/* This is included inline inside each Redis module. */
|
||||
static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) REDISMODULE_ATTR_UNUSED;
|
||||
static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue