summaryrefslogtreecommitdiff
path: root/qmp.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2015-12-09 12:34:02 +0000
committerAndreas Färber <afaerber@suse.de>2016-01-18 17:47:58 +0100
commit7746abd8e9ee9db20c0b0fdb19504f163ba3cbea (patch)
treea5e9c56a0342b23cabe21e6bd199f312e1393fab /qmp.c
parent16bf7f522a2ff68993f80631ed86254c71eaf5d4 (diff)
downloadqemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.tar.gz
qemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.tar.bz2
qemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.zip
qom: Change object property iterator API contract
Currently the ObjectProperty iterator API works as follows: ObjectPropertyIterator *iter; iter = object_property_iter_init(obj); while ((prop = object_property_iter_next(iter))) { ... } object_property_iter_free(iter); This has the benefit that the ObjectPropertyIterator struct can be opaque, but has the downside that callers need to explicitly call a free function. It is also not in keeping with iterator style used elsewhere in QEMU/GLib2. This patch changes the API to use stack allocation instead: ObjectPropertyIterator iter; object_property_iter_init(&iter, obj); while ((prop = object_property_iter_next(&iter))) { ... } Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [AF: Fused ObjectPropertyIterator struct with typedef] Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'qmp.c')
-rw-r--r--qmp.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/qmp.c b/qmp.c
index 0a1fa19925..3ff6db79b9 100644
--- a/qmp.c
+++ b/qmp.c
@@ -210,7 +210,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
bool ambiguous = false;
ObjectPropertyInfoList *props = NULL;
ObjectProperty *prop;
- ObjectPropertyIterator *iter;
+ ObjectPropertyIterator iter;
obj = object_resolve_path(path, &ambiguous);
if (obj == NULL) {
@@ -223,8 +223,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
return NULL;
}
- iter = object_property_iter_init(obj);
- while ((prop = object_property_iter_next(iter))) {
+ object_property_iter_init(&iter, obj);
+ while ((prop = object_property_iter_next(&iter))) {
ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
@@ -234,7 +234,6 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
entry->value->name = g_strdup(prop->name);
entry->value->type = g_strdup(prop->type);
}
- object_property_iter_free(iter);
return props;
}
@@ -506,7 +505,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
ObjectClass *klass;
Object *obj;
ObjectProperty *prop;
- ObjectPropertyIterator *iter;
+ ObjectPropertyIterator iter;
DevicePropertyInfoList *prop_list = NULL;
klass = object_class_by_name(typename);
@@ -535,8 +534,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
obj = object_new(typename);
- iter = object_property_iter_init(obj);
- while ((prop = object_property_iter_next(iter))) {
+ object_property_iter_init(&iter, obj);
+ while ((prop = object_property_iter_next(&iter))) {
DevicePropertyInfo *info;
DevicePropertyInfoList *entry;
@@ -567,7 +566,6 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
entry->next = prop_list;
prop_list = entry;
}
- object_property_iter_free(iter);
object_unref(obj);