From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de
Subject: [Qemu-devel] [PATCH v3 3/7] qapi: QMP input visitor, handle floats parsed as ints
Date: Mon, 5 Mar 2012 13:10:30 -0600 [thread overview]
Message-ID: <1330974634-7527-4-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1330974634-7527-1-git-send-email-mdroth@linux.vnet.ibm.com>
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 | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index e6b6152..f7ffb59 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -209,13 +209,18 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
QmpInputVisitor *qiv = to_qiv(v);
const 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");
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
next prev parent reply other threads:[~2012-03-05 19:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 19:10 [Qemu-devel] [PATCH v3 0/7] add fixed-width visitors and serialization tests Michael Roth
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 1/7] qapi: add Visitor interfaces for uint*_t and int*_t Michael Roth
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 2/7] qapi: unit tests for visitor-based serialization Michael Roth
2012-03-05 19:10 ` Michael Roth [this message]
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 4/7] qapi: add String visitor coverage to serialization unit tests Michael Roth
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 5/7] qapi: String visitor, use %f represenation for floats Michael Roth
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 6/7] qdev: use int32_t container for devfn property Michael Roth
2012-03-05 19:10 ` [Qemu-devel] [PATCH v3 7/7] qdev: switch property accessors to fixed-width visitor interfaces Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1330974634-7527-4-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).