On 11/20/21 7:19 AM, frame wrote:

> I think this is true for an object instance. But from an interface
> instance, the object instance must be accessible somewhere?

Everything needed is available from the pointer to a class object (or interface). There are some offset arithmetic involved to get to the right vtbl pointer but the pointer of an object cannot be stored anywhere in the vtbl because there is just one vtbl but very many objects.

> This is also
> how I would read the doc:
>
>> The vtbl[0] entry is a pointer to the corresponding instance of the
>> object.Interface class.

That is from

  https://dlang.org/spec/abi.html

What they mean with object.Instance is the following definition I find e.g. in my /usr/include/dmd/druntime/import/object.d file:

/**
 * Information about an interface.
* When an object is accessed via an interface, an Interface* appears as the
 * first entry in its vtbl.
 */
struct Interface
{
TypeInfo_Class classinfo; /// .classinfo for this interface (not for containing class)
    void*[]     vtbl;
size_t offset; /// offset to Interface 'this' from Object 'this'
}

So, the first entry is a pointer to that struct.

The ABI document mentions "pointer to instance of TypeInfo" as well, which is defined in the same object.d as well:

/**
 * Runtime type information about a type.
 * Can be retrieved for any type using a
 * $(GLINK2 expression,TypeidExpression, TypeidExpression).
 */
class TypeInfo
{
  // ...
}

Ali

Reply via email to