From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHtT5-0003Qo-Ne for qemu-devel@nongnu.org; Thu, 14 Aug 2014 07:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHtSw-0008DZ-Vv for qemu-devel@nongnu.org; Thu, 14 Aug 2014 07:45:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHtSw-0008DT-Pi for qemu-devel@nongnu.org; Thu, 14 Aug 2014 07:45:10 -0400 From: Markus Armbruster References: <1407287673-20308-1-git-send-email-eblake@redhat.com> <1407287673-20308-13-git-send-email-eblake@redhat.com> Date: Thu, 14 Aug 2014 13:45:06 +0200 In-Reply-To: <1407287673-20308-13-git-send-email-eblake@redhat.com> (Eric Blake's message of "Tue, 5 Aug 2014 19:14:31 -0600") Message-ID: <87y4ure1ml.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 12/14] qapi: drop inline subtype in query-version List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Luiz Capitulino , Fam Zheng , qemu-devel@nongnu.org, wenchaoqemu@gmail.com Eric Blake writes: > A future patch will be using a 'name':{dictionary} entry in the > QAPI schema to specify a default value for an optional argument; > but existing use of inline substructs conflicts with that goal. > This patch fixes one of only two commands relying on nested > subtypes, by breaking the nesting into an explicit type. > > Prefer the safer g_new0() while making the conversion. > > * qapi/common.json (VersionInfo): Split inline data... > (VersionTriple): ...into new type. > * qmp.c (qmp_query_version): Update caller. > * hmp.c (hmp_info_version): Likewise. > > Signed-off-by: Eric Blake > --- > hmp.c | 2 +- > qapi/common.json | 26 +++++++++++++++++++------- > qmp.c | 9 +++++---- > 3 files changed, 25 insertions(+), 12 deletions(-) > > diff --git a/hmp.c b/hmp.c > index 4d1838e..e637fbc 100644 > --- a/hmp.c > +++ b/hmp.c > @@ -55,7 +55,7 @@ void hmp_info_version(Monitor *mon, const QDict *qdict) > info = qmp_query_version(NULL); > > monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", > - info->qemu.major, info->qemu.minor, info->qemu.micro, > + info->qemu->major, info->qemu->minor, info->qemu->micro, > info->package); > > qapi_free_VersionInfo(info); This demonstrates the difference between anonymous and named complex member types: anonymous means unboxed, named means boxed. Already visible in the previous patch, but it's easier to see here (less noise). I'm no friend of excessive boxing in C, and QAPI code generator is too boxing-happy for my taste already. However, I like tying boxed vs. unboxed to named vs. anonymous even less. > diff --git a/qapi/common.json b/qapi/common.json > index 4e9a21f..d007095 100644 > --- a/qapi/common.json > +++ b/qapi/common.json > @@ -29,15 +29,28 @@ > 'DeviceNotActive', 'DeviceNotFound', 'KVMMissingCap' ] } > > ## > +# @VersionTriple > +# > +# A three-part version number. > +# > +# @qemu.major: The major version number. > +# > +# @qemu.minor: The minor version number. > +# > +# @qemu.micro: The micro version number. > +# > +# Since: 2.2 > +## > +{ 'type': 'VersionTriple', > + 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } > + > + > +## > # @VersionInfo: > # > # A description of QEMU's version. > # > -# @qemu.major: The major version of QEMU > -# > -# @qemu.minor: The minor version of QEMU > -# > -# @qemu.micro: The micro version of QEMU. By current convention, a micro > +# @qemu: The version of QEMU. By current convention, a micro > # version of 50 signifies a development branch. A micro version > # greater than or equal to 90 signifies a release candidate for > # the next minor version. A micro version of less than 50 > @@ -51,8 +64,7 @@ > # Since: 0.14.0 > ## > { 'type': 'VersionInfo', > - 'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'}, > - 'package': 'str'} } > + 'data': {'qemu': 'VersionTriple', 'package': 'str'} } > > ## > # @query-version: > diff --git a/qmp.c b/qmp.c > index 0d2553a..35e6f7a 100644 > --- a/qmp.c > +++ b/qmp.c > @@ -45,15 +45,16 @@ NameInfo *qmp_query_name(Error **errp) > > VersionInfo *qmp_query_version(Error **errp) > { > - VersionInfo *info = g_malloc0(sizeof(*info)); > + VersionInfo *info = g_new0(VersionInfo, 1); Unrelated improvement. I figure you want it for consistency with the g_new0() you add. Okay. > const char *version = QEMU_VERSION; > char *tmp; > > - info->qemu.major = strtol(version, &tmp, 10); > + info->qemu = g_new0(VersionTriple, 1); > + info->qemu->major = strtol(version, &tmp, 10); > tmp++; > - info->qemu.minor = strtol(tmp, &tmp, 10); > + info->qemu->minor = strtol(tmp, &tmp, 10); > tmp++; > - info->qemu.micro = strtol(tmp, &tmp, 10); > + info->qemu->micro = strtol(tmp, &tmp, 10); > info->package = g_strdup(QEMU_PKGVERSION); > > return info;