From patchwork Mon May 4 15:05:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 467683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D4B45140157 for ; Tue, 5 May 2015 01:24:39 +1000 (AEST) Received: from localhost ([::1]:34726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpIEX-0000JQ-Ml for incoming@patchwork.ozlabs.org; Mon, 04 May 2015 11:24:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpHwa-0005To-2I for qemu-devel@nongnu.org; Mon, 04 May 2015 11:06:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpHwY-0000Ot-1R for qemu-devel@nongnu.org; Mon, 04 May 2015 11:06:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46886) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpHwX-0000OG-On for qemu-devel@nongnu.org; Mon, 04 May 2015 11:06:01 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t44F60Mo003850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 May 2015 11:06:00 -0400 Received: from red.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t44F5dIt018431; Mon, 4 May 2015 11:05:59 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 4 May 2015 09:05:31 -0600 Message-Id: <1430751937-17523-35-git-send-email-eblake@redhat.com> In-Reply-To: <1430751937-17523-1-git-send-email-eblake@redhat.com> References: <1430751937-17523-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, berto@igalia.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH v8 34/40] qapi: Drop inline nested struct in query-version X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument (see previous commit message for more details why); but existing use of inline nested structs conflicts with that goal. This patch fixes one of only two commands relying on nested types, by breaking the nesting into an explicit type; it means that the type is now boxed instead of unboxed in C code, but the QMP wire format is unaffected by this change. Prefer the safer g_new0() while making the conversion. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- 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 d85d913..97d9c2c 100644 --- a/hmp.c +++ b/hmp.c @@ -60,7 +60,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); diff --git a/qapi/common.json b/qapi/common.json index 12431c6..bad56bf 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.4 +## +{ 'struct': '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 ## { 'struct': '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 e6c7050..3f5dfe3 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); 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;