From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRSKy-0000Jg-5V for qemu-devel@nongnu.org; Thu, 25 Oct 2012 14:39:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRSKt-00028E-Op for qemu-devel@nongnu.org; Thu, 25 Oct 2012 14:39:24 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:59127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRSKt-00027M-3L for qemu-devel@nongnu.org; Thu, 25 Oct 2012 14:39:19 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 26 Oct 2012 00:09:15 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9PIdAsm56033382 for ; Fri, 26 Oct 2012 00:09:11 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9Q091Ja028615 for ; Fri, 26 Oct 2012 11:09:02 +1100 From: Anthony Liguori In-Reply-To: <1351178549-5699-2-git-send-email-peter.maydell@linaro.org> References: <1351178549-5699-1-git-send-email-peter.maydell@linaro.org> <1351178549-5699-2-git-send-email-peter.maydell@linaro.org> Date: Thu, 25 Oct 2012 13:39:04 -0500 Message-ID: <871ugm2y7r.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH v4 1/2] qom: Detect attempts to add a property that already exists List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: Paolo Bonzini , patches@linaro.org Peter Maydell writes: > 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 Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > qom/object.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/qom/object.c b/qom/object.c > index e3e9242..a9dfc8c 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(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