From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/4] qapi: Add qobject_is_equal()
Date: Mon, 19 Jun 2017 16:59:16 +0200 [thread overview]
Message-ID: <151020e7-3e68-3a57-34c2-100542a02c36@redhat.com> (raw)
In-Reply-To: <20170619135525.GG6113@noname.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3195 bytes --]
On 2017-06-19 15:55, Kevin Wolf wrote:
> Am 14.06.2017 um 17:31 hat Max Reitz geschrieben:
>> This generic function (along with its implementations for different
>> types) determines whether two QObjects are equal.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>
>> diff --git a/qobject/qdict.c b/qobject/qdict.c
>> index 88e2ecd..2ed57ca 100644
>> --- a/qobject/qdict.c
>> +++ b/qobject/qdict.c
>> @@ -410,6 +410,30 @@ void qdict_del(QDict *qdict, const char *key)
>> }
>>
>> /**
>> + * qdict_is_equal(): Tests whether the two QDicts are equal
>
> This should specify what equality means for QDicts: Do their entries
> have to point to the same objects, or is it enough if the objects
> compare equal? It seems you're trying to implement the lattter.
Yes, I'll add a comment.
>> + */
>> +bool qdict_is_equal(const QObject *x, const QObject *y)
>> +{
>> + const QDict *dict_x = qobject_to_qdict(x), *dict_y = qobject_to_qdict(y);
>> + const QDictEntry *e;
>> +
>> + if (qdict_size(dict_x) != qdict_size(dict_y)) {
>> + return false;
>> + }
>> +
>> + for (e = qdict_first(dict_x); e; e = qdict_next(dict_x, e)) {
>> + const QObject *obj_x = qdict_entry_value(e);
>> + const QObject *obj_y = qdict_get(dict_y, qdict_entry_key(e));
>> +
>> + if (!qobject_is_equal(obj_x, obj_y)) {
>> + return false;
>> + }
>> + }
>> +
>> + return true;
>> +}
>
> If I'm not mistaken, this doesn't actually check equality, but that the
> entries of x are a subset of the entries of y.
That's why I'm checking that x and y have the same size before.
>> +/**
>> * qdict_destroy_obj(): Free all the memory allocated by a QDict
>> */
>> void qdict_destroy_obj(QObject *obj)
>> diff --git a/qobject/qlist.c b/qobject/qlist.c
>> index 86b60cb..b3033c6 100644
>> --- a/qobject/qlist.c
>> +++ b/qobject/qlist.c
>> @@ -140,6 +140,31 @@ QList *qobject_to_qlist(const QObject *obj)
>> }
>>
>> /**
>> + * qlist_is_equal(): Tests whether the two QLists are equal
>
> Like for QDict, this isn't a complete description.
Yes, I'll add a comment here, too.
> Your implementation seems to check that both lists contain objects that
> compare equal at each index (i.e. order matters).
Of course it does because lists are not sets but arrays (in contrast to
dicts).
Max
>> + */
>> +bool qlist_is_equal(const QObject *x, const QObject *y)
>> +{
>> + const QList *list_x = qobject_to_qlist(x), *list_y = qobject_to_qlist(y);
>> + const QListEntry *entry_x, *entry_y;
>> +
>> + entry_x = qlist_first(list_x);
>> + entry_y = qlist_first(list_y);
>> +
>> + while (entry_x && entry_y) {
>> + if (!qobject_is_equal(qlist_entry_obj(entry_x),
>> + qlist_entry_obj(entry_y)))
>> + {
>> + return false;
>> + }
>> +
>> + entry_x = qlist_next(entry_x);
>> + entry_y = qlist_next(entry_y);
>> + }
>> +
>> + return !entry_x && !entry_y;
>> +}
>> +
>> +/**
>> * qlist_destroy_obj(): Free all the memory allocated by a QList
>> */
>
> Kevin
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]
next prev parent reply other threads:[~2017-06-19 14:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-14 15:30 [Qemu-devel] [PATCH 0/4] block: Don't compare strings in bdrv_reopen_prepare() Max Reitz
2017-06-14 15:30 ` [Qemu-devel] [PATCH 1/4] qapi/qnull: Add own header Max Reitz
2017-06-19 13:20 ` Kevin Wolf
2017-06-14 15:31 ` [Qemu-devel] [PATCH 2/4] qapi: Add qobject_is_equal() Max Reitz
2017-06-19 13:55 ` Kevin Wolf
2017-06-19 14:59 ` Max Reitz [this message]
2017-06-14 15:31 ` [Qemu-devel] [PATCH 3/4] block: qobject_is_equal() in bdrv_reopen_prepare() Max Reitz
2017-06-19 14:10 ` Kevin Wolf
2017-06-14 15:31 ` [Qemu-devel] [PATCH 4/4] iotests: Add test for non-string option reopening Max Reitz
2017-06-19 14:14 ` Kevin Wolf
2017-06-14 16:20 ` [Qemu-devel] [PATCH 0/4] block: Don't compare strings in bdrv_reopen_prepare() no-reply
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=151020e7-3e68-3a57-34c2-100542a02c36@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--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).