-
Notifications
You must be signed in to change notification settings - Fork 712
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
Generate methods that invoke vtable pointers #27
Comments
Just a quick update: The vtables before were absolutely wrong anyway (didn't take into account destructors, etc.). Also, MSVC packs virtual method overrides differently from the rest of the compilers, so this will require target-specific code (which is not a huge deal though, we already do it). In any case, this is still a major amount of work, though certainly useful. I'll consider implementing it if there's enough need for it, though the logic is surely complex. |
I was searching for information regarding this feature in bindgen. As I understand, it still has to be done as of may 2018. Is there any hope it will be considered at some point? Thanks |
It's not really trivial, someone needs to go ahead and implement it properly, and add a bunch of tests. I'd be happy to mentor, though I'm not sure if I'd have the time to do it myself. |
Bindgen doesn't play nice with virtual functions. rust-lang/rust-bindgen#27 rust-lang/rust-bindgen#1400
This is basically a matter of implementing this: rust-bindgen/src/codegen/mod.rs Lines 997 to 1018 in 91d9600
Which already has a reference to all methods and base classes. Making this work for simple casses (no base classes, no overloaded methods) should be trivial. From there we can improve. |
Turns out that `bindgen` can actually parse the `NvInfer.h` file pretty ok in most situations. This removes a lot of the need for extra indirection and dynamic allocation that we were doing before to wrap it in a C API. Only outstanding issue is that it doesn't automatically generate bindings to pure virtual functions. All member functions in the `NvInfer.h` file are pure virtual so we just get the types but not their methods. To fix this we still need a very thin wrapper that accepts the type as the first parameter and then calls the appropriate function directly on the type. There is an issue tracking this rust-lang/rust-bindgen#27 that hopefully will remove the need for this thin wrapper completely.
Turns out that `bindgen` can actually parse the `NvInfer.h` file pretty ok in most situations. This removes a lot of the need for extra indirection and dynamic allocation that we were doing before to wrap it in a C API. Only outstanding issue is that it doesn't automatically generate bindings to pure virtual functions. All member functions in the `NvInfer.h` file are pure virtual so we just get the types but not their methods. To fix this we still need a very thin wrapper that accepts the type as the first parameter and then calls the appropriate function directly on the type. There is an issue tracking this rust-lang/rust-bindgen#27 that hopefully will remove the need for this thin wrapper completely.
Is this fixed via #2145? |
Yes, use this to generate a basic vtable let bindings = bindgen::Builder::default()
.header("wrapper.hpp")
.clang_arg("-x")
.clang_arg("c++")
.clang_arg("-std=c++11")
.derive_default(true)
.derive_debug(true)
.vtable_generation(true)
.generate_comments(false)
.layout_tests(false)
.generate_comments(false)
.derive_copy(true)
.derive_hash(false)
.parse_callbacks(Box::new(MyCallback {}))
.generate()
.expect("Unable to generate bindings"); With |
We generate glue for C++ classes with virtual tables (for example, CustomAutoRooter in rust-mozjs), but we don't generate methods that fetch the function pointer from the vtable and invoke it with the this pointer. That would be a significant improvement in usability.
The text was updated successfully, but these errors were encountered: