]> git.lizzy.rs Git - rust.git/commitdiff
Add comment about stabilizing CString::from_ptr
authorAlex Crichton <alex@alexcrichton.com>
Thu, 11 Jun 2015 18:26:16 +0000 (11:26 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 17 Jun 2015 16:07:17 +0000 (09:07 -0700)
This naming needs to consider the raw vs ptr naming of
Box/CStr/CString/slice/etc.

src/liballoc/boxed.rs
src/libstd/ffi/c_str.rs

index 1a360ebc05c71865f95cafd8747744b9c5cf24fc..1039756363e9fa1aa6a05ed1a9f7f30720a19488 100644 (file)
@@ -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)
     }
@@ -147,6 +148,7 @@ pub unsafe fn from_raw(raw: *mut T) -> Self {
     /// ```
     #[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) }
     }
index becc697bcd9a0a0919f2821fdecba1f2b3429d75..ffc204ada60fb92a0468654690c95afa0e51b6b3 100644 (file)
@@ -206,6 +206,9 @@ pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> 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);
@@ -221,6 +224,7 @@ pub unsafe fn from_ptr(ptr: *const libc::c_char) -> 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