-
Notifications
You must be signed in to change notification settings - Fork 689
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
add option to use DST structs for flex arrays #2772
Merged
Merged
+1,012
−19
Commits on Apr 1, 2024
-
This option uses Rust DST types to model C structures with flexible array members. For example, if you declare: ```c struct record { int len; float values[]; } ``` this means it's a C structure with a well-defined prefix, but a tail of `values` which depends on how much memory we've allocated for it. We can model this in Rust with: ```rust struct record { len: c_int, values: [f32], } ``` which means more or less the same thing - there's a type which has a known prefix, but its suffix is not directly known.
Configuration menu - View commit details
-
Copy full SHA for 06bfb06 - Browse repository at this point
Copy the full SHA 06bfb06View commit details -
Only generate flex array member for last field
There are some tests which have two incomplete array fields; only the very last one is valid as a flexible array member (in C) or can be a DST field in Rust.
Configuration menu - View commit details
-
Copy full SHA for e9eb68d - Browse repository at this point
Copy the full SHA e9eb68dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 907a510 - Browse repository at this point
Copy the full SHA 907a510View commit details -
Rework methods on flexarray types
Put the pointer converting methods on the sized prefix types ([T; 0]) since they're the default type and what you're likely to be starting with. Emphasize the ones which work on references since they have safe lifetimes, but also have raw pointer variants, esp for handling uninitialized cases. The flex types have methods which return the sized type along with the length.
Configuration menu - View commit details
-
Copy full SHA for 474c38b - Browse repository at this point
Copy the full SHA 474c38bView commit details -
Configuration menu - View commit details
-
Copy full SHA for c6c141d - Browse repository at this point
Copy the full SHA c6c141dView commit details -
Configuration menu - View commit details
-
Copy full SHA for d2f810e - Browse repository at this point
Copy the full SHA d2f810eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 75e42d7 - Browse repository at this point
Copy the full SHA 75e42d7View commit details -
Previously it was generating inner `unsafe` blocks for all unsafe functions in conformance with Rust 2024, but now only do it when `--wrap-unsafe-ops` is enabled for consistency with other generated code. Also rename `flex_mut_ref` -> `flex_ref_mut` to make it consistent with `flex_ptr_mut` and general Rust convention.
Configuration menu - View commit details
-
Copy full SHA for 998c8a5 - Browse repository at this point
Copy the full SHA 998c8a5View commit details -
Make all the flexarray helpers inline
The conversions between fixed and dynamically sized forms are essentially type-level transforms which should have trivial implementations in terms of generated code, so there's no reason not to make them inline.
Configuration menu - View commit details
-
Copy full SHA for 81356cb - Browse repository at this point
Copy the full SHA 81356cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8a7291d - Browse repository at this point
Copy the full SHA 8a7291dView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.