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
Expand slices to separate pointer and size #247
Comments
Can you really rely on that layout and ABI? |
Nope. |
We had a discussion about this in the gfx daily. It sounds like this doesn't have a defined layout currently, but might in the future. This is another thing, like strings, where it'd be nice to be able to autogenerate conversion thunks. But there's not a great way to add support for this in cbindgen today. So I'll close this for now. |
Would it be possible for cbindgen to come with a companion library containing wrappers like |
Ideally we'd get rust to specify these and then just teach cbindgen about that. But lacking them, I'd be fine with something like that. We can put it in this repo if it makes sense. Gecko had a bunch of types for stuff like |
Yeah, to be clear, cbindgen doesn't need any changes itself, it just needs to maintain a second library that works well with cbindgen that does this. |
Actually, I didn't realize that cbindgen can't generate types from dependencies at all. That does make things a little bit worse here :/ |
It does generate types from dependencies, see |
I use the #[repr(C)]
struct S<'a> {
#[cfg(not(feature = "cbindgen"))]
slice: &'a [u8],
#[cfg(feature = "cbindgen")]
ptr: *const u8,
#[cfg(feature = "cbindgen")]
len: usize,
} (which is pretty useful for workarounds in general, and helps with other things like bitfields). |
ahhh thanks |
Right, but that's still relying on technically unspecified behavior, isn't it? I just want https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/pointers.md set on stone ;) |
It would be really nice to support slices by splitting those into separate (pointer, size) values, e.g.
would be translated into:
where the "_length" suffix is configured like all the other prefixes/suffixes
The text was updated successfully, but these errors were encountered: