You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(where the struct std_unique_ptr<u8> does indeed contain a pointer to a u8).
These 'expected results' are what we get if we alter the C++ to uncomment the line A and comment the line B.
Diagnosis
The test case above is a minimized version of std::unique_ptr and all its dependencies. It sadly depends on template specialization, so it's unsurprising that bindgen doesn't do a perfect job.
Here's what it's trying to do:
unique_ptr contains a __pointer_type<main type, deleter type>. There are two specializations of __pointer_type:
For deleter_types which declare a typename called pointer, that's what gets used.
For anything else, main type* gets used.
Solution
I get that this is very, very hard and presumably the solutions are those explored in #297 and involve (at least) bindgen being able to calculate any constexpr to work out the correct template specialization! (or to use clang in a completely different way to ask it the same questions).
Mostly I'm writing this up so that other people who search the bindgen issues list for unique_ptr get a write up of why it doesn't work yet.
Context
I'm generating snippets of code for use with https://github.com/dtolnay/cxx (my very early experiments are here: https://github.com/google/autocxx). I'd like to be able to use bindgen to replace std_unique_ptr<T> with UniquePtr<T>. But, at the moment, bindgen simply discards the <T> bit because bindgen's analysis on whether the parameter is used decides that it's not.
As I delve deeper into this I might see if I can add a builder method to request bindgen to keep template arguments on certain types which it would otherwise discard. I'm not sure if that'll be possible, but that's the way I'm thinking about this.
What to do with this issue
It should probably be closed as a duplicate of #297!
The text was updated successfully, but these errors were encountered:
So, for reference, returning std::unique_ptr from a function just won't work (generally, at least), because of ABI issues. MSVC treats types with destructors differently from Rust in extern functions, and expects them to be returned differently. That being said, it makes sense to do this anyway IMO.
What we've done for this kind of stuff in Firefox, is using the replaces functionality to replace it with a simpler type, so having something like this fed to bindgen:
Input C/C++ Header
Full test case here: https://gist.github.com/adetaylor/f878dbf25367c2553971bf72b1ed269f (164 lines)
Important bits here:
Bindgen Invocation
Actual Results
The same
std_unique_ptr
type is issued for bothstd::unique_ptr
s even though one points to auint8_t
and the other to auint32_t
.(where
std_unique_ptr
ends up being a struct containing a singleu8
).Expected Results
(where the struct
std_unique_ptr<u8>
does indeed contain a pointer to au8
).These 'expected results' are what we get if we alter the C++ to uncomment the line A and comment the line B.
Diagnosis
The test case above is a minimized version of
std::unique_ptr
and all its dependencies. It sadly depends on template specialization, so it's unsurprising thatbindgen
doesn't do a perfect job.Here's what it's trying to do:
unique_ptr
contains a__pointer_type<main type, deleter type>
. There are two specializations of__pointer_type
:deleter_type
s which declare a typename calledpointer
, that's what gets used.main type*
gets used.Solution
I get that this is very, very hard and presumably the solutions are those explored in #297 and involve (at least) bindgen being able to calculate any
constexpr
to work out the correct template specialization! (or to use clang in a completely different way to ask it the same questions).Mostly I'm writing this up so that other people who search the bindgen issues list for
unique_ptr
get a write up of why it doesn't work yet.Context
I'm generating snippets of code for use with https://github.com/dtolnay/cxx (my very early experiments are here: https://github.com/google/autocxx). I'd like to be able to use bindgen to replace
std_unique_ptr<T>
withUniquePtr<T>
. But, at the moment, bindgen simply discards the<T>
bit becausebindgen
's analysis on whether the parameter is used decides that it's not.As I delve deeper into this I might see if I can add a
builder
method to requestbindgen
to keep template arguments on certain types which it would otherwise discard. I'm not sure if that'll be possible, but that's the way I'm thinking about this.What to do with this issue
It should probably be closed as a duplicate of #297!
The text was updated successfully, but these errors were encountered: