aboutsummaryrefslogtreecommitdiff
path: root/qom/object.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-09-04 19:41:15 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-09-04 19:41:15 +0100
commitfd884c07658d02a96a882b8457d6d7a5cd71a407 (patch)
treeda89f830084fd9e281eca8f0482c68603b51065e /qom/object.c
parentbbb6a1e872a6f0d6c43913726b2229c0cbdd3220 (diff)
parent1d45a705fc007a13f20d18473290082eae6d1725 (diff)
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging
QOM infrastructure fixes and device conversions * Cleanups for recursive device unrealization # gpg: Signature made Thu 04 Sep 2014 18:17:35 BST using RSA key ID 3E7E013F # gpg: Good signature from "Andreas Färber <afaerber@suse.de>" # gpg: aka "Andreas Färber <afaerber@suse.com>" * remotes/afaerber/tags/qom-devices-for-peter: qdev: Add cleanup logic in device_set_realized() to avoid resource leak qdev: Use NULL instead of local_err for qbus_child unrealize qdev: Use error_abort instead of using local_err memory: Remove object_property_add_child_array() qom: Add automatic arrayification to object_property_add() machine: Clean up -machine handling qom: Make object_child_foreach() safe for objects removal Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qom/object.c')
-rw-r--r--qom/object.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/qom/object.c b/qom/object.c
index 79bd0cc474..da0919a3dd 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -668,10 +668,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
void *opaque)
{
- ObjectProperty *prop;
+ ObjectProperty *prop, *next;
int ret = 0;
- QTAILQ_FOREACH(prop, &obj->properties, node) {
+ QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
if (object_property_is_child(prop)) {
ret = fn(prop->opaque, opaque);
if (ret != 0) {
@@ -728,6 +728,27 @@ object_property_add(Object *obj, const char *name, const char *type,
void *opaque, Error **errp)
{
ObjectProperty *prop;
+ size_t name_len = strlen(name);
+
+ if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
+ int i;
+ ObjectProperty *ret;
+ char *name_no_array = g_strdup(name);
+
+ name_no_array[name_len - 3] = '\0';
+ for (i = 0; ; ++i) {
+ char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
+
+ ret = object_property_add(obj, full_name, type, get, set,
+ release, opaque, NULL);
+ g_free(full_name);
+ if (ret) {
+ break;
+ }
+ }
+ g_free(name_no_array);
+ return ret;
+ }
QTAILQ_FOREACH(prop, &obj->properties, node) {
if (strcmp(prop->name, name) == 0) {