From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgdRW-0003Lz-FX for qemu-devel@nongnu.org; Mon, 18 Jun 2012 11:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgdRU-0002SQ-J7 for qemu-devel@nongnu.org; Mon, 18 Jun 2012 11:00:38 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:38572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgdRU-0002P4-Ai for qemu-devel@nongnu.org; Mon, 18 Jun 2012 11:00:36 -0400 Received: from /spool/local by e6.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 18 Jun 2012 11:00:17 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 8A0C16E8057 for ; Mon, 18 Jun 2012 10:54:43 -0400 (EDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5IEsfSE037204 for ; Mon, 18 Jun 2012 10:54:42 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5IEsbds029658 for ; Mon, 18 Jun 2012 08:54:37 -0600 Message-ID: <4FDF412B.3070606@us.ibm.com> Date: Mon, 18 Jun 2012 09:54:35 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1339620902-4481-1-git-send-email-aliguori@us.ibm.com> <1339620902-4481-4-git-send-email-aliguori@us.ibm.com> <4FDF2C6B.2010607@us.ibm.com> <4FDF3262.4090400@suse.de> In-Reply-To: <4FDF3262.4090400@suse.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 3/3] qom: add unit test for Interfaces List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Andreas_F=E4rber?= Cc: Peter Crosthwaite , Paolo Bonzini , qemu-devel@nongnu.org On 06/18/2012 08:51 AM, Andreas Färber wrote: > Am 18.06.2012 15:46, schrieb Peter Crosthwaite: >>>>> +#define HERBIVORE(obj) \ >>>>> + INTERFACE_CHECK(Herbivore, (obj), TYPE_HERBIVORE) >>>>> + >>>>> +typedef struct Herbivore >>>>> +{ >>>>> + Object obj; >>>>> +} Herbivore; >>>> >>>> >>>> All this is doing is saying Herbivores are Objects right? A user cant >>>> add anything to this struct given that interfaces are stateless so >>>> could this be simplified to >>>> >>>> typedef Object Herbivore; >>> >>> >>> This is admittedly a little wierd... >>> >>> Interfaces don't exist as Objects in QOM. >> >> Not in the sense that they used too, but all objects that implement an >> interface are still OBJECTs just through the inheritance path of their >> concrete class, which is the point of this struct yes? Yes, they are objects, which is why the struct just contains Object. It's basically just a type-safe wrapper for Object. Nothing more than that. >> >> They are just classes. But it's >>> very handy to be able to have a Herbivore type that you can cast objects to. >>> >> >> Yes I agree in full, but the typedef definition is functionally >> equivalent to what you have there, and removes the temptation to add >> fields to the object type. Having a skeletal struct there gives the >> illusion to readers that interface objects are in someway extensible. typedef struct Object Herbivore; is a weak alias. IOW, it's not an error to pass Object * instead of Herbivore *. Worse yet, passing Carnivore * also is not an error. The struct definition provides a strict alias. We could wrap it in a macro to avoid confusing the reader I guess. > Why have a typedef at all then? You can just use Object directly. If > that ever changes it leads to all kinds of problems (well, necessary > adjustments), as seen in the pci_host series. Type safety. Regards, Anthony Liguori > > Andreas >