rust-lang / rust-lang/rust-bindgen

Enhancing VTable Generation to Support Inherited Classes

Open
#2,799 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
class IUnknown {
public:
    virtual void Release() {
        delete this;
    };
};

class iTH : public IUnknown {
public:
    virtual void AccessibleFunction() = 0;
};

class CTH: public iTH {
public:
    CTH() = default;

    void AccessibleFunction() override {};
};

iTH *CreateITH() {
    return (iTH *)(new CTH());
}

int main() {
    iTH *ptr = CreateITH();
    ptr->AccessibleFunction();
    ptr->Release();
    return 0;
}
Bindgen Invocation
bindgen::Builder::default()
    .header("input.h")
    .vtable_generation(true)
    .generate()
    .unwrap()
Actual Results

Currently, the vtable generation is limited to virtual classes without any base members.

Expected Results

The expectation is to extend vtable generation to support more complex class hierarchies.

Current Work Status

I'm in the process of addressing this issue through a PR. My aim is to remove the limitation preventing the generation from working with classes that have inheritance. However, I've encountered some hurdles along the way. It would be immensely helpful to connect with a maintainer of rust-bindgen to discuss the underlying architecture in more detail.

So far, I've made progress, but I've hit a roadblock. Specifically, I'm unsure how to access the comp_info of base members in order to retrieve their associated fields, types, and sizes. My goal is to associate a VTable declaration for each class with accurate information. Additionally, I aim to incorporate base member fields directly into each class, rather than adding base_XXX fields to each class (which occurs due to vtable merging).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied C++ hierarchy and the bindgen::Builder invocation using vtable_generation(true); trace how inherited virtual classes are represented. Done means vtable generation handles the IUnknown → iTH → CTH hierarchy, including inherited members and class fields. No files or tests are named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.