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

Cleanup some CString logic #83

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

vlovich
Copy link
Contributor

@vlovich vlovich commented Jan 22, 2025

Replace RawCString with a single function since the main thing it's adding is the implicit .expect on the String -> CString conversion. RawCString and CString otherwise have identical behaviors so the abstraction isn't adding anything AFAICT.

Mark cstr_to_string as unsafe since it's against convention to whitewash the unsafety behind a safe API that wraps the interior with unsafe. The point of unsafe generally is to demarcate "I know at the call site this is actually safe but I can't prove it to the compiler" or "this is a safe abstraction even though internally I have to use unsafe since I can't convince the compiler". cstr_to_string falls in the former camp - the function itself isn't a safe abstraction and thus the call-site must be responsible for acknowledging the unsafety.

RawCString doesn't offer any additional smarts over lifetime ownserhip
vs constructing a CString.
In Rust, having an unsafe interior conventionally means that you are
guaranteeing safety at the boundary. However, that's not the case for
cstr_to_string which is taking a random pointer as input. Thankfully,
this doesn't functionally change anything anyway since it was already
always called from an unsafe context.
@thewh1teagle
Copy link
Owner

Looks good, thanks!

@thewh1teagle thewh1teagle merged commit 1ad02d7 into thewh1teagle:main Jan 23, 2025
3 checks passed
@vlovich vlovich deleted the vitali/cleanup-csr branch January 27, 2025 23:18
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