diff mbox series

[v3,3/6] qmp: qmp_qom_list_properties(): ignore empty string options

Message ID 1558079119-320634-4-git-send-email-imammedo@redhat.com (mailing list archive)
State New, archived
Headers show
Series numa: deprecate '-numa node, mem' and default memory distribution | expand

Commit Message

Igor Mammedov May 17, 2019, 7:45 a.m. UTC
Current QAPI semantics return empty "" string in case string property
value hasn't been set (i.e. NULL). Do not show initial value in this
case in "qom-list-properties" command output to reduce clutter.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 qmp.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Markus Armbruster May 27, 2019, 6:22 p.m. UTC | #1
Igor Mammedov <imammedo@redhat.com> writes:

> Current QAPI semantics return empty "" string in case string property
> value hasn't been set (i.e. NULL). Do not show initial value in this
> case in "qom-list-properties" command output to reduce clutter.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  qmp.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/qmp.c b/qmp.c
> index 8415541..463c7d4 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -41,6 +41,7 @@
>  #include "qom/object_interfaces.h"
>  #include "hw/mem/memory-device.h"
>  #include "hw/acpi/acpi_dev_interface.h"
> +#include "qapi/qmp/qstring.h"
>  
>  NameInfo *qmp_query_name(Error **errp)
>  {
> @@ -596,7 +597,16 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
>          if (obj) {
>              info->q_default =
>                  object_property_get_qobject(obj, info->name, NULL);
> -            info->has_q_default = !!info->q_default;
> +            if (info->q_default) {
> +               if (qobject_type(info->q_default) == QTYPE_QSTRING) {
> +                   QString *value = qobject_to(QString, info->q_default);
> +                   if (!strcmp(qstring_get_str(value), "")) {
> +                       qobject_unref(info->q_default);
> +                       info->q_default = NULL;
> +                   }
> +               }
> +               info->has_q_default = !!info->q_default;
> +            }
>          }
>  
>          entry = g_malloc0(sizeof(*entry));

The commit message suggests we omit @default when a string-valued
property is null.  We omit it when it's "", too.

Makes me wonder whether we should omit other "default defaults", too,
such as integer zero.  After all, what's so special about strings?

I'm not sure omitting any default defaults is a good idea.  But then I'm
not yet sure @default is a good idea.
diff mbox series

Patch

diff --git a/qmp.c b/qmp.c
index 8415541..463c7d4 100644
--- a/qmp.c
+++ b/qmp.c
@@ -41,6 +41,7 @@ 
 #include "qom/object_interfaces.h"
 #include "hw/mem/memory-device.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "qapi/qmp/qstring.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -596,7 +597,16 @@  ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
         if (obj) {
             info->q_default =
                 object_property_get_qobject(obj, info->name, NULL);
-            info->has_q_default = !!info->q_default;
+            if (info->q_default) {
+               if (qobject_type(info->q_default) == QTYPE_QSTRING) {
+                   QString *value = qobject_to(QString, info->q_default);
+                   if (!strcmp(qstring_get_str(value), "")) {
+                       qobject_unref(info->q_default);
+                       info->q_default = NULL;
+                   }
+               }
+               info->has_q_default = !!info->q_default;
+            }
         }
 
         entry = g_malloc0(sizeof(*entry));