From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnhtD-00037j-Uf for qemu-devel@nongnu.org; Fri, 01 Sep 2017 05:05:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnht8-0002hF-Hw for qemu-devel@nongnu.org; Fri, 01 Sep 2017 05:05:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnht8-0002gY-9J for qemu-devel@nongnu.org; Fri, 01 Sep 2017 05:05:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 614B78BD21 for ; Fri, 1 Sep 2017 09:05:16 +0000 (UTC) From: Markus Armbruster References: <20170824103350.16400-1-marcandre.lureau@redhat.com> <20170824103350.16400-3-marcandre.lureau@redhat.com> <20170901000634.GC17184@localhost.localdomain> Date: Fri, 01 Sep 2017 11:05:11 +0200 In-Reply-To: <20170901000634.GC17184@localhost.localdomain> (Eduardo Habkost's message of "Thu, 31 Aug 2017 21:06:34 -0300") Message-ID: <87shg6dc1k.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 02/14] qlit: move qlit from check-qjson to qobject/ List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , qemu-devel@nongnu.org Eduardo Habkost writes: > On Thu, Aug 24, 2017 at 12:33:38PM +0200, Marc-Andr=C3=A9 Lureau wrote: >> Fix code style issues while at it, to please check-patch. >>=20 >> Signed-off-by: Marc-Andr=C3=A9 Lureau >> --- >> include/qapi/qmp/qlit.h | 49 +++++++++++++++++++++++++ >> qobject/qlit.c | 89 ++++++++++++++++++++++++++++++++++++++++++= +++ >> tests/check-qjson.c | 96 +-----------------------------------------= ------- >> qobject/Makefile.objs | 2 +- >> 4 files changed, 140 insertions(+), 96 deletions(-) >> create mode 100644 include/qapi/qmp/qlit.h >> create mode 100644 qobject/qlit.c >>=20 >> diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h >> new file mode 100644 >> index 0000000000..4e2e760ef1 >> --- /dev/null >> +++ b/include/qapi/qmp/qlit.h >> @@ -0,0 +1,49 @@ >> +/* >> + * Copyright IBM, Corp. 2009 >> + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. >> + * >> + * Authors: >> + * Anthony Liguori >> + * Markus Armbruster >> + * Marc-Andr=C3=A9 Lureau >> + * >> + * This work is licensed under the terms of the GNU LGPL, version 2.1 o= r later. >> + * See the COPYING.LIB file in the top-level directory. >> + * >> + */ >> +#ifndef QLIT_H_ >> +#define QLIT_H_ >> + >> +#include "qapi-types.h" >> +#include "qobject.h" >> + >> +typedef struct LiteralQDictEntry LiteralQDictEntry; >> +typedef struct LiteralQObject LiteralQObject; >> + >> +struct LiteralQObject { >> + int type; >> + union { >> + int64_t qnum; >> + const char *qstr; >> + LiteralQDictEntry *qdict; >> + LiteralQObject *qlist; >> + } value; >> +}; >> + >> +struct LiteralQDictEntry { >> + const char *key; >> + LiteralQObject value; >> +}; >> + >> +#define QLIT_QNUM(val) \ >> + (LiteralQObject){.type =3D QTYPE_QNUM, .value.qnum =3D (val)} >> +#define QLIT_QSTR(val) \ >> + (LiteralQObject){.type =3D QTYPE_QSTRING, .value.qstr =3D (val)} >> +#define QLIT_QDICT(val) \ >> + (LiteralQObject){.type =3D QTYPE_QDICT, .value.qdict =3D (val)} >> +#define QLIT_QLIST(val) \ >> + (LiteralQObject){.type =3D QTYPE_QLIST, .value.qlist =3D (val)} > > I'm still trying to understand why this exists. Doesn't this > provide exactly the same functionality as QObject? The value-add is initializers. Check out check-qjson.c for examples. Use cases: * Specify expected output as data (QLitObject initializer), then use qlit_equal_qobject() to verify actual output matches. Example: check-qjson.c. I think it compares nicely to the qdict_get morass we use elsewhere. * Specify a QObject as data (QLitObject initializer), build it with qobject_from_qlit(). Example: PATCH 14. I think it beats specifying the QObject in code (qdict_new(), qdict_put(), ...) at least when the QObject is big.