qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] qapi: add explicit null to string input and out


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] qapi: add explicit null to string input and output visitors
Date: Mon, 21 Nov 2016 10:32:50 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 11/19/2016 02:28 AM, Greg Kurz wrote:
> This may be used for deprecated object properties that are kept for
> backwards compatibility.
> 
> Signed-off-by: Greg Kurz <address@hidden>
> ---
> 
> This is enough to fix David's patch:
> 
> [RFCv2 10/12] pseries: Move CPU compatibility property to machine

Do we need both input and output visitors, or is the problem only caused
on an output visit?

> 
> Messag-Id: <address@hidden>
> 
>  qapi/string-input-visitor.c  |    5 +++++
>  qapi/string-output-visitor.c |   14 ++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
> index 8dfa5612522b..4a378d7b67e6 100644
> --- a/qapi/string-input-visitor.c
> +++ b/qapi/string-input-visitor.c
> @@ -314,6 +314,10 @@ static void parse_type_number(Visitor *v, const char 
> *name, double *obj,
>      *obj = val;
>  }
>  
> +static void parse_type_null(Visitor *v, const char *name, Error **errp)
> +{
> +}

In particular, this always succeeds, even though we don't have a
symmetric way to guarantee that the user can specifically request NULL
input (the qobject visitor checks for the JSON keyword NULL, but that's
different from string parsing), so I'm a bit worried that it is not
doing what we want. If you omit this hunk, does the problem with David's
patch still go away with just the output visitor change?

> +
>  static void parse_optional(Visitor *v, const char *name, bool *present)
>  {
>      StringInputVisitor *siv = to_siv(v);
> @@ -348,6 +352,7 @@ Visitor *string_input_visitor_new(const char *str)
>      v->visitor.type_bool = parse_type_bool;
>      v->visitor.type_str = parse_type_str;
>      v->visitor.type_number = parse_type_number;
> +    v->visitor.type_null = parse_type_null;
>      v->visitor.start_list = start_list;
>      v->visitor.next_list = next_list;
>      v->visitor.end_list = end_list;
> diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c
> index 94ac8211d144..5ec5352ca87c 100644
> --- a/qapi/string-output-visitor.c
> +++ b/qapi/string-output-visitor.c
> @@ -266,6 +266,19 @@ static void print_type_number(Visitor *v, const char 
> *name, double *obj,
>      string_output_set(sov, g_strdup_printf("%f", *obj));
>  }
>  
> +static void print_type_null(Visitor *v, const char *name, Error **errp)
> +{
> +    StringOutputVisitor *sov = to_sov(v);
> +    char *out;
> +
> +    if (sov->human) {
> +        out = g_strdup("<null>");
> +    } else {
> +        out = g_strdup("");
> +    }
> +    string_output_set(sov, out);
> +}
> +
>  static void
>  start_list(Visitor *v, const char *name, GenericList **list, size_t size,
>             Error **errp)
> @@ -351,6 +364,7 @@ Visitor *string_output_visitor_new(bool human, char 
> **result)
>      v->visitor.type_bool = print_type_bool;
>      v->visitor.type_str = print_type_str;
>      v->visitor.type_number = print_type_number;
> +    v->visitor.type_null = print_type_null;
>      v->visitor.start_list = start_list;
>      v->visitor.next_list = next_list;
>      v->visitor.end_list = end_list;
> 
> 
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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