interfaces ABI

BCS BCS at pathlink.com
Mon Mar 19 11:26:11 PDT 2007


Luís Marques wrote:
> Hello,
> 
> The interfaces ABI is marked "TBD". Could this be filled, please?
> 
> I found the following surprising, regarding the ABI:
> 
> An object only has a pointer to the vtable and a monitor, the rest being 
> the actual data ("non-static members"). At the vtable's offset 0 we find 
> a pointer to the classinfo. And the classinfo has an array of 
> interfaces. So when I add an interface, I would assume the objects to 
> remain equal in size. The classinfo would get a bigger array of 
> interfaces, and perhaps the vtable would also get bigger. But since no 
> non-static member were added to the class, I expected the object size to 
> be equal. Yet, it gets bigger.
> 
> -- 
> Luís

IIRC interface are implemented by adding a pointer to the interfaces 
v-tbl to the object, then when a object is cast to an interface the 
interface ends up as a pointer to /it's/ v-tbl in the object. The reason 
for this is that the interface's v-tbl includes an offset to the start 
of the object. When an interface is used to make a call it ends up 
looking something like this.

I i;

((*i)[member_offset]) (i+(*i)[v_tbl_offset], /** args **/ )

Why the v-tbls are in the classinfo? I don't know.

What I would like to see is interfaces become a context/v-tbl pair (sort 
of like arrays being a pointer/length pair). Then, when an interface is 
used to make a call it would end up looking something like this.

I i;

(i.vtbl[member_offset]) (i.context, /** args **/ )

this would free classes from having to carry around a v-tbl pointer and 
also let other things like struct and functions implement interfaces.



More information about the Digitalmars-d mailing list