[Issue 10622] New: Wrong "this" pointer in methods called via IUnknown derived interfaces

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 12 07:52:58 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10622

           Summary: Wrong "this" pointer in methods called via IUnknown
                    derived interfaces
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: sludwig at outerproduct.org


--- Comment #0 from Sönke Ludwig <sludwig at outerproduct.org> 2013-07-12 07:52:57 PDT ---
The following program crashes in the second invocation of AddRef (could be any
other method defined by IUnknown or a derived interface) because the "this"
pointer points to the IUnknown vtable instead of the object's base, which is
assumed by the code.

---
import std.c.windows.com;
import std.c.windows.windows;

class Test : IUnknown {
  int i = 1;
  ULONG AddRef() { assert(i == 1); return 0; }
  ULONG AddRef() { assert(i == 1); return 0; }
  HRESULT AddRef(IID*, void**) { assert(i == 1); return E_FAIL; }
}

void main()
{
  auto t = new Test;
  t.AddRef(); // works
  auto u = cast(IUnknown)t;
  u.AddRef(); // crash in _d_invariant
}
---

Setting this to major severity because it makes defining any COM objects in D
impossible on Win64 (and thus many COM APIs are unusable). Tested on DMD
2.063.2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list