about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-09-03 10:36:34 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-09-03 10:36:34 -0700
commit6bb2c5d32299b4664c3876793b4e759d8fbc0008 (patch)
tree25d8e0ed88b5937c60415511512768313968fc8c /src
parent9e9c83b8994fab4f69fc75838c8c856b57caa5d1 (diff)
downloadrust-6bb2c5d32299b4664c3876793b4e759d8fbc0008.tar.gz
rust-6bb2c5d32299b4664c3876793b4e759d8fbc0008.zip
std: Update CString::{into,from}_raw with `*mut T`
Conventionally in C `*mut T` is a transfer of ownership where `*const T` is a
loan, so `*mut T` is likely the more appropriate return type for these
functions. Additionally, this more closely mirrors the APIs on `Box` for this
sort of functionality.

cc #27769
Diffstat (limited to 'src')
-rw-r--r--src/libstd/ffi/c_str.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 23daa87401a..587eb0f1cea 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -209,7 +209,7 @@ impl CString {
                issue = "27769")]
     #[deprecated(since = "1.4.0", reason = "renamed to from_raw")]
     pub unsafe fn from_ptr(ptr: *const libc::c_char) -> CString {
-        CString::from_raw(ptr)
+        CString::from_raw(ptr as *mut _)
     }
 
     /// Retakes ownership of a CString that was transferred to C.
@@ -219,7 +219,7 @@ impl CString {
     /// using the pointer.
     #[unstable(feature = "cstr_memory", reason = "recently added",
                issue = "27769")]
-    pub unsafe fn from_raw(ptr: *const libc::c_char) -> CString {
+    pub unsafe fn from_raw(ptr: *mut libc::c_char) -> CString {
         let len = libc::strlen(ptr) + 1; // Including the NUL byte
         let slice = slice::from_raw_parts(ptr, len as usize);
         CString { inner: mem::transmute(slice) }
@@ -237,7 +237,7 @@ impl CString {
                issue = "27769")]
     #[deprecated(since = "1.4.0", reason = "renamed to into_raw")]
     pub fn into_ptr(self) -> *const libc::c_char {
-        self.into_raw()
+        self.into_raw() as *const _
     }
 
     /// Transfers ownership of the string to a C caller.
@@ -250,11 +250,8 @@ impl CString {
     /// Failure to call `from_ptr` will lead to a memory leak.
     #[unstable(feature = "cstr_memory", reason = "recently added",
                issue = "27769")]
-    pub fn into_raw(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
-        // shrinking to fit is the only way to be sure.
-        Box::into_raw(self.inner) as *const libc::c_char
+    pub fn into_raw(self) -> *mut libc::c_char {
+        Box::into_raw(self.inner) as *mut libc::c_char
     }
 
     /// Returns the contents of this `CString` as a slice of bytes.