[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] Issues around TYPE_INTERFACE
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] Issues around TYPE_INTERFACE |
Date: |
Wed, 3 Apr 2019 21:33:19 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
On 03/04/19 10:53, Markus Armbruster wrote:
> Why (1) our interfaces can't have state:
>
> Since interfaces are abstract, there's no such thing as an interface
> instance.
Well, there is. Since all class instances are Objects, and interfaces
are applied to classes, interface instances must be Object. In fact,
INTERFACE_CHECK() expects that to be the case, since it needs to go
spelunking into the class. However, it is an implementation detail as
far as the interface _user_ is concerned.
> When @obj points to an instance of MyFrob, then we can safely cast it to
> any supertype of MyFrob.
>
> MyIface is not a supertype of MyFrob, it's an interface. WTF?
>
> Turns out we only ever define MyIface in one of two ways:
>
> typedef struct MyIface MyIface; // incomplete
>
> typedef struct MyIface { // fake subtype of Object
> Object parent;
> } MyIface;
>
> If we somehow know that only subtypes of SuperFrob have interface
> MyIface, then we can exploit that and safely cast to SuperFrob * or any
> of its supertypes.
I'm not sure we want to know that. That said, the incomplete type is
much nicer. Anybody wants to add a BiteSizedTask.
Paolo