-
Notifications
You must be signed in to change notification settings - Fork 724
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
Using a class with a std::unique_ptr member #1389
Comments
That's the correct layout for it, right? Assuming you're in a 64-bit system. If you see a unique_ptr returned as a u8, that's clearly a bug, and I'd appreciate a test-case for it. Thanks! |
If |
@emilio there are 2 issues here, I'll talk about the std::unique_ptr one and file another for the second. Yes, I'm on 64 bit. I discovered the std::unique_ptr being represented by a u8 while working with V8, on my repo for the previous issue. The function signiture in C++ is:
Which has the corresponding binding:
|
Hmm, I don't think getting and returning unique_ptr's is going to work, at least on MSVC, where we can't convince rustc to use the same ABI. In particular, MSVC will return the pointer on a reserved slot on the stack, while rustc will expect it in a register. |
See rust-lang/rust#38258 and #778. |
Ah. I wonder if you've thought about automatically generating C++ code for the constructs that can't easily cross the Rust/C++ boundary like this one, sort of what Swig has done for scripting languages. Unfortunately, it doesn't support a C backend, which would make using C++ a lot easier. |
Yeah, that's one of the solutions proposed in #778. I haven't thought of a great design for that, but if somebody had the cycles to prototype it I'd be happy to mentor as needed :) |
Hm, I have no background in ASTs, compilers and the like, so I'm not even sure how to approach this problem. This is definitely a motivating enough project that I could see myself attempting to learn it, especially if I had some help, though I'm not sure how big this project would be. Does Clang expose enough information about the parsed C++ files to make this feasible? |
Well, sort of, anything that bindgen can generate we already read... There's an idea to make this even better (because libclang isn't that good at templates) which is #297. You can reproduce that bug without much template magic: template<typename T>
class SmartPtr
{
T* m_raw;
~SmartPtr();
};
SmartPtr<int> do_something(); So making that solution work should definitely be doable without #297. Making it work for the C++ standard library and the like might be a bit harder? But in any case I'd treat both issues as different projects. |
Closing as everything that's actionable on bindgen's side is tracked in other issues. |
Hi,
I'm attempting to create an instance of a class with a unique ptr, among other members in it, and invoke some methods. Its crashing probably because the struct layout doesn't match.
I've seen several instances where std::unique_ptr members in classes are being represented as a u64 by bindgen and even once, returned as a u8 by a function that returns a unique_ptr.
I've set everything under the std namespace to be treated as an opaque type, so I'm wondering if I need to specifically whitelist these to have them represented properly.
The text was updated successfully, but these errors were encountered: