From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>
Subject: [PATCH 4/8] qnum: qnum_value_is_equal() function
Date: Mon, 9 Nov 2020 16:25:52 -0500 [thread overview]
Message-ID: <20201109212556.3934583-5-ehabkost@redhat.com> (raw)
In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com>
Extract the QNum value comparison logic to a function that takes
QNumValue* as argument.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/qapi/qmp/qnum.h | 1 +
qobject/qnum.c | 29 +++++++++++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h
index 62fbdfda68..0327ecd0f0 100644
--- a/include/qapi/qmp/qnum.h
+++ b/include/qapi/qmp/qnum.h
@@ -106,6 +106,7 @@ double qnum_get_double(const QNum *qn);
char *qnum_to_string(QNum *qn);
+bool qnum_value_is_equal(const QNumValue *num_x, const QNumValue *num_y);
bool qnum_is_equal(const QObject *x, const QObject *y);
void qnum_destroy_obj(QObject *obj);
diff --git a/qobject/qnum.c b/qobject/qnum.c
index f80d4efd76..6a0f948b16 100644
--- a/qobject/qnum.c
+++ b/qobject/qnum.c
@@ -207,9 +207,9 @@ char *qnum_to_string(QNum *qn)
}
/**
- * qnum_is_equal(): Test whether the two QNums are equal
- * @x: QNum object
- * @y: QNum object
+ * qnum_value_is_equal(): Test whether two QNumValues are equal
+ * @num_x: QNum value
+ * @num_y: QNum value
*
* Negative integers are never considered equal to unsigned integers,
* but positive integers in the range [0, INT64_MAX] are considered
@@ -217,13 +217,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 *num_x, const QNumValue *num_y)
{
- const QNum *qnum_x = qobject_to(QNum, x);
- const QNum *qnum_y = qobject_to(QNum, y);
- const QNumValue *num_x = &qnum_x->value;
- const QNumValue *num_y = &qnum_y->value;
-
switch (num_x->kind) {
case QNUM_I64:
switch (num_y->kind) {
@@ -241,7 +236,7 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
case QNUM_U64:
switch (num_y->kind) {
case QNUM_I64:
- return qnum_is_equal(y, x);
+ return qnum_value_is_equal(num_y, num_x);
case QNUM_U64:
/* Comparison in native uint64_t type */
return num_x->u.u64 == num_y->u.u64;
@@ -264,6 +259,20 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
abort();
}
+/**
+ * qnum_is_equal(): Test whether the two QNums are equal
+ * @x: QNum object
+ * @y: QNum object
+ *
+ * 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
*
--
2.28.0
next prev parent reply other threads:[~2020-11-09 21:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 21:25 [PATCH 0/8] qom: Use qlit to represent property defaults Eduardo Habkost
2020-11-09 21:25 ` [PATCH 1/8] qobject: Include API docs in docs/devel/qobject.html Eduardo Habkost
2020-11-09 21:25 ` [PATCH 2/8] qnum: Make qnum_get_double() get const pointer Eduardo Habkost
2020-11-09 21:25 ` [PATCH 3/8] qnum: QNumValue type for QNum value literals Eduardo Habkost
2020-11-09 21:25 ` Eduardo Habkost [this message]
2020-11-09 21:25 ` [PATCH 5/8] qlit: Support all types of QNums Eduardo Habkost
2020-11-09 21:25 ` [PATCH 6/8] qlit: qlit_type() function Eduardo Habkost
2020-11-09 21:25 ` [PATCH 7/8] qom: Make object_property_set_default() public Eduardo Habkost
2020-11-09 21:25 ` [PATCH 8/8] qom: Use qlit to represent property defaults Eduardo Habkost
2020-11-09 21:39 ` [PATCH 0/8] " no-reply
2020-11-10 16:39 ` Paolo Bonzini
2020-11-10 18:16 ` Eduardo Habkost
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=20201109212556.3934583-5-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.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).