diff mbox

[2/2] qom: Detect attempts to add a property that already exists

Message ID 1350667146-26273-3-git-send-email-peter.maydell@linaro.org
State New
Headers show

Commit Message

Peter Maydell Oct. 19, 2012, 5:19 p.m. UTC
Detect attempts to add a property to an object if one of
that name already exists, and report them as critical
errors. In particular, for static properties (eg qdev
Property arrays) this will manifest as an abort() with
a useful error message.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 qom/object.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/qom/object.c b/qom/object.c
index e3e9242..228ca92 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -620,7 +620,18 @@  void object_property_add(Object *obj, const char *name, const char *type,
                          ObjectPropertyRelease *release,
                          void *opaque, Error **errp)
 {
-    ObjectProperty *prop = g_malloc0(sizeof(*prop));
+    ObjectProperty *prop;
+
+    QTAILQ_FOREACH(prop, &obj->properties, node) {
+        if (strcmp(prop->name, name) == 0) {
+            error_setg_critical(errp, "attempt to add duplicate property '%s'"
+                                " to object (type '%s')\n", name,
+                                object_get_typename(obj));
+            return;
+        }
+    }
+
+    prop = g_malloc0(sizeof(*prop));
 
     prop->name = g_strdup(name);
     prop->type = g_strdup(type);