[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH 2/4] qapi: Add qobject_is_equal()
From: |
Max Reitz |
Subject: |
Re: [Qemu-block] [PATCH 2/4] qapi: Add qobject_is_equal() |
Date: |
Mon, 19 Jun 2017 16:59:16 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 |
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 <address@hidden>
>
>> 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
>
signature.asc
Description: OpenPGP digital signature
- [Qemu-block] [PATCH 0/4] block: Don't compare strings in bdrv_reopen_prepare(), Max Reitz, 2017/06/14
- [Qemu-block] [PATCH 2/4] qapi: Add qobject_is_equal(), Max Reitz, 2017/06/14
- [Qemu-block] [PATCH 1/4] qapi/qnull: Add own header, Max Reitz, 2017/06/14
- [Qemu-block] [PATCH 3/4] block: qobject_is_equal() in bdrv_reopen_prepare(), Max Reitz, 2017/06/14
- [Qemu-block] [PATCH 4/4] iotests: Add test for non-string option reopening, Max Reitz, 2017/06/14
- Re: [Qemu-block] [Qemu-devel] [PATCH 0/4] block: Don't compare strings in bdrv_reopen_prepare(), no-reply, 2017/06/14