-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wiggle: generate offset accessors for structs (#6884)
Adds methods of the shape `GeneratedStruct::offset_of_<field_name>() -> u32` to allow clients to get the same offsets used in the generated `read` and `write` methods. I don't believe there is currently a way to get these otherwise for applications that wish to selectively read and write to fields. I considered a couple alternatives to this: 1. Add methods like `read_<field_name>` and `write_<field_name>`. The interface to these ends up being awkward because the `GuestType` impls are currently for owned types, so these methods would be forced to either take ownership of the entire struct to write one field, or else silently clone the field. 2. Add `#[repr(C)]` to the generated struct definition so that clients could use tools like `memoffset` to calculate the offset themselves. I didn't want to depend on the witx offsets coinciding with `repr(C)`, though. I extended the Wiggle `records` to exercise these new methods.
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters