std: remove unnecessary test from c_str.drop and use safer transmute

This commit is contained in:
Erick Tryzelaar 2013-08-06 21:08:39 -07:00
parent e053bff5d0
commit d6257b315b

View File

@ -57,7 +57,7 @@ pub fn with_ref<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
/// Fails if the CString is null.
pub fn with_mut_ref<T>(&mut self, f: &fn(*mut libc::c_char) -> T) -> T {
if self.buf.is_null() { fail!("CString is null!"); }
f(unsafe { cast::transmute(self.buf) })
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
}
/// Returns true if the CString is a null.
@ -99,7 +99,7 @@ fn iter<'a>(&'a self) -> CStringIterator<'a> {
impl Drop for CString {
fn drop(&self) {
if self.owns_buffer_ && self.buf.is_not_null() {
if self.owns_buffer_ {
unsafe {
libc::free(self.buf as *libc::c_void)
}