-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Split CString::new into CString::new and CString::new_owned #18125
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. |
@@ -430,7 +458,7 @@ impl<'a> ToCStr for &'a [u8] { | |||
ptr::copy_memory(buf, self.as_ptr(), self_len); | |||
*buf.offset(self_len as int) = 0; | |||
|
|||
CString::new(buf as *const libc::c_char, true) | |||
CString::new_owned(buf as *mut i8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/i8/libc::c_char/
The pair of names Note also that the module-wide document goes as follows:
|
Good catch.
That is the case though. The owned variant deallocates the buffer when it drops. I'll fix the documentation as well. |
@nodakai these docs are not very relevant, since they're wrong even now. unsafe fn new(buf: *const i8, owns_buffer: bool) -> CString Passing |
@canndrew @nikomatsakis What is the status of this PR? |
@nodakai sorry for the delay, I've been at a conference and not keeping up with github. I'm going through PRs assigned to me now. |
ef0b959
to
c6c6d0c
Compare
So, in general this looks to be high-quality work, but I know that there are existing efforts to revamp these APIs and I'm not sure how this PR fits in. I'm ccing @aturon who can provide more feedback on that. I want to say thanks for the PR and also to apologize for the delay in reviewing this. |
@canndrew Thanks for doing this work! This seems like a reasonable change to the API, but I'm a bit worried that we actually need a more substantial overhaul: see #16772 which recommends breaking into two separate types. More generally, I've been planning to revamp the Because of the potential for these more drastic changes, I'm a little hesitant to land this smaller API change because of the extra churn it would cause. Would you be interested in being involved with a larger revamp effort? |
@canndrew To be clear, I'm not necessarily opposed to landing this incremental improvement now, I just want to think a bit about how it fits into broader plans. |
FYI, here's my crack at improving |
@aturon Sure I'd be interested in being involved in a larger revamp effort. I actually think |
Closing in favor of @mzabaluev's RFC. |
This is a fix for #18117