On Thu, 30 Oct 2025, Paolo Bonzini wrote:
On 10/29/25 20:20, Peter Xu wrote:
On Wed, Oct 29, 2025 at 11:30:10AM +0100, BALATON Zoltan wrote:
memory_region_new_* will work, but I don't think removing unnecessary
but harmless fields from a device state structure does not sufficiently
motivates adding them.

I haven't given up on this yet, that's why I alternatively proposed

object_alloc (same as object_new without object_initialize)
memory_region_init

which is just a small change but should also work without adding
memory_region_new convenience functions. Then only object_alloc needs to be
added.

IMHO if this will ever happen, memory_region_new*() is better, unless
object_alloc() can be used anywhere besides MemoryRegion..

It seems to me, MemoryRegion is the only one I'm aware of that may need
such tweak, rather than using object_new() directly.

Yes, pretty much. Anyhow, leaking on purpose with g_new is not a good idea. It's g_new, not g_leak; and everyone else is using a field in the device structure so I don't see why one would want to do differently.

I've tried to explain why I dislike that way in previous replies in this thread but here's a short summary:

- Not piling memory regions not otherwise needed in device struct makes it easier to understand. (Could you spot errors within the lot of boiler plate code before clean up? Having less code makes it more comprehensible.)

- Documentation says it should work this way QOM managing memory regions so it was meant to be that way. I'd rather fix code than documentation as I think if it just works that's easier than loosing that convenience.

- Allows simpler device models reusing superclasses without having to write much boiler plate code to create a subclass.

I'll send some patches that can be discussed later.

Regards,
BALATON Zoltan

Reply via email to