From 05deaf2d15a6b5434a1dfcfe2c6ff2b9e28ca877 Mon Sep 17 00:00:00 2001 From: hwware Date: Fri, 22 Nov 2024 21:32:27 +0000 Subject: [PATCH] update UpdateRuntimeArgs function logic and test case codes Signed-off-by: hwware --- src/module.c | 13 +++++-------- tests/modules/moduleparameter.c | 4 +++- tests/unit/moduleapi/moduleconfigs.tcl | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/module.c b/src/module.c index af0e31d336..768dd3309d 100644 --- a/src/module.c +++ b/src/module.c @@ -2264,19 +2264,16 @@ int moduleIsModuleCommand(void *module_handle, struct serverCommand *cmd) { * - VALKEYMODULE_ERR on failure. */ int VM_UpdateRuntimeArgs(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { - if (!ctx->module->onload) { - return VALKEYMODULE_ERR; - } struct moduleLoadQueueEntry *loadmod = ctx->module->loadmod; for (int i = 0; i < loadmod->argc; i++) { decrRefCount(loadmod->argv[i]); } zfree(loadmod->argv); - loadmod->argv = argc ? zmalloc(sizeof(robj *) * argc) : NULL; - loadmod->argc = argc; - for (int i = 0; i < argc; i++) { - loadmod->argv[i] = argv[i]; - incrRefCount(loadmod->argv[i]); + loadmod->argv = argc - 1 ? zmalloc(sizeof(robj *) * (argc - 1)) : NULL; + loadmod->argc = argc - 1; + for (int i = 1; i < argc; i++) { + loadmod->argv[i - 1] = argv[i]; + incrRefCount(loadmod->argv[i - 1]); } return VALKEYMODULE_OK; } diff --git a/tests/modules/moduleparameter.c b/tests/modules/moduleparameter.c index 82b9d86c9b..6c110f2cfb 100644 --- a/tests/modules/moduleparameter.c +++ b/tests/modules/moduleparameter.c @@ -6,7 +6,9 @@ int test_module_update_parameter(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { - return ValkeyModule_UpdateRuntimeArgs(ctx, argv, argc); + + ValkeyModule_UpdateRuntimeArgs(ctx, argv, argc); + return ValkeyModule_ReplyWithSimpleString(ctx, "OK"); } int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { diff --git a/tests/unit/moduleapi/moduleconfigs.tcl b/tests/unit/moduleapi/moduleconfigs.tcl index 3cb08ebc8e..44a8d68fa8 100644 --- a/tests/unit/moduleapi/moduleconfigs.tcl +++ b/tests/unit/moduleapi/moduleconfigs.tcl @@ -252,7 +252,7 @@ start_server {tags {"modules"}} { set modulename [lmap x [r module list] {dict get $x name}] assert_not_equal [lsearch $modulename moduleparameter] -1 assert_equal "{10 20 30}" [lmap x [r module list] {dict get $x args}] - r testmoduleparameter.update.parameter 40 50 60 70 + assert_equal OK [r testmoduleparameter.update.parameter 40 50 60 70] assert_equal "{40 50 60 70}" [lmap x [r module list] {dict get $x args}] } }