From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHANF-0007qS-Qr for qemu-devel@nongnu.org; Tue, 12 Aug 2014 07:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHANA-00074X-85 for qemu-devel@nongnu.org; Tue, 12 Aug 2014 07:36:17 -0400 Received: from cantor2.suse.de ([195.135.220.15]:42690 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHANA-00073S-1N for qemu-devel@nongnu.org; Tue, 12 Aug 2014 07:36:12 -0400 Message-ID: <53E9FC27.7@suse.de> Date: Tue, 12 Aug 2014 13:36:07 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <9e52946a183e4c6371285df8d7a99febd546998c.1407128441.git.peter.crosthwaite@xilinx.com> In-Reply-To: <9e52946a183e4c6371285df8d7a99febd546998c.1407128441.git.peter.crosthwaite@xilinx.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH qom v2 1/2] qom: object_property_add: Add automatic arrayification List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite , qemu-devel@nongnu.org Cc: pbonzini@redhat.com Am 04.08.2014 07:08, schrieb Peter Crosthwaite: > If "[*]" is given as the last part of a QOM property name, treat that > as an array property. The added property is given the first available > name, replacing the * with a decimal number counting from 0. >=20 > First add with name "foo[*]" will be "foo[0]". Second "foo[1]" and so > on. I think it's worth mentioning here that the caller learns about which one has been created through the ObjectProperty return value - which is not immediately obvious from the diff. >=20 > Signed-off-by: Peter Crosthwaite > --- > changed since v1 (Paolo review): > Cache strlen result in variable > Use memcmp instead of strncmp >=20 > Suggest by Paolo and first pass discussion on list about the feature > here: >=20 > https://lists.nongnu.org/archive/html/qemu-devel/2014-06/msg03794.html >=20 > qom/object.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) >=20 > diff --git a/qom/object.c b/qom/object.c > index 0e8267b..4484330 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -738,6 +738,29 @@ object_property_add(Object *obj, const char *name,= const char *type, > void *opaque, Error **errp) > { > ObjectProperty *prop; > + size_t name_len =3D strlen(name); > + > + if (name_len >=3D 3 && !memcmp(name + name_len - 3, "[*]", 4)) { > + int i; > + ObjectProperty *ret; > + char *name_no_array =3D g_strdup(name); > + > + name_no_array[name_len - 3] =3D '\0'; > + for (i =3D 0; ; ++i) { > + char *full_name =3D g_strdup_printf("%s[%d]", name_no_arra= y, i); > + Error *local_err =3D NULL; White line missing here... > + ret =3D object_property_add(obj, full_name, type, get, set= , > + release, opaque, &local_err); > + ... but present here. > + g_free(full_name); > + if (!local_err) { > + break; > + } > + error_free(local_err); Can't we do this without creating and throwing away an Error by comparing the list of obj->properties against full_name like below? > + } > + g_free(name_no_array); > + return ret; > + } > =20 > QTAILQ_FOREACH(prop, &obj->properties, node) { > if (strcmp(prop->name, name) =3D=3D 0) { Regards, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg