8000 kernel/processbuffer: accept arbitrary Ranges in ProcessSlice::get by lschuermann · Pull Request #4192 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

kernel/processbuffer: accept arbitrary Ranges in ProcessSlice::get #4192

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

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

lschuermann
Copy link
Member

Pull Request Overview

This commit changes the {Readable,Writeable}ProcessSlice types' get method implementation to accept an arbitrary range type (usize, Range, RangeFrom, RangeTo), mirroring the semantics and implementation of the core library's implementation of this method on the slice primitive.

This change makes it easier and more convenient to write panic-avoiding code when interacting with process memory.

It removes some redundancy in the Index trait implementations by making them generic over the newly introduced ProcessSliceIndex trait (which is necessary for the polymorphism of the get method).

While we could use the core library's SliceIndex trait, parameterized over our own ProcessSlice types, this trait includes mandatory methods that are undesirable for the process buffer infrastructure, such as unchecked or mutable index operations. Furthermore, implementing it requires the slice_index_methods nightly feature. Thus we vendor our own, small variant of this trait. The Rust standard library's implementation can be seen here: https://github.com/rust-lang/rust/blob/a1eceec00b2684f947481696ae2322e20d59db60/library/core/src/slice/index.rs#L200

This change should be fully backwards compatible. It does, however, deprecate the now redundant get_from and get_to methods. These were only used in one location across the entire upstream codebase.

Testing Strategy

This pull request was tested by compiling.

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

This commit changes the `{Readable,Writeable}ProcessSlice` types'
`get` method implementation to accept an arbitrary range
type (`usize`, `Range`, `RangeFrom`, `RangeTo`), mirroring the
semantics and implementation of the core library's implementation of
this method on the slice primitive.

This change makes it easier and more convenient to write
panic-avoiding code when interacting with process memory.

It removes some redundancy in the `Index` trait implementations by
making them generic over the newly introduced `ProcessSliceIndex`
trait (which is necessary for the polymorphism of the `get` method).

While we could use the core library's `SliceIndex` trait,
parameterized over our own `ProcessSlice` types, this trait includes
mandatory methods that are undesirable for the process buffer
infrastructure, such as unchecked or mutable index
operations. Furthermore, implementing it requires the
`slice_index_methods` nightly feature. Thus we vendor our own, small
variant of this trait.  The Rust standard library's implementation can
be seen here:
https://github.com/rust-lang/rust/blob/a1eceec00b2684f947481696ae2322e20d59db60/library/core/src/slice/index.rs#L200
@github-actions github-actions bot added kernel WG-Network In the purview of the Network working group. labels Oct 9, 2024
Copy link
Contributor
@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from me since this isn't doing any slice arithmetic.

@alevy alevy added this pull request to the merge queue Oct 11, 2024
Merged via the queue into tock:master with commit e37632b Oct 11, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel WG-Network In the purview of the Network working group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0