diff options
Diffstat (limited to 'qobject/qdict.c')
-rw-r--r-- | qobject/qdict.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/qobject/qdict.c b/qobject/qdict.c index 88e2ecd658..576018e531 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -11,8 +11,7 @@ */ #include "qemu/osdep.h" -#include "qapi/qmp/qint.h" -#include "qapi/qmp/qfloat.h" +#include "qapi/qmp/qnum.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qstring.h" @@ -180,37 +179,26 @@ size_t qdict_size(const QDict *qdict) /** * qdict_get_double(): Get an number mapped by 'key' * - * This function assumes that 'key' exists and it stores a - * QFloat or QInt object. + * This function assumes that 'key' exists and it stores a QNum. * * Return number mapped by 'key'. */ double qdict_get_double(const QDict *qdict, const char *key) { - QObject *obj = qdict_get(qdict, key); - - assert(obj); - switch (qobject_type(obj)) { - case QTYPE_QFLOAT: - return qfloat_get_double(qobject_to_qfloat(obj)); - case QTYPE_QINT: - return qint_get_int(qobject_to_qint(obj)); - default: - abort(); - } + return qnum_get_double(qobject_to_qnum(qdict_get(qdict, key))); } /** * qdict_get_int(): Get an integer mapped by 'key' * * This function assumes that 'key' exists and it stores a - * QInt object. + * QNum representable as int. * * Return integer mapped by 'key'. */ int64_t qdict_get_int(const QDict *qdict, const char *key) { - return qint_get_int(qobject_to_qint(qdict_get(qdict, key))); + return qnum_get_int(qobject_to_qnum(qdict_get(qdict, key))); } /** @@ -259,16 +247,21 @@ const char *qdict_get_str(const QDict *qdict, const char *key) /** * qdict_get_try_int(): Try to get integer mapped by 'key' * - * Return integer mapped by 'key', if it is not present in - * the dictionary or if the stored object is not of QInt type - * 'def_value' will be returned. + * Return integer mapped by 'key', if it is not present in the + * dictionary or if the stored object is not a QNum representing an + * integer, 'def_value' will be returned. */ int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t def_value) { - QInt *qint = qobject_to_qint(qdict_get(qdict, key)); + QNum *qnum = qobject_to_qnum(qdict_get(qdict, key)); + int64_t val; + + if (!qnum || !qnum_get_try_int(qnum, &val)) { + return def_value; + } - return qint ? qint_get_int(qint) : def_value; + return val; } /** |