[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/17] qapi: update the qobject visitor to use QUInt
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 08/17] qapi: update the qobject visitor to use QUInt |
Date: |
Tue, 9 May 2017 20:35:50 +0300 |
Switch to use QNum/uint where appropriate to remove i64 limitation.
The input visitor will cast i64 input to u64 for compatibility
reasons (existing json QMP client already use negative i64 for large
u64, and expect an implicit cast in qemu).
Signed-off-by: Marc-André Lureau <address@hidden>
---
qapi/qobject-input-visitor.c | 13 +++++++++++--
qapi/qobject-output-visitor.c | 3 +--
tests/test-qobject-output-visitor.c | 21 ++++++++++++++++-----
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 785949ebab..72cefcf677 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -420,9 +420,9 @@ static void qobject_input_type_int64_keyval(Visitor *v,
const char *name,
static void qobject_input_type_uint64(Visitor *v, const char *name,
uint64_t *obj, Error **errp)
{
- /* FIXME: qobject_to_qnum mishandles values over INT64_MAX */
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
+ Error *err = NULL;
QNum *qnum;
if (!qobj) {
@@ -435,7 +435,16 @@ static void qobject_input_type_uint64(Visitor *v, const
char *name,
return;
}
- *obj = qnum_get_int(qnum, errp);
+ /* XXX: compatibility case, accept negative values as u64 */
+ *obj = qnum_get_int(qnum, &err);
+
+ if (err) {
+ error_free(err);
+ err = NULL;
+ *obj = qnum_get_uint(qnum, &err);
+ }
+
+ error_propagate(errp, err);
}
static void qobject_input_type_uint64_keyval(Visitor *v, const char *name,
diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c
index 2ca5093b22..70be84ccb5 100644
--- a/qapi/qobject-output-visitor.c
+++ b/qapi/qobject-output-visitor.c
@@ -150,9 +150,8 @@ static void qobject_output_type_int64(Visitor *v, const
char *name,
static void qobject_output_type_uint64(Visitor *v, const char *name,
uint64_t *obj, Error **errp)
{
- /* FIXME values larger than INT64_MAX become negative */
QObjectOutputVisitor *qov = to_qov(v);
- qobject_output_add(qov, name, qnum_from_int(*obj));
+ qobject_output_add(qov, name, qnum_from_uint(*obj));
}
static void qobject_output_type_bool(Visitor *v, const char *name, bool *obj,
diff --git a/tests/test-qobject-output-visitor.c
b/tests/test-qobject-output-visitor.c
index 66a682d5a8..767818e393 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -595,15 +595,26 @@ static void check_native_list(QObject *qobj,
qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
switch (kind) {
- case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
case USER_DEF_NATIVE_LIST_UNION_KIND_U8:
case USER_DEF_NATIVE_LIST_UNION_KIND_U16:
case USER_DEF_NATIVE_LIST_UNION_KIND_U32:
case USER_DEF_NATIVE_LIST_UNION_KIND_U64:
- /* all integer elements in JSON arrays get stored into QNums when
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QNum *qvalue;
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qnum(tmp);
+ g_assert_cmpuint(qnum_get_uint(qvalue, &error_abort), ==, i);
+ qobject_decref(qlist_pop(qlist));
+ }
+ break;
+
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
+ /* all integer elements in JSON arrays get stored into QInts when
* we convert to QObjects, so we can check them all in the same
* fashion, so simply fall through here
*/
--
2.13.0.rc1.16.gd80b50c3f
- Re: [Qemu-devel] [PATCH 05/17] qapi: remove promote_int, (continued)
[Qemu-devel] [PATCH 08/17] qapi: update the qobject visitor to use QUInt,
Marc-André Lureau <=
[Qemu-devel] [PATCH 09/17] qnum: fix get_int() with values > INT64_MAX, Marc-André Lureau, 2017/05/09
[Qemu-devel] [PATCH 10/17] object: add uint property setter/getter, Marc-André Lureau, 2017/05/09
[Qemu-devel] [PATCH 11/17] object: use more specific property type names, Marc-André Lureau, 2017/05/09