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: Jamie Lokier
Subject: Re: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups
Date: Fri, 19 Mar 2010 01:41:59 +0000
User-agent: Mutt/1.5.13 (2006-08-11)

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




reply via email to

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