From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWhgq-0005Wt-IE for qemu-devel@nongnu.org; Tue, 11 Dec 2018 08:03:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWhgn-0000Fq-7h for qemu-devel@nongnu.org; Tue, 11 Dec 2018 08:03:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWhgm-0000FE-UG for qemu-devel@nongnu.org; Tue, 11 Dec 2018 08:03:05 -0500 Date: Tue, 11 Dec 2018 14:03:01 +0100 From: Igor Mammedov Message-ID: <20181211140301.5c9e42ab@redhat.com> In-Reply-To: References: <20181204142023.15982-1-marcandre.lureau@redhat.com> <20181204142023.15982-13-marcandre.lureau@redhat.com> <20181210180503.2cd631cf@Igors-MacBook-Pro.local> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH for-3.2 v5 12/19] qdev-props: convert global_props to GPtrArray List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?TWFyYy1BbmRyw6k=?= Lureau Cc: QEMU , Eduardo Habkost On Tue, 11 Dec 2018 16:12:58 +0400 Marc-Andr=C3=A9 Lureau wrote: > Hi >=20 > On Mon, Dec 10, 2018 at 9:07 PM Igor Mammedov wrote: > > > > On Tue, 4 Dec 2018 18:20:16 +0400 > > Marc-Andr=C3=A9 Lureau wrote: > > =20 > > > A step towards being able to call a common function, > > > object_apply_global_props(). > > > > > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > > --- > > > hw/core/qdev-properties.c | 29 ++++++++++++++++++++--------- > > > 1 file changed, 20 insertions(+), 9 deletions(-) > > > > > > diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c > > > index 43c30a57f4..3467e0485c 100644 > > > --- a/hw/core/qdev-properties.c > > > +++ b/hw/core/qdev-properties.c > > > @@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, cons= t char *name, void *value) > > > *ptr =3D value; > > > } > > > > > > -static GList *global_props; > > > +static GPtrArray *global_props(void) > > > +{ > > > + static GPtrArray *gp; > > > + > > > + if (!gp) { > > > + gp =3D g_ptr_array_new(); =20 > > one more leak? =20 >=20 > We leak the global_props list before and using a list is going to use > more memory than using a GPtrArray. >=20 > If you worry about the global leaks, we can adress it with > destructors. I don't think that matters here. We don't do it for a bunch of 'static' objects, so as Eduardo pointed out it's not worth it or more precisely it's broken currently and it's out of the scope of this series to fix it up. >=20 > > =20 > > > + } > > > + > > > + return gp; > > > +} > > > > > > void qdev_prop_register_global(GlobalProperty *prop) > > > { > > > - global_props =3D g_list_append(global_props, prop); > > > + g_ptr_array_add(global_props(), prop); > > > } > > > > > > int qdev_prop_check_globals(void) > > > { > > > - GList *l; > > > - int ret =3D 0; > > > + int i, ret =3D 0; > > > > > > - for (l =3D global_props; l; l =3D l->next) { > > > - GlobalProperty *prop =3D l->data; > > > + for (i =3D 0; i < global_props()->len; i++) { > > > + GlobalProperty *prop; > > > ObjectClass *oc; > > > DeviceClass *dc; > > > + > > > + prop =3D g_ptr_array_index(global_props(), i); > > > if (prop->used) { > > > continue; > > > } > > > @@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void) > > > > > > void qdev_prop_set_globals(DeviceState *dev) > > > { > > > - GList *l; > > > + int i; > > > > > > - for (l =3D global_props; l; l =3D l->next) { > > > - GlobalProperty *prop =3D l->data; > > > + for (i =3D 0; i < global_props()->len; i++) { > > > + GlobalProperty *prop; > > > Error *err =3D NULL; > > > > > > + prop =3D g_ptr_array_index(global_props(), i); > > > if (object_dynamic_cast(OBJECT(dev), prop->driver) =3D=3D NU= LL) { > > > continue; > > > } =20 > > > > =20 >=20 >=20