diff mbox

[v4,17/19] qapi: Drop inline subtype in query-version

Message ID 1411165504-18198-18-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake Sept. 19, 2014, 10:25 p.m. UTC
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.  The
QMP wire format is unaffected by this change.

Prefer the safer g_new0() while making the conversion.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 hmp.c            |  2 +-
 qapi/common.json | 26 +++++++++++++++++++-------
 qmp.c            |  9 +++++----
 3 files changed, 25 insertions(+), 12 deletions(-)

Comments

Markus Armbruster Sept. 30, 2014, 5:40 p.m. UTC | #1
Eric Blake <eblake@redhat.com> 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.  The
> QMP wire format is unaffected by this change.

"subtype" makes me think of subtype polymorphism.  I'd stick to
"substruct", or "nested struct".

Suggest to mention nested structs are unboxed, but explicit types are
boxed.

> Prefer the safer g_new0() while making the conversion.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  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 40a90da..23fc3da 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);
> 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 c6767c4..24b658a 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;

Here you can see the boxing.
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index 40a90da..23fc3da 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);
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 c6767c4..24b658a 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;