Skip to content
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 10 commits into from
Apr 1, 2024

Commits on Apr 1, 2024

  1. Add --flexarray-dst option

    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.
    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    06bfb06 View commit details
    Browse the repository at this point in the history
  2. 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.
    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    e9eb68d View commit details
    Browse the repository at this point in the history
  3. Add flex array member tests

    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    907a510 View commit details
    Browse the repository at this point in the history
  4. 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.
    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    474c38b View commit details
    Browse the repository at this point in the history
  5. Add documentation

    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    c6c141d View commit details
    Browse the repository at this point in the history
  6. Update with review comments

    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    d2f810e View commit details
    Browse the repository at this point in the history
  7. Small doc tweaks

    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    75e42d7 View commit details
    Browse the repository at this point in the history
  8. Honour --wrap-unsafe-ops

    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.
    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    998c8a5 View commit details
    Browse the repository at this point in the history
  9. 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.
    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    81356cb View commit details
    Browse the repository at this point in the history
  10. Update test fixtures

    jsgf committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    8a7291d View commit details
    Browse the repository at this point in the history