qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups


From: Michael S. Tsirkin
Subject: Re: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups
Date: Sun, 21 Mar 2010 16:31:03 +0200
User-agent: Mutt/1.5.19 (2009-01-05)

On Fri, Mar 19, 2010 at 01:41:59AM +0000, Jamie Lokier wrote:
> Juan Quintela wrote:
> > vstrucut virtio_common *create_virtio_comon(...., size we really want);
> > Again, this implements superclass/subclass as well as you can implemnt
> > it in C.
> 
> It would be more type-safe for create_virtio_common() to be a macro
> taking the subclass *type* rather than sizeof.
> 
> And it would make the calls short: No need to cast the result, because
> the macro would return the desired type (doing the cast itself).
> 
> #define create_virtio_common(...., type) \
>    ((type *)_create_virtio_common(...., sizeof(type)))
> 
> Once you have that, it's easy to change to add a field name and
> container_of:
> 
> #define create_virtio_common(...., type, field) \
>    (container_of(_create_virtio_common(...., sizeof(type)), type, field))
> 
> That gives you malloc in common init, and type-safe callers everywhere
> (no possibility for mistaken sizeof).
> 
> I think it's a simpler to use API and better at protecting against
> caller mistakes; you may disagree.
> 
> -- Jamie

That's version 1 of my patch. Version 2 removed even need for macro
completely by moving allocations to the caller.

-- 
MST




reply via email to

[Prev in Thread] Current Thread [Next in Thread]