aboutsummaryrefslogtreecommitdiff
path: root/qom
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 /qom
parent16bf7f522a2ff68993f80631ed86254c71eaf5d4 (diff)
downloadqemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.zip
qemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.tar.gz
qemu-7746abd8e9ee9db20c0b0fdb19504f163ba3cbea.tar.bz2
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 'qom')
-rw-r--r--qom/object.c22
1 files changed, 4 insertions, 18 deletions
diff --git a/qom/object.c b/qom/object.c
index 5d4c80b..5ff97ab 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -67,11 +67,6 @@ struct TypeImpl
InterfaceImpl interfaces[MAX_INTERFACES];
};
-struct ObjectPropertyIterator {
- ObjectClass *nextclass;
- GHashTableIter iter;
-};
-
static Type type_interface;
static GHashTable *type_table_get(void)
@@ -999,20 +994,11 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
return NULL;
}
-ObjectPropertyIterator *object_property_iter_init(Object *obj)
+void object_property_iter_init(ObjectPropertyIterator *iter,
+ Object *obj)
{
- ObjectPropertyIterator *ret = g_new0(ObjectPropertyIterator, 1);
- g_hash_table_iter_init(&ret->iter, obj->properties);
- ret->nextclass = object_get_class(obj);
- return ret;
-}
-
-void object_property_iter_free(ObjectPropertyIterator *iter)
-{
- if (!iter) {
- return;
- }
- g_free(iter);
+ g_hash_table_iter_init(&iter->iter, obj->properties);
+ iter->nextclass = object_get_class(obj);
}
ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter)