qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats pars


From: Luiz Capitulino
Subject: Re: [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints
Date: Fri, 11 May 2012 16:30:40 -0300

On Fri, 11 May 2012 12:43:24 -0500
Michael Roth <address@hidden> wrote:

> JSON numbers can be interpreted as either integers or floating point
> values depending on their representation. As a result, QMP input visitor
> might visit a QInt when it was expecting a QFloat, so add handling to
> account for this.
> 
> Signed-off-by: Michael Roth <address@hidden>

Applied to the QMP branch, thanks.

> ---
>  qapi/qmp-input-visitor.c |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
> index 4cdc47d..107d8d3 100644
> --- a/qapi/qmp-input-visitor.c
> +++ b/qapi/qmp-input-visitor.c
> @@ -246,13 +246,18 @@ static void qmp_input_type_number(Visitor *v, double 
> *obj, const char *name,
>      QmpInputVisitor *qiv = to_qiv(v);
>      QObject *qobj = qmp_input_get_object(qiv, name);
>  
> -    if (!qobj || qobject_type(qobj) != QTYPE_QFLOAT) {
> +    if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT &&
> +        qobject_type(qobj) != QTYPE_QINT)) {
>          error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
> -                  "double");
> +                  "number");
>          return;
>      }
>  
> -    *obj = qfloat_get_double(qobject_to_qfloat(qobj));
> +    if (qobject_type(qobj) == QTYPE_QINT) {
> +        *obj = qint_get_int(qobject_to_qint(qobj));
> +    } else {
> +        *obj = qfloat_get_double(qobject_to_qfloat(qobj));
> +    }
>  }
>  
>  static void qmp_input_start_optional(Visitor *v, bool *present,




reply via email to

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