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

Some pointer shenanigans. #2895

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nihohit
Copy link
Contributor

@nihohit nihohit commented Dec 30, 2024

The purpose of this PR is to use newer pointer/C-string APIs that weren't available when the repo was created, in order to make the handling of raw pointers slightly safer.
This change is only a partial change - hopefully I'll have time to go over more of the pointer conversions and double check them.
This is in preparation of the pointer provenance change that will hopefully land in the next Rust release, which will allow for even better safety in handling pointers.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@nihohit nihohit requested a review from a team as a code owner December 30, 2024 20:36
Rust 1.77 introduced C-string literals, which allows us to use static C-strings, instead of going through CString and allocating a new string on every invocation.

https://doc.rust-lang.org/edition-guide/rust-2021/c-string-literals.html
Signed-off-by: Shachar Langbeheim <[email protected]>
https://doc.rust-lang.org/std/ptr/fn.from_mut.html
This is recommended as a safer alternative to `as` casts, since they provide some type checking.
Notice that the caveat in the docs isn't relevant here, since the function is called exclusively over leaked boxes, which don't have a bounded lifetime.

Signed-off-by: Shachar Langbeheim <[email protected]>
Signed-off-by: Shachar Langbeheim <[email protected]>
@nihohit nihohit force-pushed the pointer-shenanigans branch from 6f86fcf to d5e76f8 Compare December 30, 2024 20:52
Signed-off-by: Shachar Langbeheim <[email protected]>
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.

1 participant