qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] qom: Support JSON in user_creatable_parse_str()


From: Markus Armbruster
Subject: Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
Date: Sat, 13 Mar 2021 09:00:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Recommend

    qom: Support JSON in HMP object_add and tools --object

to put the most interesting bit right in "git-log --oneline".

Kevin Wolf <kwolf@redhat.com> writes:

> Support JSON for --object in all tools and in HMP object_add in the same
> way as it is supported in qobject_input_visitor_new_str().
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> Based-on: <20210311144811.313451-1-kwolf@redhat.com>
>
>  qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 62d7db7629..f5ea84b6c4 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -295,25 +295,35 @@ static void user_creatable_print_help_from_qdict(QDict 
> *args)
>  ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
>  {
>      ERRP_GUARD();
> -    QDict *args;
> +    QObject *obj;
>      bool help;
>      Visitor *v;
>      ObjectOptions *options;
>  
> -    args = keyval_parse(optarg, "qom-type", &help, errp);
> -    if (*errp) {
> -        return NULL;
> -    }
> -    if (help) {
> -        user_creatable_print_help_from_qdict(args);
> -        qobject_unref(args);
> -        return NULL;
> +    if (optarg[0] == '{') {
> +        obj = qobject_from_json(optarg, errp);
> +        if (!obj) {
> +            return NULL;
> +        }
> +        v = qobject_input_visitor_new(obj);
> +    } else {
> +        QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
> +        if (*errp) {
> +            return NULL;
> +        }
> +        if (help) {
> +            user_creatable_print_help_from_qdict(args);
> +            qobject_unref(args);
> +            return NULL;
> +        }
> +
> +        obj = QOBJECT(args);
> +        v = qobject_input_visitor_new_keyval(obj);
>      }
>  
> -    v = qobject_input_visitor_new_keyval(QOBJECT(args));
>      visit_type_ObjectOptions(v, NULL, &options, errp);
>      visit_free(v);
> -    qobject_unref(args);
> +    qobject_unref(obj);
>  
>      return options;
>  }

Best viewed with whitespace change ignored:

   diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
   index 2e50698075..93b8878127 100644
   --- a/qom/object_interfaces.c
   +++ b/qom/object_interfaces.c
   @@ -242,12 +242,19 @@ static void user_creatable_print_help_from_qdict(QDict 
*args)
    ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
    {
        ERRP_GUARD();
   -    QDict *args;
   +    QObject *obj;
        bool help;
        Visitor *v;
        ObjectOptions *options;

   -    args = keyval_parse(optarg, "qom-type", &help, errp);
   +    if (optarg[0] == '{') {
   +        obj = qobject_from_json(optarg, errp);
   +        if (!obj) {
   +            return NULL;
   +        }
   +        v = qobject_input_visitor_new(obj);
   +    } else {
   +        QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
            if (*errp) {
                return NULL;
            }
   @@ -257,10 +264,13 @@ ObjectOptions *user_creatable_parse_str(const char 
*optarg, Error **errp)
                return NULL;
            }

   -    v = qobject_input_visitor_new_keyval(QOBJECT(args));
   +        obj = QOBJECT(args);
   +        v = qobject_input_visitor_new_keyval(obj);
   +    }
   +
        visit_type_ObjectOptions(v, NULL, &options, errp);
        visit_free(v);
   -    qobject_unref(args);
   +    qobject_unref(obj);

        return options;
    }

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]