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

The scope of the unsafe block can be appropriately reduced #32

Closed
wants to merge 1 commit into from

Conversation

peamaeq
Copy link

@peamaeq peamaeq commented Jun 23, 2022

In this function you use the unsafe keyword for almost the entrie function body.

We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust.

Hope this PR can help you.
Best regards.
References
https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

@sekineh
Copy link
Owner

sekineh commented Jun 27, 2022

Thanks, it looks good.
But CI failed because the dependency atoi requires MaybeUninit which was introduced in rustc 1.36.
So we need to bump the MSRV in the following files.

  • README.md
  • .github/workflows/rust.yml

We also need a CHANGELOG entry.

  • CHANGELOG.md

@clint-white
Copy link
Contributor

clint-white commented Jul 2, 2022

As the CI failures are unrelated to this PR (same errors on master), I openned a separate PR: #33.

Regarding the changes introduced in this PR, these are a subset of those found in rust-lang/rust#81706. The upstream PR also makes several of the private functions unsafe (sift_up, sift_down, sift_down_range, sift_down_to_bottom) and adds SAFETY comments before every use of unsafe. It would be worth incorporating those.

It may also be worth porting a more recent version from std to include other changes such as rust-lang/rust#81127 which improved the performance of BinaryHeap::into_sorted_vec().

@clint-white
Copy link
Contributor

This would now conflict with #34, but very similar changes to those proposed here are among those proposed there.

@sekineh
Copy link
Owner

sekineh commented Oct 7, 2022

These big unsafe blocks are fixed in #34.

@sekineh sekineh closed this Oct 7, 2022
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.

3 participants