@@ -87,6 +87,7 @@ double qnum_get_double(const QNum *qn);
char *qnum_to_string(QNum *qn);
+bool qnum_value_is_equal(const QNumValue *val_x, const QNumValue *val_y);
bool qnum_is_equal(const QObject *x, const QObject *y);
void qnum_destroy_obj(QObject *obj);
@@ -202,7 +202,7 @@ char *qnum_to_string(QNum *qn)
}
/**
- * qnum_is_equal(): Test whether the two QNums are equal
+ * qnum_value_is_equal(): Test whether two QNumValues are equal
*
* Negative integers are never considered equal to unsigned integers,
* but positive integers in the range [0, INT64_MAX] are considered
@@ -210,13 +210,8 @@ char *qnum_to_string(QNum *qn)
*
* Doubles are never considered equal to integers.
*/
-bool qnum_is_equal(const QObject *x, const QObject *y)
+bool qnum_value_is_equal(const QNumValue *val_x, const QNumValue *val_y)
{
- const QNum *num_x = qobject_to(QNum, x);
- const QNum *num_y = qobject_to(QNum, y);
- const QNumValue *val_x = &num_x->value;
- const QNumValue *val_y = &num_y->value;
-
switch (val_x->kind) {
case QNUM_I64:
switch (val_y->kind) {
@@ -234,7 +229,7 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
case QNUM_U64:
switch (val_y->kind) {
case QNUM_I64:
- return qnum_is_equal(y, x);
+ return qnum_value_is_equal(val_y, val_x);
case QNUM_U64:
/* Comparison in native uint64_t type */
return val_x->u.u64 == val_y->u.u64;
@@ -257,6 +252,19 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
abort();
}
+/**
+ * qnum_is_equal(): Test whether the two QNums are equal
+ *
+ * See qnum_value_is_equal() for details on the comparison rules.
+ */
+bool qnum_is_equal(const QObject *x, const QObject *y)
+{
+ const QNum *qnum_x = qobject_to(QNum, x);
+ const QNum *qnum_y = qobject_to(QNum, y);
+
+ return qnum_value_is_equal(&qnum_x->value, &qnum_y->value);
+}
+
/**
* qnum_destroy_obj(): Free all memory allocated by a
* QNum object
Extract the QNum value comparison logic to a function that takes QNumValue* as argument. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Changes v2 -> v3: * Rename function parameters to val_x/val_y * Insert blank line after variable declarations at qnum_is_equal() --- include/qapi/qmp/qnum.h | 1 + qobject/qnum.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-)