From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlyq6-0000JD-BG for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zlyq3-0004LZ-TI for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:37:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlyq3-0004LU-NY for qemu-devel@nongnu.org; Tue, 13 Oct 2015 08:37:55 -0400 From: "Daniel P. Berrange" Date: Tue, 13 Oct 2015 13:37:41 +0100 Message-Id: <1444739866-14798-3-git-send-email-berrange@redhat.com> In-Reply-To: <1444739866-14798-1-git-send-email-berrange@redhat.com> References: <1444739866-14798-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH v4 2/7] qmp: convert QMP code to use object property iterators List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Pavel Fedin , Markus Armbruster , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Stop directly accessing the Object "properties" field data structure and instead use the formal object property iterator APIs. This insulates the code from future data structure changes in the Object struct. Signed-off-by: Daniel P. Berrange --- qmp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qmp.c b/qmp.c index d9ecede..5d99439 100644 --- a/qmp.c +++ b/qmp.c @@ -208,6 +208,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) bool ambiguous = false; ObjectPropertyInfoList *props = NULL; ObjectProperty *prop; + ObjectPropertyIterator *iter; obj = object_resolve_path(path, &ambiguous); if (obj == NULL) { @@ -220,7 +221,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) return NULL; } - QTAILQ_FOREACH(prop, &obj->properties, node) { + iter = object_property_iter_init(obj); + while ((prop = object_property_iter_next(iter))) { ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); @@ -230,6 +232,7 @@ 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; } @@ -500,6 +503,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, ObjectClass *klass; Object *obj; ObjectProperty *prop; + ObjectPropertyIterator *iter; DevicePropertyInfoList *prop_list = NULL; klass = object_class_by_name(typename); @@ -528,7 +532,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, obj = object_new(typename); - QTAILQ_FOREACH(prop, &obj->properties, node) { + iter = object_property_iter_init(obj); + while ((prop = object_property_iter_next(iter))) { DevicePropertyInfo *info; DevicePropertyInfoList *entry; @@ -559,6 +564,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, entry->next = prop_list; prop_list = entry; } + object_property_iter_free(iter); object_unref(obj); -- 2.4.3