From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XobPg-0007xu-S3 for qemu-devel@nongnu.org; Wed, 12 Nov 2014 12:09:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XobPa-0004y6-G2 for qemu-devel@nongnu.org; Wed, 12 Nov 2014 12:09:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XobPa-0004xJ-8T for qemu-devel@nongnu.org; Wed, 12 Nov 2014 12:08:54 -0500 From: Markus Armbruster Date: Wed, 12 Nov 2014 18:08:47 +0100 Message-Id: <1415812130-2592-2-git-send-email-armbru@redhat.com> In-Reply-To: <1415812130-2592-1-git-send-email-armbru@redhat.com> References: <1415812130-2592-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 1/4] qom: New object_gen_new_property_name() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, peter.crosthwaite@xilinx.com, afaerber@suse.de The next few commits will use it to replace object_property_add()'s "automatic arrayification" (commit 3396590). "Automatic arrayification" is a convenience feature for creating a bunch of properties with a common type, accessors and so forth, named in a peculiar way: "foo[0]", "foo[1]", ... It's implemented by making property names ending with "[*]" magical. The magic is uncalled for, as names can be just as well generated separately from adding properties. The name object_gen_new_property_name() is exceedingly long, but that's how QOM names are. Signed-off-by: Markus Armbruster --- include/qom/object.h | 8 ++++++++ qom/object.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 89c3092..b5c9201 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -832,6 +832,14 @@ void object_property_del(Object *obj, const char *name, Error **errp); ObjectProperty *object_property_find(Object *obj, const char *name, Error **errp); +/* + * Return a property name that doesn't clash with @obj's existing ones. + * The name is of the form %s[%d], where %s is @stem, and %d counts up + * from zero. + * The caller should free the name. + */ +char *object_gen_new_property_name(Object *obj, const char *stem); + void object_unparent(Object *obj); /** diff --git a/qom/object.c b/qom/object.c index 1812c73..4c46662 100644 --- a/qom/object.c +++ b/qom/object.c @@ -808,6 +808,20 @@ void object_property_del(Object *obj, const char *name, Error **errp) g_free(prop); } +char *object_gen_new_property_name(Object *obj, const char *stem) +{ + int i; + + for (i = 0; ; ++i) { + char *name = g_strdup_printf("%s[%d]", stem, i); + + if (!object_property_find(obj, name, NULL)) { + return name; + } + g_free(name); + } +} + void object_property_get(Object *obj, Visitor *v, const char *name, Error **errp) { -- 1.9.3