Unverified Commit f8970fdb authored by guybe7's avatar guybe7 Committed by GitHub
Browse files

Cleanup: Remove redundant arg from moduleCreateArgvFromUserFormat (#11426)

We do not need to return the length of argv because it is equal to argc, which we return anyway.
This change makes the code cleaner and adds a comment to explain something that might not be immediately clear.
parent 737a0905
...@@ -444,7 +444,7 @@ struct ModuleConfig { ...@@ -444,7 +444,7 @@ struct ModuleConfig {
void RM_FreeCallReply(RedisModuleCallReply *reply); void RM_FreeCallReply(RedisModuleCallReply *reply);
void RM_CloseKey(RedisModuleKey *key); void RM_CloseKey(RedisModuleKey *key);
void autoMemoryCollect(RedisModuleCtx *ctx); void autoMemoryCollect(RedisModuleCtx *ctx);
robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *argvlenp, int *flags, va_list ap); robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap);
void RM_ZsetRangeStop(RedisModuleKey *kp); void RM_ZsetRangeStop(RedisModuleKey *kp);
static void zsetKeyReset(RedisModuleKey *key); static void zsetKeyReset(RedisModuleKey *key);
static void moduleInitKeyTypeSpecific(RedisModuleKey *key); static void moduleInitKeyTypeSpecific(RedisModuleKey *key);
...@@ -3226,7 +3226,7 @@ int RM_Replicate(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) ...@@ -3226,7 +3226,7 @@ int RM_Replicate(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...)
   
/* Create the client and dispatch the command. */ /* Create the client and dispatch the command. */
va_start(ap, fmt); va_start(ap, fmt);
argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,NULL,&flags,ap); argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
va_end(ap); va_end(ap);
if (argv == NULL) return REDISMODULE_ERR; if (argv == NULL) return REDISMODULE_ERR;
   
...@@ -5643,7 +5643,7 @@ void RM_SetContextUser(RedisModuleCtx *ctx, const RedisModuleUser *user) { ...@@ -5643,7 +5643,7 @@ void RM_SetContextUser(RedisModuleCtx *ctx, const RedisModuleUser *user) {
   
/* Returns an array of robj pointers, by parsing the format specifier "fmt" as described for /* Returns an array of robj pointers, by parsing the format specifier "fmt" as described for
* the RM_Call(), RM_Replicate() and other module APIs. Populates *argcp with the number of * the RM_Call(), RM_Replicate() and other module APIs. Populates *argcp with the number of
* items and *argvlenp with the length of the allocated argv. * items (which equals to the length of the allocated argv).
* *
* The integer pointed by 'flags' is populated with flags according * The integer pointed by 'flags' is populated with flags according
* to special modifiers in "fmt". * to special modifiers in "fmt".
...@@ -5657,7 +5657,7 @@ void RM_SetContextUser(RedisModuleCtx *ctx, const RedisModuleUser *user) { ...@@ -5657,7 +5657,7 @@ void RM_SetContextUser(RedisModuleCtx *ctx, const RedisModuleUser *user) {
* *
* On error (format specifier error) NULL is returned and nothing is * On error (format specifier error) NULL is returned and nothing is
* allocated. On success the argument vector is returned. */ * allocated. On success the argument vector is returned. */
robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *argvlenp, int *flags, va_list ap) { robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap) {
int argc = 0, argv_size, j; int argc = 0, argv_size, j;
robj **argv = NULL; robj **argv = NULL;
   
...@@ -5734,7 +5734,6 @@ robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int ...@@ -5734,7 +5734,6 @@ robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int
p++; p++;
} }
if (argcp) *argcp = argc; if (argcp) *argcp = argc;
if (argvlenp) *argvlenp = argv_size;
return argv; return argv;
   
fmterr: fmterr:
...@@ -5823,7 +5822,7 @@ fmterr: ...@@ -5823,7 +5822,7 @@ fmterr:
RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) { RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) {
client *c = NULL; client *c = NULL;
robj **argv = NULL; robj **argv = NULL;
int argc = 0, argv_len = 0, flags = 0; int argc = 0, flags = 0;
va_list ap; va_list ap;
RedisModuleCallReply *reply = NULL; RedisModuleCallReply *reply = NULL;
int replicate = 0; /* Replicate this command? */ int replicate = 0; /* Replicate this command? */
...@@ -5832,7 +5831,7 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch ...@@ -5832,7 +5831,7 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
   
/* Handle arguments. */ /* Handle arguments. */
va_start(ap, fmt); va_start(ap, fmt);
argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&argv_len,&flags,ap); argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
replicate = flags & REDISMODULE_ARGV_REPLICATE; replicate = flags & REDISMODULE_ARGV_REPLICATE;
error_as_call_replies = flags & REDISMODULE_ARGV_CALL_REPLIES_AS_ERRORS; error_as_call_replies = flags & REDISMODULE_ARGV_CALL_REPLIES_AS_ERRORS;
va_end(ap); va_end(ap);
...@@ -5856,8 +5855,9 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch ...@@ -5856,8 +5855,9 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
c->flags |= CLIENT_DENY_BLOCKING; c->flags |= CLIENT_DENY_BLOCKING;
c->db = ctx->client->db; c->db = ctx->client->db;
c->argv = argv; c->argv = argv;
c->argc = argc; /* We have to assign argv_len, which is equal to argc in that case (RM_Call)
c->argv_len = argv_len; * because we may be calling a command that uses rewriteClientCommandArgument */
c->argc = c->argv_len = argc;
c->resp = 2; c->resp = 2;
if (flags & REDISMODULE_ARGV_RESP_3) { if (flags & REDISMODULE_ARGV_RESP_3) {
c->resp = 3; c->resp = 3;
...@@ -7030,7 +7030,7 @@ void RM_EmitAOF(RedisModuleIO *io, const char *cmdname, const char *fmt, ...) { ...@@ -7030,7 +7030,7 @@ void RM_EmitAOF(RedisModuleIO *io, const char *cmdname, const char *fmt, ...) {
   
/* Emit the arguments into the AOF in Redis protocol format. */ /* Emit the arguments into the AOF in Redis protocol format. */
va_start(ap, fmt); va_start(ap, fmt);
argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,NULL,&flags,ap); argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
va_end(ap); va_end(ap);
if (argv == NULL) { if (argv == NULL) {
serverLog(LL_WARNING, serverLog(LL_WARNING,
......
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