qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	patches@linaro.org
Subject: [Qemu-devel] [PATCH 2/2] qom: Detect attempts to add a property that already exists
Date: Fri, 19 Oct 2012 18:19:06 +0100	[thread overview]
Message-ID: <1350667146-26273-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1350667146-26273-1-git-send-email-peter.maydell@linaro.org>

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 --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);
-- 
1.7.9.5

  parent reply	other threads:[~2012-10-19 17:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-19 17:19 [Qemu-devel] [PATCH 0/2] qom: detect attempts to add a property that already exists Peter Maydell
2012-10-19 17:19 ` [Qemu-devel] [PATCH 1/2] error: Distinguish critical and non-critical errors Peter Maydell
2012-10-19 17:19 ` Peter Maydell [this message]
2012-10-22 15:35 ` [Qemu-devel] [PATCH 0/2] qom: detect attempts to add a property that already exists Luiz Capitulino
2012-10-22 16:26   ` Peter Maydell
2012-10-22 16:51     ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350667146-26273-3-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=aliguori@us.ibm.com \
    --cc=patches@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).