From: Paolo Bonzini <pbonzini@redhat.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
qemu-devel@nongnu.org, Liu Ping Fan <qemulist@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses
Date: Fri, 23 Nov 2012 18:16:32 +0100 [thread overview]
Message-ID: <50AFAF70.2070500@redhat.com> (raw)
In-Reply-To: <50AFAD61.4040907@suse.de>
Il 23/11/2012 18:07, Andreas Färber ha scritto:
>> > bus = g_malloc0(sizeof(*bus));
>> > - bus->qbus.glib_allocated = true;
>> > pci_bus_new_inplace(bus, parent, name, address_space_mem,
>> > address_space_io, devfn_min);
>> > + OBJECT(bus)->free = 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 = g_free;
> here.
All of the alternatives look ugly:
/* malloc mismatch, ouch */
obj = g_malloc0(sizeof(PCIBus));
bus = PCI_BUS(obj);
/* Cast to superclass? */
bus = g_malloc0(sizeof(*bus));
obj = OBJECT(bus);
/* Huge path to access the member */
bus->qbus.obj->free = 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 = parent;
bus->name = 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
next prev parent reply other threads:[~2012-11-23 17:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 8:47 [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects Paolo Bonzini
2012-11-23 16:49 ` Andreas Färber
2012-11-26 15:49 ` Anthony Liguori
2012-11-26 16:08 ` Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 2/5] qdev: move bus removal to object_unparent Paolo Bonzini
2012-11-23 16:52 ` Andreas Färber
2012-11-27 1:02 ` Andreas Färber
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 3/5] qom: make object_delete usable for statically-allocated objects Paolo Bonzini
2012-11-23 17:02 ` Andreas Färber
2012-11-23 17:10 ` Paolo Bonzini
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses Paolo Bonzini
2012-11-23 17:07 ` Andreas Färber
2012-11-23 17:16 ` Paolo Bonzini [this message]
2012-11-23 8:47 ` [Qemu-devel] [PATCH 1.3 5/5] qom: make object_finalize static Paolo Bonzini
2012-11-23 17:12 ` Andreas Färber
2012-11-23 17:32 ` Paolo Bonzini
2012-11-26 21:47 ` [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50AFAF70.2070500@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).