All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] readline: fix hmp completion issue
@ 2023-02-07  4:52 Dongli Zhang
  2023-02-08 11:05 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dongli Zhang @ 2023-02-07  4:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: dgilbert, joe.jin

The auto completion does not work in some cases.

Case 1.

1. (qemu) info reg
2. Press 'Tab'.
3. It does not auto complete.

Case 2.

1. (qemu) block_resize flo
2. Press 'Tab'.
3. It does not auto complete 'floppy0'.

Since the readline_add_completion_of() may add any completion when
strlen(pfx) is zero, we remove the check with (name[0] == '\0') because
strlen() always returns zero in that case.

Fixes: 52f50b1e9f8f ("readline: Extract readline_add_completion_of() from monitor")
Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 monitor/hmp.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/monitor/hmp.c b/monitor/hmp.c
index 2aa85d3982..fee410362f 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1189,9 +1189,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
         }
         memcpy(cmd, pstart, len);
         cmd[len] = '\0';
-        if (name[0] == '\0') {
-            readline_add_completion_of(mon->rs, name, cmd);
-        }
+        readline_add_completion_of(mon->rs, name, cmd);
         if (*p == '\0') {
             break;
         }
@@ -1335,9 +1333,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
             /* block device name completion */
             readline_set_completion_index(mon->rs, strlen(str));
             while ((blk = blk_next(blk)) != NULL) {
-                if (str[0] == '\0') {
-                    readline_add_completion_of(mon->rs, str, blk_name(blk));
-                }
+                readline_add_completion_of(mon->rs, str, blk_name(blk));
             }
             break;
         case 's':
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] readline: fix hmp completion issue
  2023-02-07  4:52 [PATCH 1/1] readline: fix hmp completion issue Dongli Zhang
@ 2023-02-08 11:05 ` Philippe Mathieu-Daudé
  2023-02-08 12:33 ` Markus Armbruster
  2023-02-14 13:39 ` Thomas Huth
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-08 11:05 UTC (permalink / raw)
  To: Dongli Zhang, qemu-devel; +Cc: dgilbert, joe.jin, Markus Armbruster

On 7/2/23 05:52, Dongli Zhang wrote:
> The auto completion does not work in some cases.
> 
> Case 1.
> 
> 1. (qemu) info reg
> 2. Press 'Tab'.
> 3. It does not auto complete.
> 
> Case 2.
> 
> 1. (qemu) block_resize flo
> 2. Press 'Tab'.
> 3. It does not auto complete 'floppy0'.
> 
> Since the readline_add_completion_of() may add any completion when
> strlen(pfx) is zero, we remove the check with (name[0] == '\0') because
> strlen() always returns zero in that case.
> 
> Fixes: 52f50b1e9f8f ("readline: Extract readline_add_completion_of() from monitor")
> Cc: Joe Jin <joe.jin@oracle.com>
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> ---
>   monitor/hmp.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index 2aa85d3982..fee410362f 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -1189,9 +1189,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
>           }
>           memcpy(cmd, pstart, len);
>           cmd[len] = '\0';
> -        if (name[0] == '\0') {
> -            readline_add_completion_of(mon->rs, name, cmd);
> -        }
> +        readline_add_completion_of(mon->rs, name, cmd);
>           if (*p == '\0') {
>               break;
>           }
> @@ -1335,9 +1333,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
>               /* block device name completion */
>               readline_set_completion_index(mon->rs, strlen(str));
>               while ((blk = blk_next(blk)) != NULL) {
> -                if (str[0] == '\0') {
> -                    readline_add_completion_of(mon->rs, str, blk_name(blk));
> -                }
> +                readline_add_completion_of(mon->rs, str, blk_name(blk));
>               }
>               break;
>           case 's':

Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] readline: fix hmp completion issue
  2023-02-07  4:52 [PATCH 1/1] readline: fix hmp completion issue Dongli Zhang
  2023-02-08 11:05 ` Philippe Mathieu-Daudé
@ 2023-02-08 12:33 ` Markus Armbruster
  2023-02-14 13:39 ` Thomas Huth
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-02-08 12:33 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: qemu-devel, dgilbert, joe.jin

Dongli Zhang <dongli.zhang@oracle.com> writes:

