Received: from eggs.gnu.org ([2001:4830:134:3::10]:45118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfAL8-0003Iv-6H for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfAL1-0004as-LD for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:18 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:50702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfAL1-0004Zv-EE for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:11 -0400 Received: by mail-wi0-f176.google.com with SMTP id hi2so2523305wib.9 for ; Fri, 17 Oct 2014 09:25:10 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 17 Oct 2014 18:24:47 +0200 Message-Id: <1413563095-27301-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1413563095-27301-1-git-send-email-pbonzini@redhat.com> References: <1413563095-27301-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH qom v4 05/13] qom: Demote already-has-a-parent to a regular error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Crosthwaite , afaerber@suse.de, agraf@suse.de From: Peter Crosthwaite Rather than an abort(). This allows callers to decide whether parenting an already-parented object is a fatal error condition. Useful for providing a default value for an object's parent in the case where you want to set one iff it doesn't already have one. Reviewed-by: Alexander Graf Signed-off-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index 7d617da..04cb6fd 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1079,6 +1079,11 @@ void object_property_add_child(Object *obj, const char *name, gchar *type; ObjectProperty *op; + if (child->parent != NULL) { + error_setg(errp, "child object is already parented"); + return; + } + type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child))); op = object_property_add(obj, name, type, object_get_child_property, NULL, @@ -1090,7 +1095,6 @@ void object_property_add_child(Object *obj, const char *name, op->resolve = object_resolve_child_property; object_ref(child); - g_assert(child->parent == NULL); child->parent = obj; out: -- 2.1.0