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

Improve fill_zeroes' use of ptr::write_bytes #284

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

a1phyr
Copy link
Contributor

@a1phyr a1phyr commented Nov 6, 2024

No description provided.

@Lokathor
Copy link
Owner

Lokathor commented Nov 6, 2024

Looks like these are deliberately two lines to prevent the length check (using &self) from invalidating the mut pointer.

@a1phyr
Copy link
Contributor Author

a1phyr commented Nov 6, 2024

Nice catch! It doesn't seem to annoy MIRI though: https://play.rust-lang.org/?edition=2021&gist=3ffc5bffdb51903f2613413470953084

@a1phyr a1phyr force-pushed the improve_fill_zeroes branch from d4fc770 to 002072f Compare November 19, 2024 09:59
@Lokathor Lokathor merged commit 1400815 into Lokathor:main Nov 19, 2024
14 checks passed
@Lokathor
Copy link
Owner

released in bytemuck-1.20

@thomcc
Copy link
Contributor

thomcc commented Nov 27, 2024

I think the old version filled padding with zeroes, but the new one isn't guaranteed to.

@Lokathor
Copy link
Owner

write_bytes is similar to C’s memset, but sets count * size_of::() bytes to val.

https://doc.rust-lang.org/core/ptr/fn.write_bytes.html

and the size of T includes any tail padding

so i think this is the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch semver patch change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants