From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NtdCR-0005FU-RE for qemu-devel@nongnu.org; Mon, 22 Mar 2010 04:41:27 -0400 Received: from [199.232.76.173] (port=35937 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NtdCQ-0005FF-Nt for qemu-devel@nongnu.org; Mon, 22 Mar 2010 04:41:26 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NtdCP-0004GE-7B for qemu-devel@nongnu.org; Mon, 22 Mar 2010 04:41:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1030) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NtdCO-0004G2-Pd for qemu-devel@nongnu.org; Mon, 22 Mar 2010 04:41:25 -0400 Date: Mon, 22 Mar 2010 10:37:58 +0200 From: "Michael S. Tsirkin" Message-ID: <20100322083758.GA16574@redhat.com> References: <20100318074239.GA23474@redhat.com> <20100318090711.GB23649@redhat.com> <20100319014159.GB14108@shareable.org> <20100321143103.GD12758@redhat.com> <20100321181143.GE4174@shareable.org> <20100321195700.GB13355@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org On Mon, Mar 22, 2010 at 02:13:48AM +0100, Juan Quintela wrote: > "Michael S. Tsirkin" wrote: > > On Sun, Mar 21, 2010 at 06:11:43PM +0000, Jamie Lokier wrote: > >> Michael S. Tsirkin wrote: > >> > That's version 1 of my patch. Version 2 removed even need for macro > >> > completely by moving allocations to the caller. > >> > >> The downside of moving allocations are: (1) it's one more call in the > >> caller, to allocate the type, (2) it needs a virtual destructor for > >> each type to free the object, which can clutter the code if there is > >> no other reason for virtual destructors. > > > > BTW I don't understand why do you refer to virtual destructors here. > > When virtio-net.c allocates and frees structure of type VirtIONet > > this is analogous to regular destructur, not a virtual one. > > If you remove it in virtio-net.c, you are right. > > If your remove it in virtio.c, then you need the equivalent of a virtual > destructor (somehow you need to find a field that is an offset and do a > free(pointer- offset). > > If struct VirtIODevice is the 1st field of everything, then a simple > free(pointer) is enough and does the right thing. > > Notice that as just now there is no free call, you can put it in either > place. We should remove it in virtio-net.c. We need to do cleanup there anyway. > > >> I don't think those are necessarily bad, but they can remove from the > >> neatness of existing code. Personally I favour an occasional macro > >> using sizeof/offsetof/container_of if the result is a natural and > >> sensible API to all of its callers. > >> > >> -- Jamie > > Later, Juan.