From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtcAR-0000T5-Cv for qemu-devel@nongnu.org; Sat, 16 May 2015 09:30:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YtcAN-00021r-A7 for qemu-devel@nongnu.org; Sat, 16 May 2015 09:30:15 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46751 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtcAM-00021a-Vg for qemu-devel@nongnu.org; Sat, 16 May 2015 09:30:11 -0400 Message-ID: <5557465F.4030108@suse.de> Date: Sat, 16 May 2015 15:30:07 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1431728700-18055-1-git-send-email-eblake@redhat.com> <1431728700-18055-2-git-send-email-eblake@redhat.com> In-Reply-To: <1431728700-18055-2-git-send-email-eblake@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] qobject: Use 'bool' for qbool List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: kwolf@redhat.com, berto@igalia.com, mst@redhat.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com, mreitz@redhat.com Am 16.05.2015 um 00:24 schrieb Eric Blake: > We require a C99 compiler, so let's use 'bool' instead of 'int' > when dealing with boolean values. There are few enough clients > to fix them all in one pass. >=20 > Signed-off-by: Eric Blake > --- > block/qapi.c | 2 +- > block/quorum.c | 4 ++-- > block/vvfat.c | 4 ++-- > include/qapi/qmp/qbool.h | 8 ++++---- > monitor.c | 10 +++++----- > qapi/qmp-input-visitor.c | 2 +- > qapi/qmp-output-visitor.c | 2 +- > qobject/json-parser.c | 6 +++--- > qobject/qbool.c | 8 ++++---- > qobject/qdict.c | 4 ++-- > qobject/qjson.c | 2 +- > qom/object.c | 4 ++-- > tests/check-qjson.c | 11 ++++++----- > tests/test-qmp-event.c | 4 ++-- > tests/test-qmp-output-visitor.c | 4 ++-- > util/qemu-option.c | 2 +- > 16 files changed, 39 insertions(+), 38 deletions(-) [...] > diff --git a/qobject/qbool.c b/qobject/qbool.c > index a3d2afa..5ff69f0 100644 > --- a/qobject/qbool.c > +++ b/qobject/qbool.c > @@ -23,11 +23,11 @@ static const QType qbool_type =3D { > }; >=20 > /** > - * qbool_from_int(): Create a new QBool from an int > + * qbool_from_bool(): Create a new QBool from a bool > * > * Return strong reference. Can you fix the syntax as follow-up please? /** * qbool_from_bool: * @value: ... * * Desc... * * Returns: ... */ > */ > -QBool *qbool_from_int(int value) > +QBool *qbool_from_bool(bool value) > { > QBool *qb; >=20 > @@ -39,9 +39,9 @@ QBool *qbool_from_int(int value) > } >=20 > /** > - * qbool_get_int(): Get the stored int > + * qbool_get_bool(): Get the stored bool > */ > -int qbool_get_int(const QBool *qb) > +bool qbool_get_bool(const QBool *qb) > { > return qb->value; > } [...] > diff --git a/tests/check-qjson.c b/tests/check-qjson.c > index 60e5b22..1cfffa5 100644 > --- a/tests/check-qjson.c > +++ b/tests/check-qjson.c > @@ -1013,7 +1013,7 @@ static void keyword_literal(void) > g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); >=20 > qbool =3D qobject_to_qbool(obj); > - g_assert(qbool_get_int(qbool) !=3D 0); > + g_assert(qbool_get_bool(qbool) =3D=3D true); >=20 > str =3D qobject_to_json(obj); > g_assert(strcmp(qstring_get_str(str), "true") =3D=3D 0); > @@ -1026,7 +1026,7 @@ static void keyword_literal(void) > g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); >=20 > qbool =3D qobject_to_qbool(obj); > - g_assert(qbool_get_int(qbool) =3D=3D 0); > + g_assert(qbool_get_bool(qbool) =3D=3D false); >=20 > str =3D qobject_to_json(obj); > g_assert(strcmp(qstring_get_str(str), "false") =3D=3D 0); > @@ -1039,16 +1039,17 @@ static void keyword_literal(void) > g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); >=20 > qbool =3D qobject_to_qbool(obj); > - g_assert(qbool_get_int(qbool) =3D=3D 0); > + g_assert(qbool_get_bool(qbool) =3D=3D false); >=20 > QDECREF(qbool); >=20 > - obj =3D qobject_from_jsonf("%i", true); > + /* Test that non-zero values other than 1 get collapsed to true */ > + obj =3D qobject_from_jsonf("%i", 2); > g_assert(obj !=3D NULL); > g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); >=20 > qbool =3D qobject_to_qbool(obj); > - g_assert(qbool_get_int(qbool) !=3D 0); > + g_assert(qbool_get_bool(qbool) =3D=3D true); >=20 > QDECREF(qbool); >=20 [...] > diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-vi= sitor.c > index f8c9367..5be8e77 100644 > --- a/tests/test-qmp-output-visitor.c > +++ b/tests/test-qmp-output-visitor.c > @@ -72,7 +72,7 @@ static void test_visitor_out_bool(TestOutputVisitorDa= ta *data, > obj =3D qmp_output_get_qobject(data->qov); > g_assert(obj !=3D NULL); > g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); > - g_assert(qbool_get_int(qobject_to_qbool(obj)) =3D=3D value); > + g_assert(qbool_get_bool(qobject_to_qbool(obj)) =3D=3D value); >=20 > qobject_decref(obj); > } > @@ -662,7 +662,7 @@ static void check_native_list(QObject *qobj, > tmp =3D qlist_peek(qlist); > g_assert(tmp); > qvalue =3D qobject_to_qbool(tmp); > - g_assert_cmpint(qbool_get_int(qvalue), =3D=3D, (i % 3 =3D=3D= 0) ? 1 : 0); > + g_assert_cmpint(qbool_get_bool(qvalue), =3D=3D, i % 3 =3D=3D= 0); > qobject_decref(qlist_pop(qlist)); > } > break; [snip] I notice that we're inconsistent in using g_assert() vs. g_assert_cmpint(). Given that GLib has a weird GBoolean, should we add a macro qtest_assert_cmpbool() instead as follow-up? That said, Reviewed-by: Andreas F=E4rber Regards, Andreas --=20 SUSE Linux GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Felix Imend=F6rffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG N=FCrnberg)