[PATCH V8 16/39] qapi: strv_from_strList

Steve Sistare posted 39 patches 3 years, 7 months ago
Maintainers: Stefano Stabellini <sstabellini@kernel.org>, Anthony Perard <anthony.perard@citrix.com>, Paul Durrant <paul@xen.org>, David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, Steve Sistare <steven.sistare@oracle.com>, Mark Kanda <mark.kanda@oracle.com>, Peter Xu <peterx@redhat.com>, Juan Quintela <quintela@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Beraldo Leal <bleal@redhat.com>, Eric Blake <eblake@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
[PATCH V8 16/39] qapi: strv_from_strList
Posted by Steve Sistare 3 years, 7 months ago
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/qapi/util.h |  6 ++++++
 qapi/qapi-util.c    | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/qapi/util.h b/include/qapi/util.h
index 75dddca..51ff64e 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -33,6 +33,12 @@ bool qapi_bool_parse(const char *name, const char *value, bool *obj,
 int parse_qapi_name(const char *name, bool complete);
 
 /*
+ * Produce and return a NULL-terminated array of strings from @args.
+ * All strings are g_strdup'd.
+ */
+GStrv strv_from_strList(const struct strList *args);
+
+/*
  * Produce a strList from the character delimited string @in.
  * All strings are g_strdup'd.
  * A NULL or empty input string returns NULL.
diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
index b61c73c..8c96cab 100644
--- a/qapi/qapi-util.c
+++ b/qapi/qapi-util.c
@@ -154,6 +154,20 @@ int parse_qapi_name(const char *str, bool complete)
     return p - str;
 }
 
+GStrv strv_from_strList(const strList *args)
+{
+    const strList *arg;
+    int i = 0;
+    GStrv argv = g_malloc((QAPI_LIST_LENGTH(args) + 1) * sizeof(char *));
+
+    for (arg = args; arg != NULL; arg = arg->next) {
+        argv[i++] = g_strdup(arg->value);
+    }
+    argv[i] = NULL;
+
+    return argv;
+}
+
 strList *strList_from_string(const char *in, char delim)
 {
     strList *res = NULL;
-- 
1.8.3.1
Re: [PATCH V8 16/39] qapi: strv_from_strList
Posted by Marc-André Lureau 3 years, 7 months ago
Hi

On Wed, Jun 15, 2022 at 7:30 PM Steve Sistare <steven.sistare@oracle.com>
wrote:

> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> ---
>  include/qapi/util.h |  6 ++++++
>  qapi/qapi-util.c    | 14 ++++++++++++++
>  2 files changed, 20 insertions(+)
>
> diff --git a/include/qapi/util.h b/include/qapi/util.h
> index 75dddca..51ff64e 100644
> --- a/include/qapi/util.h
> +++ b/include/qapi/util.h
> @@ -33,6 +33,12 @@ bool qapi_bool_parse(const char *name, const char
> *value, bool *obj,
>  int parse_qapi_name(const char *name, bool complete);
>
>  /*
> + * Produce and return a NULL-terminated array of strings from @args.
> + * All strings are g_strdup'd.
> + */
> +GStrv strv_from_strList(const struct strList *args);
> +
> +/*
>   * Produce a strList from the character delimited string @in.
>   * All strings are g_strdup'd.
>   * A NULL or empty input string returns NULL.
> diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
> index b61c73c..8c96cab 100644
> --- a/qapi/qapi-util.c
> +++ b/qapi/qapi-util.c
> @@ -154,6 +154,20 @@ int parse_qapi_name(const char *str, bool complete)
>      return p - str;
>  }
>
> +GStrv strv_from_strList(const strList *args)
> +{
> +    const strList *arg;
> +    int i = 0;
> +    GStrv argv = g_malloc((QAPI_LIST_LENGTH(args) + 1) * sizeof(char *));
> +
>

Better use g_new() here. Otherwise:
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> +    for (arg = args; arg != NULL; arg = arg->next) {
> +        argv[i++] = g_strdup(arg->value);
> +    }
> +    argv[i] = NULL;
> +
> +    return argv;
> +}
> +
>  strList *strList_from_string(const char *in, char delim)
>  {
>      strList *res = NULL;
> --
> 1.8.3.1
>
>
>

-- 
Marc-André Lureau
Re: [PATCH V8 16/39] qapi: strv_from_strList
Posted by Steven Sistare 3 years, 7 months ago
On 6/16/2022 12:08 PM, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Jun 15, 2022 at 7:30 PM Steve Sistare <steven.sistare@oracle.com <mailto:steven.sistare@oracle.com>> wrote:
> 
>     Signed-off-by: Steve Sistare <steven.sistare@oracle.com <mailto:steven.sistare@oracle.com>>
>     ---
>      include/qapi/util.h |  6 ++++++
>      qapi/qapi-util.c    | 14 ++++++++++++++
>      2 files changed, 20 insertions(+)
> 
>     diff --git a/include/qapi/util.h b/include/qapi/util.h
>     index 75dddca..51ff64e 100644
>     --- a/include/qapi/util.h
>     +++ b/include/qapi/util.h
>     @@ -33,6 +33,12 @@ bool qapi_bool_parse(const char *name, const char *value, bool *obj,
>      int parse_qapi_name(const char *name, bool complete);
> 
>      /*
>     + * Produce and return a NULL-terminated array of strings from @args.
>     + * All strings are g_strdup'd.
>     + */
>     +GStrv strv_from_strList(const struct strList *args);
>     +
>     +/*
>       * Produce a strList from the character delimited string @in.
>       * All strings are g_strdup'd.
>       * A NULL or empty input string returns NULL.
>     diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
>     index b61c73c..8c96cab 100644
>     --- a/qapi/qapi-util.c
>     +++ b/qapi/qapi-util.c
>     @@ -154,6 +154,20 @@ int parse_qapi_name(const char *str, bool complete)
>          return p - str;
>      }
> 
>     +GStrv strv_from_strList(const strList *args)
>     +{
>     +    const strList *arg;
>     +    int i = 0;
>     +    GStrv argv = g_malloc((QAPI_LIST_LENGTH(args) + 1) * sizeof(char *));
>     +
> 
> 
> Better use g_new() here. Otherwise:
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com <mailto:marcandre.lureau@redhat.com>>

Will do, thanks - Steve

>     +    for (arg = args; arg != NULL; arg = arg->next) {
>     +        argv[i++] = g_strdup(arg->value);
>     +    }
>     +    argv[i] = NULL;
>     +
>     +    return argv;
>     +}
>     +
>      strList *strList_from_string(const char *in, char delim)
>      {
>          strList *res = NULL;
>     -- 
>     1.8.3.1
> 
> 
> 
> 
> -- 
> Marc-André Lureau