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 more description to c_str::unwrap(). #15119

Closed
wants to merge 1 commit into from

Conversation

steveklabnik
Copy link
Member

It's unclear what you are supposed to do with this memory.
Let's make that more clear.

@@ -124,6 +124,9 @@ impl CString {

/// Unwraps the wrapped `*libc::c_char` from the `CString` wrapper.
/// Any ownership of the buffer by the `CString` wrapper is forgotten.
///
/// The original object is destructed after unwrap() is called on it and
/// the memory must be freed with `libc::free()`.
Copy link
Member

Choose a reason for hiding this comment

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

This may be slightly misleading as it may not always be true. The buffer could be borrowed from another source or perhaps be in static memory. Perhaps this could be combined with the above sentence to clarify things a bit? Or just alluding to the face that it must be freed if it was previously allocated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to any particular suggestion. Maybe the second?

"Because it is a C string, it must be freed with libc::free, rather than automatically by Rust."

or something. That sentence is terrible, but maybe something along those lines?

Copy link
Member

Choose a reason for hiding this comment

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

Unwraps the wrapped *libc::c_char from the CString wrapper.

The original CString object is destructed after this method is called,
and if the underlying pointer was previously allocated care must be taken
to ensure that it is deallocated.

Something like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it. I'll update this soon.

@steveklabnik
Copy link
Member Author

Updated.

///
/// The original object is destructed after this method is called, and if
/// the underlying pointer was previously allocated, care must be taken to
/// ensure that is deallocated properly.
Copy link
Member

Choose a reason for hiding this comment

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

"that it is"

@alexcrichton
Copy link
Member

r=me with a squash

@steveklabnik
Copy link
Member Author

Typo fixed and sqaushed.

@alexcrichton
Copy link
Member

Oh dear, this seems to have reverted a bunch of updates to submodules

@steveklabnik
Copy link
Member Author

Oh my. I suck at git. One moment.

@steveklabnik
Copy link
Member Author

Whew. Bad @steveklabnik! I should remove git add . from my brain.

After some more git-fu, this should be good now. Should.

It's unclear what you are supposed to do with this memory.
Let's make that more clear.
@steveklabnik steveklabnik deleted the c_str_unwrap branch October 25, 2017 18:25
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2023
Support more intrinsics in mir interpreter

Increases passed tests on self from 49 to 52
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