-
Notifications
You must be signed in to change notification settings - Fork 723
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
Feature request: use DST to represent structures with flexible array members #2771
Comments
Prototype implementation in #2772 |
Hmm, this seems fine, but maybe we should just make the implementation of |
That's a possibility but there's a few downsides:
Specifically for the second, since these become DST types, it means it's no longer possible to directly reference them by value, so you wouldn't be able to do something like:
That's not the end of the world of course - that's why The other problem is that all pointers and references to these objects will be fat, and so not C-ABI compatible. So something like: struct controlblock {
struct msg *messagequeue;
}; could not be directly converted to: #[repr(C)]
struct controlblock {
messagequeue: *mut msg,
} Currently this proposed API is using #[repr(C)]
struct controlblock {
messagequeue: *mut msg::Thin,
} Likewise you wouldn't be able to directly pass or return the fat pointers to/from C-ABI functions. I don't think any of these are show-stoppers; structures with flex array have always been a bit awkward to deal with, and I think this API is an accurate reflection of that (ie, it would make it harder to get things wrong). If we could wave a magic wand to stabilize the features and update all existing code to the new API, then I think we could replace |
Yeah to be clear I meant to make |
BTW I also experimented with this idea using a trait (https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=114e0ca2cbc10523037946a7d9c61a06) , since it's a fairly self-contained abstraction that you might want to generalize over. But as far as I know bindgen doesn't have a support library crate where this could live, and it doesn't seem like it makes sense to emit a separate variant of this trait for each bindgenned module - that would be no better than the current proposal just using intrinsic methods. |
I've published PR #2772 with a fairly complete implementation of this idea. |
I think #2772 is ready for review. |
Input C/C++ Header
Bindgen Invocation
Actual Results
This produces an output using
__IncompleteArrayField
as expected:Expected Results
It would be nice to have an option to model this by using a structure with a dynamic tail:
These types of structures are awkward to use on their own, so it would need some helper methods:
These methods would currently depend on the unstable
ptr_metadata
andlayout_for_ptr
features.The text was updated successfully, but these errors were encountered: