Skip to content

Commit

Permalink
Add comment about stabilizing CString::from_ptr
Browse files Browse the repository at this point in the history
This naming needs to consider the raw vs ptr naming of
Box/CStr/CString/slice/etc.
  • Loading branch information
alexcrichton committed Jun 17, 2015
1 parent c9b40a3 commit 913c227
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl<T : ?Sized> Box<T> {
#[unstable(feature = "box_raw",
reason = "may be renamed or moved out of Box scope")]
#[inline]
// NB: may want to be called from_ptr, see comments on CStr::from_ptr
pub unsafe fn from_raw(raw: *mut T) -> Self {
mem::transmute(raw)
}
Expand All @@ -147,6 +148,7 @@ impl<T : ?Sized> Box<T> {
/// ```
#[unstable(feature = "box_raw", reason = "may be renamed")]
#[inline]
// NB: may want to be called into_ptr, see comments on CStr::from_ptr
pub fn into_raw(b: Box<T>) -> *mut T {
unsafe { mem::transmute(b) }
}
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ impl CString {
/// `into_ptr`. The length of the string will be recalculated
/// using the pointer.
#[unstable(feature = "cstr_memory", reason = "recently added")]
// NB: may want to be called from_raw, needs to consider CStr::from_ptr,
// Box::from_raw (or whatever it's currently called), and
// slice::from_raw_parts
pub unsafe fn from_ptr(ptr: *const libc::c_char) -> CString {
let len = libc::strlen(ptr) + 1; // Including the NUL byte
let slice = slice::from_raw_parts(ptr, len as usize);
Expand All @@ -221,6 +224,7 @@ impl CString {
///
/// Failure to call `from_ptr` will lead to a memory leak.
#[unstable(feature = "cstr_memory", reason = "recently added")]
// NB: may want to be called into_raw, see comments on from_ptr
pub fn into_ptr(self) -> *const libc::c_char {
// It is important that the bytes be sized to fit - we need
// the capacity to be determinable from the string length, and
Expand Down

0 comments on commit 913c227

Please sign in to comment.