mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
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>
This commit is contained in:
parent
16bf7f522a
commit
7746abd8e9
7 changed files with 36 additions and 58 deletions
22
qom/object.c
22
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue