[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal()
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal() |
Date: |
Mon, 3 Jul 2017 07:44:41 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 |
On 07/03/2017 07:25 AM, Max Reitz wrote:
> This generic function (along with its implementations for different
> types) determines whether two QObjects are equal.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> +++ b/qobject/qnum.c
> + case QNUM_DOUBLE:
> + switch (num_y->kind) {
> + case QNUM_I64:
> + return qnum_is_equal(y, x);
> + case QNUM_U64:
> + return qnum_is_equal(y, x);
> + case QNUM_DOUBLE:
> + /* Comparison in native double type */
> + return num_x->u.dbl == num_y->u.dbl;
Which returns false if we allow NaN (in general, JSON does not, so I'm
not sure if we allow NaN in a QNum)
> +++ b/qobject/qobject.c
> +bool qobject_is_equal(const QObject *x, const QObject *y)
> +{
> + /* We cannot test x == y because an object does not need to be
> + * equal to itself (e.g. NaN floats are not). */
But this comment matches the code above in QNum.
> +
> + if (!x && !y) {
> + return true;
> + }
> +
> + if (!x || !y || x->type != y->type) {
> + return false;
> + }
I like that there is no implicit conversion between bool and int; the
only conversions that still allow equality are within the subtypes of QNum.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v3 0/5] block: Don't compare strings in bdrv_reopen_prepare(), Max Reitz, 2017/07/03
- [Qemu-devel] [PATCH v3 1/5] qapi/qnull: Add own header, Max Reitz, 2017/07/03
- [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Max Reitz, 2017/07/03
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(),
Eric Blake <=
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Markus Armbruster, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Max Reitz, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Max Reitz, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Eric Blake, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Max Reitz, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Max Reitz, 2017/07/05
- Re: [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal(), Eric Blake, 2017/07/05