diff options
Diffstat (limited to 'qom')
| -rw-r--r-- | qom/object.c | 9 | ||||
| -rw-r--r-- | qom/object_interfaces.c | 4 | ||||
| -rw-r--r-- | qom/qom-hmp-cmds.c | 7 | ||||
| -rw-r--r-- | qom/qom-qmp-cmds.c | 29 |
4 files changed, 19 insertions, 30 deletions
diff --git a/qom/object.c b/qom/object.c index f2ae6e6b2a..5cd43fe366 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1415,15 +1415,18 @@ char *object_property_get_str(Object *obj, const char *name, Error **errp) { QObject *ret = object_property_get_qobject(obj, name, errp); + QString *qstring; char *retval; if (!ret) { return NULL; } - - retval = g_strdup(qobject_get_try_str(ret)); - if (!retval) { + qstring = qobject_to(QString, ret); + if (!qstring) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); + retval = NULL; + } else { + retval = g_strdup(qstring_get_str(qstring)); } qobject_unref(ret); diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index ed896fe764..1e9ad6f08a 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -5,7 +5,6 @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" -#include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qom/object_interfaces.h" #include "qemu/help_option.h" @@ -207,7 +206,8 @@ char *object_property_help(const char *name, const char *type, g_string_append(str, description); } if (defval) { - g_autofree char *def_json = qstring_free(qobject_to_json(defval), TRUE); + g_autofree char *def_json = g_string_free(qobject_to_json(defval), + true); g_string_append_printf(str, " (default: %s)", def_json); } diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index 8861a109d5..453fbfeabc 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -13,7 +13,6 @@ #include "qapi/qapi-commands-qom.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" -#include "qapi/qmp/qstring.h" #include "qom/object.h" void hmp_qom_list(Monitor *mon, const QDict *qdict) @@ -78,9 +77,9 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict) QObject *obj = qmp_qom_get(path, property, &err); if (err == NULL) { - QString *str = qobject_to_json_pretty(obj); - monitor_printf(mon, "%s\n", qstring_get_str(str)); - qobject_unref(str); + GString *str = qobject_to_json_pretty(obj, true); + monitor_printf(mon, "%s\n", str->str); + g_string_free(str, true); } qobject_unref(obj); diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 2dd233f293..b40ac39f30 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -46,14 +46,12 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) object_property_iter_init(&iter, obj); while ((prop = object_property_iter_next(&iter))) { - ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); + ObjectPropertyInfo *value = g_malloc0(sizeof(ObjectPropertyInfo)); - entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); - entry->next = props; - props = entry; + QAPI_LIST_PREPEND(props, value); - entry->value->name = g_strdup(prop->name); - entry->value->type = g_strdup(prop->type); + value->name = g_strdup(prop->name); + value->type = g_strdup(prop->type); } return props; @@ -90,7 +88,7 @@ QObject *qmp_qom_get(const char *path, const char *property, Error **errp) static void qom_list_types_tramp(ObjectClass *klass, void *data) { - ObjectTypeInfoList *e, **pret = data; + ObjectTypeInfoList **pret = data; ObjectTypeInfo *info; ObjectClass *parent = object_class_get_parent(klass); @@ -102,10 +100,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data) info->parent = g_strdup(object_class_get_name(parent)); } - e = g_malloc0(sizeof(*e)); - e->value = info; - e->next = *pret; - *pret = e; + QAPI_LIST_PREPEND(*pret, info); } ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, @@ -150,7 +145,6 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename, object_property_iter_init(&iter, obj); while ((prop = object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; /* Skip Object and DeviceState properties */ if (strcmp(prop->name, "type") == 0 || @@ -176,10 +170,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename, info->default_value = qobject_ref(prop->defval); info->has_default_value = !!info->default_value; - entry = g_malloc0(sizeof(*entry)); - entry->value = info; - entry->next = prop_list; - prop_list = entry; + QAPI_LIST_PREPEND(prop_list, info); } object_unref(obj); @@ -217,7 +208,6 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename, } while ((prop = object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; info = g_malloc0(sizeof(*info)); info->name = g_strdup(prop->name); @@ -225,10 +215,7 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename, info->has_description = !!prop->description; info->description = g_strdup(prop->description); - entry = g_malloc0(sizeof(*entry)); - entry->value = info; - entry->next = prop_list; - prop_list = entry; + QAPI_LIST_PREPEND(prop_list, info); } object_unref(obj); |