Biohazrd icon indicating copy to clipboard operation
Biohazrd copied to clipboard

Meta: Improve friendliness of building vtables

Open PathogenDavid opened this issue 3 years ago • 1 comments

Building vtables to create C# classes derived from C++ ones is rather tedious and error-prone in Biohazrd. This issue tracks ideas for ways we could improve this situation.

  • [ ] Create an anlyzer to error when pure virtual methods aren't overridden.
  • [ ] Make helpers for building vtables.
  • [ ] Create guidance on extending vtables in C# to include a GCHandle.
  • [ ] Provide a way to get the base vtable of a C++ type.
    • Is there an easy way to do this without initializing the base class?
    • Since C++'s vtable initialization semantics are completely different from C#'s*, we could get away with creating the modified vtable lazily and end up with the right result. Need to do a little research of how C++ handles this. (Does the derived vtable get fully populated at compile time or only the differences? -- Seems to be fully populated based on this test. How does this work when BaseClass is in a DLL?)
    • *In C++, the vtable is initialized by the constructor (if it exists), so the base class doesn't have access to virtual methods in the derived class during construction. This is in contrast to the CLR, which initializes the vtable before any constructors are run. (For example, compare this C++ example with this C# one.)

PathogenDavid avatar Nov 07 '20 10:11 PathogenDavid

Related: https://github.com/InfectedLibraries/Biohazrd/issues/192

PathogenDavid avatar Jun 21 '21 20:06 PathogenDavid