Bug 1712 – vtbl[0] for interface not set to corresponding Interface*
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-12-02T21:00:00Z
Last change time
2015-06-09T01:14:23Z
Keywords
spec
Assigned to
bugzilla
Creator
dhasenan
Comments
Comment #0 by dhasenan — 2007-12-02T21:00:39Z
From the spec:
"""
struct Interface;
Information about an interface. A pointer to this appears as the first entry in the interface's vtbl[].
"""
By implication, the vtbl has to be a void* array of length one, and the first entry must be non-null.
---
interface IFoo {};
writefln("%x", IFoo.classinfo.vtbl.ptr); // prints '0'
---
Comment #1 by bugzilla — 2008-01-20T00:48:37Z
The vtbl[] for an interface is not in the interface's classinfo, as the vtbl[] is not generated by the interface definition, but by the class definition that implements the interface.
Comment #2 by dhasenan — 2008-01-20T10:53:37Z
So you're saying that the Interface* should appear in the vtbl of each implementing class? Like this:
---
interface IFoo {}
class Foo : IFoo {}
// Foo implements one more interface than Object, so its vtbl includes
// one Interface* that Object doesn't. Nothing else is specific to Foo.
assert(Object.classinfo.vtbl.length + 1 == Foo.classinfo.vtbl.length);
---
Except that doesn't work.
I understand that the vtbl of an interface should not include any function pointers. However, the spec says it should hold an Interface*. http://www.digitalmars.com/d/phobos/object.html if you want the link. Either the spec is incorrect or the implementation is incorrect. If the spec is incorrect, then I cannot proxy certain objects, and you should alter the documentation.
Or is there some other vtbl in which the Interface* should appear? If so, the documentation is far from clear on the matter and should be altered.
Comment #3 by dhasenan — 2008-01-21T09:13:29Z
Please amend the documentation to say:
"When an object is accessed via an interface, an Interface* appears as the first entry in its vtbl."
Thanks to Bill Baxter for digging up a link related to this issue.