diff --git a/qemu/include/qom/object.h b/qemu/include/qom/object.h index 352f2f2f..5d837eb7 100644 --- a/qemu/include/qom/object.h +++ b/qemu/include/qom/object.h @@ -827,7 +827,10 @@ ObjectProperty *object_property_find(struct uc_struct *uc, Object *obj, ObjectProperty *object_class_property_find(struct uc_struct *uc, ObjectClass *klass, const char *name, Error **errp); -typedef struct ObjectPropertyIterator ObjectPropertyIterator; +typedef struct ObjectPropertyIterator { + ObjectClass *nextclass; + GHashTableIter iter; +} ObjectPropertyIterator; /** * object_property_iter_init: @@ -845,32 +848,27 @@ typedef struct ObjectPropertyIterator ObjectPropertyIterator; * Using object property iterators * * ObjectProperty *prop; - * ObjectPropertyIterator *iter; + * ObjectPropertyIterator iter; * - * 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))) { * ... do something with prop ... * } - * object_property_iter_free(iter); * * - * - * Returns: the new iterator */ -ObjectPropertyIterator *object_property_iter_init(Object *obj); - -/** - * object_property_iter_free: - * @iter: the iterator instance - * - * Releases any resources associated with the iterator. - */ -void object_property_iter_free(ObjectPropertyIterator *iter); +void object_property_iter_init(ObjectPropertyIterator *iter, + Object *obj); /** * object_property_iter_next: * @iter: the iterator instance * + * Return the next available property. If no further properties + * are available, a %NULL value will be returned and the @iter + * pointer should not be used again after this point without + * re-initializing it. + * * Returns: the next property, or %NULL when all properties * have been traversed. */ diff --git a/qemu/qom/object.c b/qemu/qom/object.c index 18075868..ccb3f964 100644 --- a/qemu/qom/object.c +++ b/qemu/qom/object.c @@ -66,11 +66,6 @@ struct TypeImpl InterfaceImpl interfaces[MAX_INTERFACES]; }; -struct ObjectPropertyIterator { - ObjectClass *nextclass; - GHashTableIter iter; -}; - static GHashTable *type_table_get(struct uc_struct *uc) { if (uc->type_table == NULL) { @@ -80,7 +75,6 @@ static GHashTable *type_table_get(struct uc_struct *uc) return uc->type_table; } - static void type_table_add(struct uc_struct *uc, TypeImpl *ti) { assert(!uc->enumerating_types); @@ -883,20 +877,11 @@ ObjectProperty *object_property_find(struct uc_struct *uc, Object *obj, 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(struct uc_struct *uc, ObjectPropertyIterator *iter)