qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints
@ 2012-05-11 17:43 Michael Roth
  2012-05-11 17:49 ` Andreas Färber
  2012-05-11 19:30 ` Luiz Capitulino
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Roth @ 2012-05-11 17:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, afaerber, lcapitulino

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 <mdroth@linux.vnet.ibm.com>
---
 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,
-- 
1.7.4.1

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

* Re: [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints
  2012-05-11 17:43 [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints Michael Roth
@ 2012-05-11 17:49 ` Andreas Färber
  2012-05-11 19:30 ` Luiz Capitulino
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2012-05-11 17:49 UTC (permalink / raw)
  To: Michael Roth; +Cc: aliguori, qemu-devel, lcapitulino

Am 11.05.2012 19:43, schrieb Michael Roth:
> 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 <mdroth@linux.vnet.ibm.com>

Acked-by: Andreas Färber <afaerber@suse.de>

/-F

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

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

* Re: [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints
  2012-05-11 17:43 [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints Michael Roth
  2012-05-11 17:49 ` Andreas Färber
@ 2012-05-11 19:30 ` Luiz Capitulino
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Capitulino @ 2012-05-11 19:30 UTC (permalink / raw)
  To: Michael Roth; +Cc: aliguori, qemu-devel, afaerber

On Fri, 11 May 2012 12:43:24 -0500
Michael Roth <mdroth@linux.vnet.ibm.com> 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 <mdroth@linux.vnet.ibm.com>

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,

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

end of thread, other threads:[~2012-05-11 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-11 17:43 [Qemu-devel] [PATCH 1.1] qapi: QMP input visitor, handle floats parsed as ints Michael Roth
2012-05-11 17:49 ` Andreas Färber
2012-05-11 19:30 ` Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).