All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: Peter Crosthwaite <peter.crosthwaite@petalogix.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] qom: add unit test for Interfaces
Date: Mon, 18 Jun 2012 09:54:35 -0500	[thread overview]
Message-ID: <4FDF412B.3070606@us.ibm.com> (raw)
In-Reply-To: <4FDF3262.4090400@suse.de>

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
>

  reply	other threads:[~2012-06-18 15:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13 20:54 [Qemu-devel] [PATCH 0/3] qom: refactor Interfaces Anthony Liguori
2012-06-13 20:55 ` [Qemu-devel] [PATCH 1/3] tests: fix dependency inclusion Anthony Liguori
2012-06-14 13:08   ` Andreas Färber
2012-06-14 13:12     ` Paolo Bonzini
2012-06-13 20:55 ` [Qemu-devel] [PATCH 2/3] qom: reimplement Interfaces Anthony Liguori
2012-06-16 10:47   ` Peter Crosthwaite
2012-06-22 11:29     ` Peter Crosthwaite
2012-06-13 20:55 ` [Qemu-devel] [PATCH 3/3] qom: add unit test for Interfaces Anthony Liguori
2012-06-16 10:31   ` Peter Crosthwaite
2012-06-18 13:26     ` Anthony Liguori
2012-06-18 13:46       ` Peter Crosthwaite
2012-06-18 13:51         ` Andreas Färber
2012-06-18 14:54           ` Anthony Liguori [this message]
2012-06-14  9:10 ` [Qemu-devel] [PATCH 0/3] qom: refactor Interfaces Paolo Bonzini
2012-06-15  4:58 ` Peter Crosthwaite

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FDF412B.3070606@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=afaerber@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@petalogix.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.