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 an iterator over XFB rows #25

Merged
merged 3 commits into from
Dec 15, 2024
Merged

Conversation

linkmauve
Copy link
Collaborator

This emits slices of u16, and allows users to not use unsafe for drawing.

This is based on #21, since it wouldn’t build on current nightly otherwise.

@linkmauve linkmauve marked this pull request as ready for review April 23, 2023 14:47
@linkmauve linkmauve force-pushed the safer-vi branch 2 times, most recently from acbc539 to 2ba40c5 Compare April 23, 2023 15:05
luma_core/src/vi.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ProfElements ProfElements left a comment

Choose a reason for hiding this comment

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

Besides one small issue it all looks awesome!

Now that the `exposed_provenance` and `strict_provenance` features have
been stabilized, we can migrate to its definitive functions.

This change is undefined behaviour though, but `as *mut u32` was similarly
UB, so we just trade one UB for another…

`core::ptr`’s documentation says:
> Situations where a valid pointer must be created from just an address,
> such as baremetal code accessing a memory-mapped interface at a fixed
> address, are an open question on how to support. These situations will
> still be allowed, but we might require some kind of “I know what I’m
> doing” annotation to explain the situation to the compiler. It’s also
> possible they need no special attention at all, because they’re
> generally accessing memory outside the scope of “the abstract machine”,
> or already using “I know what I’m doing” annotations like “volatile”.
impl<'a> Iterator for XfbIterMut<'a> {
type Item = &'a mut [u16];

fn next(&mut self) -> Option<&'a mut [u16]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

would self.xfb.data.chunks_mut(self.xfb.stride_in_u16()).next() work here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I’ve ended up replacing the whole XfbIterMut struct with ChunksMut, which already does the exact same and more.

@ProfElements
Copy link
Collaborator

I think there is a better way to implement iter_mut either with impl Iterator<Item = &'a mut [u16]> or with core::iter::from_fn

This emits slices of u16, and allows users to not use unsafe for
drawing.
Copy link
Collaborator

@ProfElements ProfElements left a comment

Choose a reason for hiding this comment

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

Looks good :)

@ProfElements ProfElements merged commit f80a9b6 into rust-wii:main Dec 15, 2024
1 of 2 checks passed
@linkmauve linkmauve deleted the safer-vi branch December 15, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants