This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8056

-- gerrit

commit c8aa198bb2905cf87c4e3ebe26510360f4fc4564
Author: Antonio Borneo <antonio.bor...@foss.st.com>
Date:   Sun Aug 6 12:26:25 2023 +0200

    helper/command: inline run_command() in exec_command()
    
    Simplify the command execution by inlining run_command() inside
    exec_command().
    
    Change-Id: Id932b006846720cfd867d22d142cd35831dbd1a2
    Signed-off-by: Antonio Borneo <antonio.bor...@foss.st.com>

diff --git a/src/helper/command.c b/src/helper/command.c
index 8860cf81fd..57db2adc15 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -489,14 +489,27 @@ static bool command_can_run(struct command_context 
*cmd_ctx, struct command *c,
        return false;
 }
 
-static int run_command(struct command_context *context,
-       struct command *c, const char **words, unsigned num_words)
+static int exec_command(Jim_Interp *interp, struct command_context *context,
+               struct command *c, int argc, Jim_Obj * const *argv)
 {
+       if (c->jim_handler)
+               return c->jim_handler(interp, argc, argv);
+
+       /* use c->handler */
+       const char **words = malloc(argc * sizeof(char *));
+       if (!words) {
+               LOG_ERROR("Out of memory");
+               return JIM_ERR;
+       }
+
+       for (int i = 0; i < argc; i++)
+               words[i] = Jim_GetString(argv[i], NULL);
+
        struct command_invocation cmd = {
                .ctx = context,
                .current = c,
                .name = c->name,
-               .argc = num_words - 1,
+               .argc = argc - 1,
                .argv = words + 1,
        };
 
@@ -526,7 +539,8 @@ static int run_command(struct command_context *context,
        }
        Jim_DecrRefCount(context->interp, cmd.output);
 
-       return retval;
+       free(words);
+       return command_retval_set(interp, retval);
 }
 
 int command_run_line(struct command_context *context, char *line)
@@ -867,27 +881,6 @@ static char *alloc_concatenate_strings(int argc, Jim_Obj * 
const *argv)
        return all;
 }
 
-static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx,
-               struct command *c, int argc, Jim_Obj * const *argv)
-{
-       if (c->jim_handler)
-               return c->jim_handler(interp, argc, argv);
-
-       /* use c->handler */
-       const char **words = malloc(argc * sizeof(char *));
-       if (!words) {
-               LOG_ERROR("Out of memory");
-               return JIM_ERR;
-       }
-
-       for (int i = 0; i < argc; i++)
-               words[i] = Jim_GetString(argv[i], NULL);
-
-       int retval = run_command(cmd_ctx, c, words, argc);
-       free(words);
-       return command_retval_set(interp, retval);
-}
-
 static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const 
*argv)
 {
        /* check subcommands */

-- 

Reply via email to