> The auto completion does not work in some cases.
>
> Case 1.
>
> 1. (qemu) info reg
> 2. Press 'Tab'.
> 3. It does not auto complete.
>
> Case 2.
>
> 1. (qemu) block_resize flo
> 2. Press 'Tab'.
> 3. It does not auto complete 'floppy0'.
>
> Since the readline_add_completion_of() may add any completion when
> strlen(pfx) is zero, we remove the check with (name[0] == '\0') because
> strlen() always returns zero in that case.
>
> Fixes: 52f50b1e9f8f ("readline: Extract readline_add_completion_of() from monitor")
> Cc: Joe Jin <joe.jin@oracle.com>
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> ---
>  monitor/hmp.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index 2aa85d3982..fee410362f 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -1189,9 +1189,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
>          }
>          memcpy(cmd, pstart, len);
>          cmd[len] = '\0';
> -        if (name[0] == '\0') {
> -            readline_add_completion_of(mon->rs, name, cmd);
> -        }
> +        readline_add_completion_of(mon->rs, name, cmd);
>          if (*p == '\0') {
>              break;
>          }

Yes, this fixes a silly logic error in my patch.

Before my patch:

        if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) {
            readline_add_completion(mon->rs, cmd);
        }

The left operand of || implies the right operand: it's true when name is
"", and strncmp("", ..., 0) is 0.  Therefore, this could simply be

        if (!strncmp(name, cmd, strlen(name))) {
            readline_add_completion(mon->rs, cmd);
        }

My patch combined with yours factors this out.

> @@ -1335,9 +1333,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
>              /* block device name completion */
>              readline_set_completion_index(mon->rs, strlen(str));
>              while ((blk = blk_next(blk)) != NULL) {
> -                if (str[0] == '\0') {
> -                    readline_add_completion_of(mon->rs, str, blk_name(blk));
> -                }
> +                readline_add_completion_of(mon->rs, str, blk_name(blk));
>              }
>              break;
>          case 's':

Likewise.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

I'll take this through my tree.  Thanks!



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] readline: fix hmp completion issue
  2023-02-07  4:52 [PATCH 1/1] readline: fix hmp completion issue Dongli Zhang
  2023-02-08 11:05 ` Philippe Mathieu-Daudé
  2023-02-08 12:33 ` Markus Armbruster
@ 2023-02-14 13:39 ` Thomas Huth
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-02-14 13:39 UTC (permalink / raw)
  To: Dongli Zhang, qemu-devel, Markus Armbruster; +Cc: dgilbert, joe.jin

On 07/02/2023 05.52, Dongli Zhang wrote:
> Subject:
> [PATCH 1/1] readline: fix hmp completion issue
> From:
> Dongli Zhang <dongli.zhang@oracle.com>
> Date:
> 07/02/2023, 05.52
> 
> To:
> qemu-devel@nongnu.org
> CC:
> dgilbert@redhat.com, joe.jin@oracle.com
> 
> 
> The auto completion does not work in some cases.
> 
> Case 1.
> 
> 1. (qemu) info reg
> 2. Press 'Tab'.
> 3. It does not auto complete.
> 
> Case 2.
> 
> 1. (qemu) block_resize flo
> 2. Press 'Tab'.
> 3. It does not auto complete 'floppy0'.
> 
> Since the readline_add_completion_of() may add any completion when
> strlen(pfx) is zero, we remove the check with (name[0] == '\0') because
> strlen() always returns zero in that case.
> 
> Fixes: 52f50b1e9f8f ("readline: Extract readline_add_completion_of() from monitor")
> Cc: Joe Jin<joe.jin@oracle.com>
> Signed-off-by: Dongli Zhang<dongli.zhang@oracle.com>
> ---
>   monitor/hmp.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index 2aa85d3982..fee410362f 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -1189,9 +1189,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
>           }
>           memcpy(cmd, pstart, len);
>           cmd[len] = '\0';
> -        if (name[0] == '\0') {
> -            readline_add_completion_of(mon->rs, name, cmd);
> -        }
> +        readline_add_completion_of(mon->rs, name, cmd);
>           if (*p == '\0') {
>               break;
>           }
> @@ -1335,9 +1333,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
>               /* block device name completion */
>               readline_set_completion_index(mon->rs, strlen(str));
>               while ((blk = blk_next(blk)) != NULL) {
> -                if (str[0] == '\0') {
> -                    readline_add_completion_of(mon->rs, str, blk_name(blk));
> -                }
> +                readline_add_completion_of(mon->rs, str, blk_name(blk));
>               }
>               break;
>           case 's':
> -- 2.34.1
> 

Thanks, this fixes the completion for me, too:

Tested-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-14 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07  4:52 [PATCH 1/1] readline: fix hmp completion issue Dongli Zhang
2023-02-08 11:05 ` Philippe Mathieu-Daudé
2023-02-08 12:33 ` Markus Armbruster
2023-02-14 13:39 ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.