Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong "this" pointer in methods called via IUnknown derived interfaces #18629

Open
dlangBugzillaToGithub opened this issue Jul 12, 2013 · 1 comment
Labels

Comments

@dlangBugzillaToGithub
Copy link

Sönke Ludwig (@s-ludwig) reported this on 2013-07-12T07:52:57Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10622

Description

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
@dlangBugzillaToGithub
Copy link
Author

sludwig (@s-ludwig) commented on 2013-07-12T08:50:03Z

Actually, as far as I understand, the pointer is correct and the function body is wrong in assuming that it points to the object's base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant