Replace the existing int64_t field in QLitObject with QNumValue, so we can get support for other QNum types for free.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- This is a new patch added in v3 of the series. It includes portions of a previous patch from v2: "qlit: Support all types of QNums". --- include/qapi/qmp/qlit.h | 5 +++-- qobject/qlit.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 2fc2db282e..a240cdd299 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -15,6 +15,7 @@ #define QLIT_H #include "qobject.h" +#include "qnum.h" typedef struct QLitDictEntry QLitDictEntry; typedef struct QLitObject QLitObject; @@ -23,7 +24,7 @@ struct QLitObject { QType type; union { bool qbool; - int64_t qnum; + QNumValue qnum; const char *qstr; QLitDictEntry *qdict; QLitObject *qlist; @@ -40,7 +41,7 @@ struct QLitDictEntry { #define QLIT_QBOOL(val) \ { .type = QTYPE_QBOOL, .value.qbool = (val) } #define QLIT_QNUM_INT(val) \ - { .type = QTYPE_QNUM, .value.qnum = (val) } + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_INT(val) } #define QLIT_QSTR(val) \ { .type = QTYPE_QSTRING, .value.qstr = (val) } #define QLIT_QDICT(val) \ diff --git a/qobject/qlit.c b/qobject/qlit.c index 67126b25d5..b7af81cefb 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -71,7 +71,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) case QTYPE_QBOOL: return lhs->value.qbool == qbool_get_bool(qobject_to(QBool, rhs)); case QTYPE_QNUM: - return qnum_value_is_equal(&(QNumValue)QNUM_VAL_INT(lhs->value.qnum), + return qnum_value_is_equal(&lhs->value.qnum, &qobject_to(QNum, rhs)->value); case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, @@ -95,7 +95,7 @@ QObject *qobject_from_qlit(const QLitObject *qlit) case QTYPE_QNULL: return QOBJECT(qnull()); case QTYPE_QNUM: - return QOBJECT(qnum_from_int(qlit->value.qnum)); + return QOBJECT(qnum_from_value(qlit->value.qnum)); case QTYPE_QSTRING: return QOBJECT(qstring_from_str(qlit->value.qstr)); case QTYPE_QDICT: { -- 2.28.0