From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NsRE1-0004gm-HC for qemu-devel@nongnu.org; Thu, 18 Mar 2010 21:42:09 -0400 Received: from [199.232.76.173] (port=43855 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsRDz-0004ge-W1 for qemu-devel@nongnu.org; Thu, 18 Mar 2010 21:42:08 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NsRDx-0003Cu-4t for qemu-devel@nongnu.org; Thu, 18 Mar 2010 21:42:07 -0400 Received: from mail2.shareable.org ([80.68.89.115]:52096) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NsRDw-0003Cm-Rb for qemu-devel@nongnu.org; Thu, 18 Mar 2010 21:42:05 -0400 Date: Fri, 19 Mar 2010 01:41:59 +0000 From: Jamie Lokier Subject: Re: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups Message-ID: <20100319014159.GB14108@shareable.org> References: <20100318064015.GA16973@redhat.com> <20100318074239.GA23474@redhat.com> <20100318090711.GB23649@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" 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