-
Notifications
You must be signed in to change notification settings - Fork 146
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
Wrong offset of CxxString field when preceded by padding #18
Comments
Right, the problem here is that I (stupidly) hadn't realized field access was even possible via (The solution is probably for |
Public fields should be fine as long as there is a way to find out the presence of padding from bindgen. (I have never looked into what information bindgen has; you might already have considered this and it's not possible or would be too platform-specific.) The Rust struct I would expect generated for that input would be something like: #[repr(C)]
pub struct S {
pub i: u32,
_padding0: [u8; 4],
pub s: ::cxx::CxxString,
_actual_s: [u64; 3],
} Notice not all fields are pub which makes the struct not constructible from Rust with an This way we're still able to take references to |
Oh here is a way that would only use information that the current implementation is already using: #[repr(C)]
pub struct S {
pub i: u32,
_align_s: [[u64; 3]; 0], // [T; 0] where T is the type of _actual_s determined through bindgen
pub s: ::cxx::CxxString,
_actual_s: [u64; 3],
} |
Unfortunately, there be doom here. The relevant limitation on bindgen is lack of support for template specialization. It seems from my explorations that any real STL type except This leads to an interesting and worrying question though. In cxx, we have:
For the purposes of field access, we need something slightly different:
These things have been 100% correlated so far, but they're not the same and I'll need to be aware of this. #17 is therefore possibly just wrong. |
For this input header, autocxx is compiling the following generated Rust code, which puts the
s
field at offset 4 in S while the C++ string field is actually at offset 8 on my machine.The text was updated successfully, but these errors were encountered: