diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-03-07 15:42:29 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-03-12 12:31:13 -0800 |
| commit | b53764c73bd722ea22142bace6249d5950066253 (patch) | |
| tree | ecf0066dbdb65bf0cf4600c4560d06edcacff707 /src/libstd/sys | |
| parent | 083db64d9050ae6f92628aa869171ac4affb016f (diff) | |
| download | rust-b53764c73bd722ea22142bace6249d5950066253.tar.gz rust-b53764c73bd722ea22142bace6249d5950066253.zip | |
std: Clean out deprecated APIs
Removes all unstable and deprecated APIs prior to the 1.8 release. All APIs that are deprecated in the 1.8 release are sticking around for the rest of this cycle. Some notable changes are: * The `dynamic_lib` module was moved into `rustc_back` as the compiler still relies on a few bits and pieces. * The `DebugTuple` formatter now special-cases an empty struct name with only one field to append a trailing comma.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/common/net.rs | 36 | ||||
| -rw-r--r-- | src/libstd/sys/unix/ext/fs.rs | 79 | ||||
| -rw-r--r-- | src/libstd/sys/windows/backtrace.rs | 120 | ||||
| -rw-r--r-- | src/libstd/sys/windows/c.rs | 15 | ||||
| -rw-r--r-- | src/libstd/sys/windows/dynamic_lib.rs | 55 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/printing/gnu.rs | 15 | ||||
| -rw-r--r-- | src/libstd/sys/windows/printing/msvc.rs | 82 |
8 files changed, 172 insertions, 231 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index aa92e5be114..42714feb921 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -11,15 +11,13 @@ use prelude::v1::*; use cmp; -use ffi::{CStr, CString}; +use ffi::CString; use fmt; use io::{self, Error, ErrorKind}; -use libc::{c_int, c_char, c_void}; +use libc::{c_int, c_void}; use mem; -#[allow(deprecated)] -use net::{SocketAddr, Shutdown, IpAddr, Ipv4Addr, Ipv6Addr}; +use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use ptr; -use str::from_utf8; use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t}; use sys::net::netc as c; use sys_common::{AsInner, FromInner, IntoInner}; @@ -155,34 +153,6 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> { } //////////////////////////////////////////////////////////////////////////////// -// lookup_addr -//////////////////////////////////////////////////////////////////////////////// - -#[allow(deprecated)] -pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> { - init(); - - let saddr = SocketAddr::new(*addr, 0); - let (inner, len) = saddr.into_inner(); - let mut hostbuf = [0 as c_char; c::NI_MAXHOST as usize]; - - let data = unsafe { - try!(cvt_gai(c::getnameinfo(inner, len, - hostbuf.as_mut_ptr(), - c::NI_MAXHOST, - ptr::null_mut(), 0, 0))); - - CStr::from_ptr(hostbuf.as_ptr()) - }; - - match from_utf8(data.to_bytes()) { - Ok(name) => Ok(name.to_owned()), - Err(_) => Err(io::Error::new(io::ErrorKind::Other, - "failed to lookup address information")) - } -} - -//////////////////////////////////////////////////////////////////////////////// // TCP streams //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index bdde25648ed..a1528458860 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -15,90 +15,11 @@ use fs::{self, Permissions, OpenOptions}; use io; use libc; -#[allow(deprecated)] -use os::unix::raw; use path::Path; use sys; use sys_common::{FromInner, AsInner, AsInnerMut}; use sys::platform::fs::MetadataExt as UnixMetadataExt; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_READ: raw::mode_t = 0o400; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_WRITE: raw::mode_t = 0o200; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_EXECUTE: raw::mode_t = 0o100; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_RWX: raw::mode_t = 0o700; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_READ: raw::mode_t = 0o040; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_WRITE: raw::mode_t = 0o020; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_EXECUTE: raw::mode_t = 0o010; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_RWX: raw::mode_t = 0o070; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_READ: raw::mode_t = 0o004; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_WRITE: raw::mode_t = 0o002; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_EXECUTE: raw::mode_t = 0o001; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_RWX: raw::mode_t = 0o007; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_READ: raw::mode_t = 0o444; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_WRITE: raw::mode_t = 0o222; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_EXECUTE: raw::mode_t = 0o111; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_RWX: raw::mode_t = 0o777; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const SETUID: raw::mode_t = 0o4000; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const SETGID: raw::mode_t = 0o2000; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const STICKY_BIT: raw::mode_t = 0o1000; - /// Unix-specific extensions to `Permissions` #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 80ff0cb0453..3cc3a631b89 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -26,22 +26,22 @@ use io::prelude::*; -use dynamic_lib::DynamicLibrary; use io; use libc::c_void; use mem; -use path::Path; use ptr; use sync::StaticMutex; use sys::c; +use sys::dynamic_lib::DynamicLibrary; -macro_rules! sym{ ($lib:expr, $e:expr, $t:ident) => (unsafe { - let lib = $lib; - match lib.symbol($e) { - Ok(f) => $crate::mem::transmute::<*mut u8, $t>(f), - Err(..) => return Ok(()) - } -}) } +macro_rules! sym { + ($lib:expr, $e:expr, $t:ident) => ( + match $lib.symbol($e) { + Ok(f) => $crate::mem::transmute::<usize, $t>(f), + Err(..) => return Ok(()) + } + ) +} #[cfg(target_env = "msvc")] #[path = "printing/msvc.rs"] @@ -52,16 +52,16 @@ mod printing; mod printing; type SymInitializeFn = - extern "system" fn(c::HANDLE, *mut c_void, - c::BOOL) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, *mut c_void, + c::BOOL) -> c::BOOL; type SymCleanupFn = - extern "system" fn(c::HANDLE) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE) -> c::BOOL; type StackWalk64Fn = - extern "system" fn(c::DWORD, c::HANDLE, c::HANDLE, - *mut c::STACKFRAME64, *mut c::CONTEXT, - *mut c_void, *mut c_void, - *mut c_void, *mut c_void) -> c::BOOL; + unsafe extern "system" fn(c::DWORD, c::HANDLE, c::HANDLE, + *mut c::STACKFRAME64, *mut c::CONTEXT, + *mut c_void, *mut c_void, + *mut c_void, *mut c_void) -> c::BOOL; #[cfg(target_arch = "x86")] pub fn init_frame(frame: &mut c::STACKFRAME64, @@ -93,7 +93,9 @@ struct Cleanup { } impl Drop for Cleanup { - fn drop(&mut self) { (self.SymCleanup)(self.handle); } + fn drop(&mut self) { + unsafe { (self.SymCleanup)(self.handle); } + } } pub fn write(w: &mut Write) -> io::Result<()> { @@ -102,52 +104,50 @@ pub fn write(w: &mut Write) -> io::Result<()> { static LOCK: StaticMutex = StaticMutex::new(); let _g = LOCK.lock(); - // Open up dbghelp.dll, we don't link to it explicitly because it can't - // always be found. Additionally, it's nice having fewer dependencies. - let path = Path::new("dbghelp.dll"); - let dbghelp = match DynamicLibrary::open(Some(&path)) { + let dbghelp = match DynamicLibrary::open("dbghelp.dll") { Ok(lib) => lib, Err(..) => return Ok(()), }; - - // Fetch the symbols necessary from dbghelp.dll - let SymInitialize = sym!(&dbghelp, "SymInitialize", SymInitializeFn); - let SymCleanup = sym!(&dbghelp, "SymCleanup", SymCleanupFn); - let StackWalk64 = sym!(&dbghelp, "StackWalk64", StackWalk64Fn); - - // Allocate necessary structures for doing the stack walk - let process = unsafe { c::GetCurrentProcess() }; - let thread = unsafe { c::GetCurrentThread() }; - let mut context: c::CONTEXT = unsafe { mem::zeroed() }; - unsafe { c::RtlCaptureContext(&mut context); } - let mut frame: c::STACKFRAME64 = unsafe { mem::zeroed() }; - let image = init_frame(&mut frame, &context); - - // Initialize this process's symbols - let ret = SymInitialize(process, ptr::null_mut(), c::TRUE); - if ret != c::TRUE { return Ok(()) } - let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; - - // And now that we're done with all the setup, do the stack walking! - // Start from -1 to avoid printing this stack frame, which will - // always be exactly the same. - let mut i = -1; - try!(write!(w, "stack backtrace:\n")); - while StackWalk64(image, process, thread, &mut frame, &mut context, - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut()) == c::TRUE { - let addr = frame.AddrPC.Offset; - if addr == frame.AddrReturn.Offset || addr == 0 || - frame.AddrReturn.Offset == 0 { break } - - i += 1; - - if i >= 0 { - try!(printing::print(w, i, addr-1, &dbghelp, process)); + unsafe { + // Fetch the symbols necessary from dbghelp.dll + let SymInitialize = sym!(dbghelp, "SymInitialize", SymInitializeFn); + let SymCleanup = sym!(dbghelp, "SymCleanup", SymCleanupFn); + let StackWalk64 = sym!(dbghelp, "StackWalk64", StackWalk64Fn); + + // Allocate necessary structures for doing the stack walk + let process = c::GetCurrentProcess(); + let thread = c::GetCurrentThread(); + let mut context: c::CONTEXT = mem::zeroed(); + c::RtlCaptureContext(&mut context); + let mut frame: c::STACKFRAME64 = mem::zeroed(); + let image = init_frame(&mut frame, &context); + + // Initialize this process's symbols + let ret = SymInitialize(process, ptr::null_mut(), c::TRUE); + if ret != c::TRUE { return Ok(()) } + let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; + + // And now that we're done with all the setup, do the stack walking! + // Start from -1 to avoid printing this stack frame, which will + // always be exactly the same. + let mut i = -1; + try!(write!(w, "stack backtrace:\n")); + while StackWalk64(image, process, thread, &mut frame, &mut context, + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut()) == c::TRUE { + let addr = frame.AddrPC.Offset; + if addr == frame.AddrReturn.Offset || addr == 0 || + frame.AddrReturn.Offset == 0 { break } + + i += 1; + + if i >= 0 { + try!(printing::print(w, i, addr - 1, process, &dbghelp)); + } } - } - Ok(()) + Ok(()) + } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 002ffc7c868..ab24b9e6fd6 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -154,8 +154,6 @@ pub const WSAESHUTDOWN: c_int = 10058; pub const WSAETIMEDOUT: c_int = 10060; pub const WSAECONNREFUSED: c_int = 10061; -pub const NI_MAXHOST: DWORD = 1025; - pub const MAX_PROTOCOL_CHAIN: DWORD = 7; pub const TOKEN_READ: DWORD = 0x20008; @@ -1099,18 +1097,11 @@ extern "system" { hints: *const ADDRINFOA, res: *mut *mut ADDRINFOA) -> c_int; pub fn freeaddrinfo(res: *mut ADDRINFOA); - pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int, - host: *mut c_char, hostlen: DWORD, - serv: *mut c_char, servlen: DWORD, - flags: c_int) -> c_int; pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE; - pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR, - handle: *mut HMODULE) -> BOOL; + pub fn FreeLibrary(handle: HMODULE) -> BOOL; pub fn GetProcAddress(handle: HMODULE, name: LPCSTR) -> *mut c_void; - pub fn FreeLibrary(handle: HMODULE) -> BOOL; - pub fn SetErrorMode(uMode: c_uint) -> c_uint; pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, pszContainer: LPCSTR, @@ -1177,10 +1168,6 @@ compat_fn! { _dwFlags: DWORD) -> DWORD { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } - pub fn SetThreadErrorMode(_dwNewMode: DWORD, - _lpOldMode: *mut DWORD) -> c_uint { - SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 - } pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } diff --git a/src/libstd/sys/windows/dynamic_lib.rs b/src/libstd/sys/windows/dynamic_lib.rs new file mode 100644 index 00000000000..84cfbe5e721 --- /dev/null +++ b/src/libstd/sys/windows/dynamic_lib.rs @@ -0,0 +1,55 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use prelude::v1::*; +use os::windows::prelude::*; + +use ffi::{CString, OsStr}; +use io; +use sys::c; + +pub struct DynamicLibrary { + handle: c::HMODULE, +} + +impl DynamicLibrary { + pub fn open(filename: &str) -> io::Result<DynamicLibrary> { + let filename = OsStr::new(filename) + .encode_wide() + .chain(Some(0)) + .collect::<Vec<_>>(); + let result = unsafe { + c::LoadLibraryW(filename.as_ptr()) + }; + if result.is_null() { + Err(io::Error::last_os_error()) + } else { + Ok(DynamicLibrary { handle: result }) + } + } + + pub fn symbol(&self, symbol: &str) -> io::Result<usize> { + let symbol = try!(CString::new(symbol)); + unsafe { + match c::GetProcAddress(self.handle, symbol.as_ptr()) as usize { + 0 => Err(io::Error::last_os_error()), + n => Ok(n), + } + } + } +} + +impl Drop for DynamicLibrary { + fn drop(&mut self) { + unsafe { + c::FreeLibrary(self.handle); + } + } +} diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 765e6e09427..384940e4dc4 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -24,6 +24,7 @@ use time::Duration; pub mod backtrace; pub mod c; pub mod condvar; +pub mod dynamic_lib; pub mod ext; pub mod fs; pub mod handle; diff --git a/src/libstd/sys/windows/printing/gnu.rs b/src/libstd/sys/windows/printing/gnu.rs index c1367d5381d..be2d5273c07 100644 --- a/src/libstd/sys/windows/printing/gnu.rs +++ b/src/libstd/sys/windows/printing/gnu.rs @@ -8,18 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated)] - -use dynamic_lib::DynamicLibrary; use io::prelude::*; use io; -use sys::c; use libc::c_void; - +use sys::c; +use sys::dynamic_lib::DynamicLibrary; use sys_common::gnu::libbacktrace; -pub fn print(w: &mut Write, i: isize, addr: u64, _: &DynamicLibrary, _: c::HANDLE) - -> io::Result<()> { +pub fn print(w: &mut Write, + i: isize, + addr: u64, + _process: c::HANDLE, + _dbghelp: &DynamicLibrary) + -> io::Result<()> { let addr = addr as usize as *mut c_void; libbacktrace::print(w, i, addr, addr) } diff --git a/src/libstd/sys/windows/printing/msvc.rs b/src/libstd/sys/windows/printing/msvc.rs index 255c645c3fb..37aaa1f1b0e 100644 --- a/src/libstd/sys/windows/printing/msvc.rs +++ b/src/libstd/sys/windows/printing/msvc.rs @@ -8,60 +8,66 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated)] - -use dynamic_lib::DynamicLibrary; use ffi::CStr; use io::prelude::*; use io; use libc::{c_ulong, c_int, c_char, c_void}; use mem; use sys::c; +use sys::dynamic_lib::DynamicLibrary; use sys_common::backtrace::{output, output_fileline}; type SymFromAddrFn = - extern "system" fn(c::HANDLE, u64, *mut u64, - *mut c::SYMBOL_INFO) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, u64, *mut u64, + *mut c::SYMBOL_INFO) -> c::BOOL; type SymGetLineFromAddr64Fn = - extern "system" fn(c::HANDLE, u64, *mut u32, - *mut c::IMAGEHLP_LINE64) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, u64, *mut u32, + *mut c::IMAGEHLP_LINE64) -> c::BOOL; -pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, - process: c::HANDLE) -> io::Result<()> { - let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn); - let SymGetLineFromAddr64 = sym!(dbghelp, "SymGetLineFromAddr64", SymGetLineFromAddr64Fn); +pub fn print(w: &mut Write, + i: isize, + addr: u64, + process: c::HANDLE, + dbghelp: &DynamicLibrary) + -> io::Result<()> { + unsafe { + let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn); + let SymGetLineFromAddr64 = sym!(dbghelp, + "SymGetLineFromAddr64", + SymGetLineFromAddr64Fn); - let mut info: c::SYMBOL_INFO = unsafe { mem::zeroed() }; - info.MaxNameLen = c::MAX_SYM_NAME as c_ulong; - // the struct size in C. the value is different to - // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81) - // due to struct alignment. - info.SizeOfStruct = 88; + let mut info: c::SYMBOL_INFO = mem::zeroed(); + info.MaxNameLen = c::MAX_SYM_NAME as c_ulong; + // the struct size in C. the value is different to + // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81) + // due to struct alignment. + info.SizeOfStruct = 88; - let mut displacement = 0u64; - let ret = SymFromAddr(process, addr, &mut displacement, &mut info); + let mut displacement = 0u64; + let ret = SymFromAddr(process, addr, &mut displacement, &mut info); - let name = if ret == c::TRUE { - let ptr = info.Name.as_ptr() as *const c_char; - Some(unsafe { CStr::from_ptr(ptr).to_bytes() }) - } else { - None - }; + let name = if ret == c::TRUE { + let ptr = info.Name.as_ptr() as *const c_char; + Some(CStr::from_ptr(ptr).to_bytes()) + } else { + None + }; - try!(output(w, i, addr as usize as *mut c_void, name)); + try!(output(w, i, addr as usize as *mut c_void, name)); - // Now find out the filename and line number - let mut line: c::IMAGEHLP_LINE64 = unsafe { mem::zeroed() }; - line.SizeOfStruct = ::mem::size_of::<c::IMAGEHLP_LINE64>() as u32; + // Now find out the filename and line number + let mut line: c::IMAGEHLP_LINE64 = mem::zeroed(); + line.SizeOfStruct = ::mem::size_of::<c::IMAGEHLP_LINE64>() as u32; - let mut displacement = 0u32; - let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line); - if ret == c::TRUE { - output_fileline(w, - unsafe { CStr::from_ptr(line.Filename).to_bytes() }, - line.LineNumber as c_int, - false) - } else { - Ok(()) + let mut displacement = 0u32; + let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line); + if ret == c::TRUE { + output_fileline(w, + CStr::from_ptr(line.Filename).to_bytes(), + line.LineNumber as c_int, + false) + } else { + Ok(()) + } } } |
