From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbwrn-00017d-HO for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:16:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbwrl-00012V-W0 for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:16:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22845) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbwrl-00012J-O9 for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:16:37 -0500 Message-ID: <50AFAF70.2070500@redhat.com> Date: Fri, 23 Nov 2012 18:16:32 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> <1353660436-8897-5-git-send-email-pbonzini@redhat.com> <50AFAD61.4040907@suse.de> In-Reply-To: <50AFAD61.4040907@suse.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-15?Q?Andreas_F=E4rber?= Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, qemu-devel@nongnu.org, Liu Ping Fan Il 23/11/2012 18:07, Andreas F=E4rber ha scritto: >> > bus =3D g_malloc0(sizeof(*bus)); >> > - bus->qbus.glib_allocated =3D true; >> > pci_bus_new_inplace(bus, parent, name, address_space_mem, >> > address_space_io, devfn_min); >> > + OBJECT(bus)->free =3D g_free; > Anthony asked not to use the macros like this, but in this case to have > Object *obj; to assign it after g_malloc0() and use obj->free =3D g_fre= e; > here. All of the alternatives look ugly: /* malloc mismatch, ouch */ obj =3D g_malloc0(sizeof(PCIBus)); bus =3D PCI_BUS(obj); /* Cast to superclass? */ bus =3D g_malloc0(sizeof(*bus)); obj =3D OBJECT(bus); /* Huge path to access the member */ bus->qbus.obj->free =3D g_free; The right solution would be to have qbus_init: void qbus_init(BusState *bus, DeviceState *parent, const char *name) { object_initialize(bus, typename); bus->parent =3D parent; bus->name =3D name ? g_strdup(name) : NULL; qbus_realize(bus); } void qbus_create_inplace(BusState *bus, const char *typename, DeviceState *parent, const char *name) { object_initialize(bus, typename); qbus_init(bus, parent, name); } and just use object_new + qbus_init. But it is more invasive, I'd prefer the least pleasant but smaller alternative now. Paolo