about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-03 09:49:50 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-03 09:49:50 +0300
commit06fb196256bbab1e7aa4f43daf45321efaa6e0eb (patch)
tree23863826af019b2bc07d295882e092d244c36699 /src/libstd/sys
parent3903ea96f557dc923cf73d3905554083cd921a01 (diff)
downloadrust-06fb196256bbab1e7aa4f43daf45321efaa6e0eb.tar.gz
rust-06fb196256bbab1e7aa4f43daf45321efaa6e0eb.zip
Use `null()`/`null_mut()` instead of `0 as *const T`/`0 as *mut T`
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/net.rs7
-rw-r--r--src/libstd/sys/unix/backtrace/printing/libbacktrace.rs2
-rw-r--r--src/libstd/sys/unix/os.rs10
-rw-r--r--src/libstd/sys/unix/process.rs2
-rw-r--r--src/libstd/sys/unix/stack_overflow.rs4
-rw-r--r--src/libstd/sys/unix/sync.rs10
-rw-r--r--src/libstd/sys/unix/thread.rs2
-rw-r--r--src/libstd/sys/windows/c.rs5
-rw-r--r--src/libstd/sys/windows/fs.rs18
-rw-r--r--src/libstd/sys/windows/net.rs3
-rw-r--r--src/libstd/sys/windows/pipe.rs3
-rw-r--r--src/libstd/sys/windows/thread_local.rs2
12 files changed, 37 insertions, 31 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs
index 67e1099c295..4fb3134eac9 100644
--- a/src/libstd/sys/common/net.rs
+++ b/src/libstd/sys/common/net.rs
@@ -16,6 +16,7 @@ use io::{self, Error, ErrorKind};
 use libc::{self, c_int, c_char, c_void, socklen_t};
 use mem;
 use net::{SocketAddr, Shutdown, IpAddr};
+use ptr;
 use str::from_utf8;
 use sys::c;
 use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t};
@@ -123,9 +124,9 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> {
     init();
 
     let c_host = try!(CString::new(host));
-    let mut res = 0 as *mut _;
+    let mut res = ptr::null_mut();
     unsafe {
-        try!(cvt_gai(getaddrinfo(c_host.as_ptr(), 0 as *const _, 0 as *const _,
+        try!(cvt_gai(getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(),
                                  &mut res)));
         Ok(LookupHost { original: res, cur: res })
     }
@@ -154,7 +155,7 @@ pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> {
     let data = unsafe {
         try!(cvt_gai(getnameinfo(inner, len,
                                  hostbuf.as_mut_ptr(), NI_MAXHOST as libc::size_t,
-                                 0 as *mut _, 0, 0)));
+                                 ptr::null_mut(), 0, 0)));
 
         CStr::from_ptr(hostbuf.as_ptr())
     };
diff --git a/src/libstd/sys/unix/backtrace/printing/libbacktrace.rs b/src/libstd/sys/unix/backtrace/printing/libbacktrace.rs
index 711e241161d..5640eb81f2a 100644
--- a/src/libstd/sys/unix/backtrace/printing/libbacktrace.rs
+++ b/src/libstd/sys/unix/backtrace/printing/libbacktrace.rs
@@ -123,7 +123,7 @@ pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void,
     // FIXME: We also call self_exe_name() on DragonFly BSD. I haven't
     //        tested if this is required or not.
     unsafe fn init_state() -> *mut backtrace_state {
-        static mut STATE: *mut backtrace_state = 0 as *mut backtrace_state;
+        static mut STATE: *mut backtrace_state = ptr::null_mut();
         static mut LAST_FILENAME: [libc::c_char; 256] = [0; 256];
         if !STATE.is_null() { return STATE }
         let selfname = if cfg!(target_os = "freebsd") ||
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index fa31ac682d4..70be04b631a 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -291,7 +291,7 @@ pub fn args() -> Args {
     };
     Args {
         iter: vec.into_iter(),
-        _dont_send_or_sync_me: 0 as *mut (),
+        _dont_send_or_sync_me: ptr::null_mut(),
     }
 }
 
@@ -347,7 +347,7 @@ pub fn args() -> Args {
         }
     }
 
-    Args { iter: res.into_iter(), _dont_send_or_sync_me: 0 as *mut _ }
+    Args { iter: res.into_iter(), _dont_send_or_sync_me: ptr::null_mut() }
 }
 
 #[cfg(any(target_os = "linux",
@@ -363,7 +363,7 @@ pub fn args() -> Args {
     let v: Vec<OsString> = bytes.into_iter().map(|v| {
         OsStringExt::from_vec(v)
     }).collect();
-    Args { iter: v.into_iter(), _dont_send_or_sync_me: 0 as *mut _ }
+    Args { iter: v.into_iter(), _dont_send_or_sync_me: ptr::null_mut() }
 }
 
 pub struct Env {
@@ -403,7 +403,7 @@ pub fn env() -> Env {
             result.push(parse(CStr::from_ptr(*environ).to_bytes()));
             environ = environ.offset(1);
         }
-        Env { iter: result.into_iter(), _dont_send_or_sync_me: 0 as *mut _ }
+        Env { iter: result.into_iter(), _dont_send_or_sync_me: ptr::null_mut() }
     };
 
     fn parse(input: &[u8]) -> (OsString, OsString) {
@@ -481,7 +481,7 @@ pub fn home_dir() -> Option<PathBuf> {
         loop {
             let mut buf = Vec::with_capacity(amt);
             let mut passwd: c::passwd = mem::zeroed();
-            let mut result = 0 as *mut _;
+            let mut result = ptr::null_mut();
             match c::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(),
                                 buf.capacity() as libc::size_t,
                                 &mut result) {
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index 59798e938a6..12ca31ce5e1 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -405,7 +405,7 @@ fn make_envp(env: Option<&HashMap<OsString, OsString>>)
 
         (ptrs.as_ptr() as *const _, tmps, ptrs)
     } else {
-        (0 as *const _, Vec::new(), Vec::new())
+        (ptr::null(), Vec::new(), Vec::new())
     }
 }
 
diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs
index 1aa75fa18b7..baff3c6bcbb 100644
--- a/src/libstd/sys/unix/stack_overflow.rs
+++ b/src/libstd/sys/unix/stack_overflow.rs
@@ -93,7 +93,7 @@ mod imp {
         // See comment above for why this function returns.
     }
 
-    static mut MAIN_ALTSTACK: *mut libc::c_void = 0 as *mut libc::c_void;
+    static mut MAIN_ALTSTACK: *mut libc::c_void = ptr::null_mut();
 
     pub unsafe fn init() {
         PAGE_SIZE = ::sys::os::page_size();
@@ -155,7 +155,7 @@ mod imp {
     }
 
     pub unsafe fn make_handler() -> super::Handler {
-        super::Handler { _data: 0 as *mut libc::c_void }
+        super::Handler { _data: ptr::null_mut() }
     }
 
     pub unsafe fn drop_handler(_handler: &mut super::Handler) {
diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs
index 9c8a1f4ca40..4e49b6473c9 100644
--- a/src/libstd/sys/unix/sync.rs
+++ b/src/libstd/sys/unix/sync.rs
@@ -59,15 +59,16 @@ extern {
           target_os = "openbsd"))]
 mod os {
     use libc;
+    use ptr;
 
     pub type pthread_mutex_t = *mut libc::c_void;
     pub type pthread_mutexattr_t = *mut libc::c_void;
     pub type pthread_cond_t = *mut libc::c_void;
     pub type pthread_rwlock_t = *mut libc::c_void;
 
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _;
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
+    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut();
+    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut();
+    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut();
     pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
 }
 
@@ -213,6 +214,7 @@ mod os {
 #[cfg(target_os = "android")]
 mod os {
     use libc;
+    use ptr;
 
     #[repr(C)]
     pub struct pthread_mutex_t { value: libc::c_int }
@@ -243,7 +245,7 @@ mod os {
         writerThreadId: 0,
         pendingReaders: 0,
         pendingWriters: 0,
-        reserved: [0 as *mut _; 4],
+        reserved: [ptr::null_mut(); 4],
     };
     pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1;
 }
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 8d59461f1e4..5a551e2b3f3 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -72,7 +72,7 @@ impl Thread {
 
         extern fn thread_start(main: *mut libc::c_void) -> *mut libc::c_void {
             unsafe { start_thread(main); }
-            0 as *mut _
+            ptr::null_mut()
         }
     }
 
diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs
index 8fb03ae7902..30c7e5a52b7 100644
--- a/src/libstd/sys/windows/c.rs
+++ b/src/libstd/sys/windows/c.rs
@@ -16,6 +16,7 @@ use libc;
 use libc::{c_uint, c_ulong};
 use libc::{DWORD, BOOL, BOOLEAN, ERROR_CALL_NOT_IMPLEMENTED, LPVOID, HANDLE};
 use libc::{LPCWSTR, LONG};
+use ptr;
 
 pub use self::GET_FILEEX_INFO_LEVELS::*;
 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
@@ -294,9 +295,9 @@ pub struct CRITICAL_SECTION {
 }
 
 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
-    ptr: 0 as *mut _,
+    ptr: ptr::null_mut(),
 };
-pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: 0 as *mut _ };
+pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
 
 #[repr(C)]
 pub struct LUID {
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index d413d536cc8..e9d98b36a43 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -328,12 +328,12 @@ impl File {
             try!(cvt({
                 c::DeviceIoControl(self.handle.raw(),
                                    c::FSCTL_GET_REPARSE_POINT,
-                                   0 as *mut _,
+                                   ptr::null_mut(),
                                    0,
                                    space.as_mut_ptr() as *mut _,
                                    space.len() as libc::DWORD,
                                    &mut bytes,
-                                   0 as *mut _)
+                                   ptr::null_mut())
             }));
             Ok((bytes, &*(space.as_ptr() as *const c::REPARSE_DATA_BUFFER)))
         }
@@ -680,15 +680,15 @@ fn directory_junctions_are_directories() {
                                    c::FSCTL_SET_REPARSE_POINT,
                                    data.as_ptr() as *mut _,
                                    (*db).ReparseDataLength + 8,
-                                   0 as *mut _, 0,
+                                   ptr::null_mut(), 0,
                                    &mut ret,
-                                   0 as *mut _)).map(|_| ())
+                                   ptr::null_mut())).map(|_| ())
         }
     }
 
     fn opendir(p: &Path, write: bool) -> io::Result<File> {
         unsafe {
-            let mut token = 0 as *mut _;
+            let mut token = ptr::null_mut();
             let mut tp: c::TOKEN_PRIVILEGES = mem::zeroed();
             try!(cvt(c::OpenProcessToken(c::GetCurrentProcess(),
                                          c::TOKEN_ADJUST_PRIVILEGES,
@@ -699,14 +699,14 @@ fn directory_junctions_are_directories() {
                 "SeBackupPrivilege".as_ref()
             };
             let name = name.encode_wide().chain(Some(0)).collect::<Vec<_>>();
-            try!(cvt(c::LookupPrivilegeValueW(0 as *const _,
+            try!(cvt(c::LookupPrivilegeValueW(ptr::null(),
                                               name.as_ptr(),
                                               &mut tp.Privileges[0].Luid)));
             tp.PrivilegeCount = 1;
             tp.Privileges[0].Attributes = c::SE_PRIVILEGE_ENABLED;
             let size = mem::size_of::<c::TOKEN_PRIVILEGES>() as libc::DWORD;
             try!(cvt(c::AdjustTokenPrivileges(token, libc::FALSE, &mut tp, size,
-                                              0 as *mut _, 0 as *mut _)));
+                                              ptr::null_mut(), ptr::null_mut())));
             try!(cvt(libc::CloseHandle(token)));
 
             File::open_reparse_point(p, write)
@@ -726,9 +726,9 @@ fn directory_junctions_are_directories() {
                                    c::FSCTL_DELETE_REPARSE_POINT,
                                    data.as_ptr() as *mut _,
                                    (*db).ReparseDataLength + 8,
-                                   0 as *mut _, 0,
+                                   ptr::null_mut(), 0,
                                    &mut bytes,
-                                   0 as *mut _)).map(|_| ())
+                                   ptr::null_mut())).map(|_| ())
         }
     }
 }
diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs
index 57e84b0c46c..e62b2d8cb18 100644
--- a/src/libstd/sys/windows/net.rs
+++ b/src/libstd/sys/windows/net.rs
@@ -15,6 +15,7 @@ use mem;
 use net::SocketAddr;
 use num::One;
 use ops::Neg;
+use ptr;
 use rt;
 use sync::Once;
 use sys;
@@ -80,7 +81,7 @@ impl Socket {
             SocketAddr::V6(..) => libc::AF_INET6,
         };
         let socket = try!(unsafe {
-            match c::WSASocketW(fam, ty, 0, 0 as *mut _, 0,
+            match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0,
                                 c::WSA_FLAG_OVERLAPPED) {
                 INVALID_SOCKET => Err(last_error()),
                 n => Ok(Socket(n)),
diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs
index 7e286b91f4a..3e2f442f073 100644
--- a/src/libstd/sys/windows/pipe.rs
+++ b/src/libstd/sys/windows/pipe.rs
@@ -10,6 +10,7 @@
 
 use io;
 use libc;
+use ptr;
 use sys::cvt;
 use sys::c;
 use sys::handle::Handle;
@@ -26,7 +27,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     let mut reader = libc::INVALID_HANDLE_VALUE;
     let mut writer = libc::INVALID_HANDLE_VALUE;
     try!(cvt(unsafe {
-        c::CreatePipe(&mut reader, &mut writer, 0 as *mut _, 0)
+        c::CreatePipe(&mut reader, &mut writer, ptr::null_mut(), 0)
     }));
     let reader = Handle::new(reader);
     let writer = Handle::new(writer);
diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs
index d9b7a59712b..17bc7ee8876 100644
--- a/src/libstd/sys/windows/thread_local.rs
+++ b/src/libstd/sys/windows/thread_local.rs
@@ -58,7 +58,7 @@ pub type Dtor = unsafe extern fn(*mut u8);
 // the thread infrastructure to be in place (useful on the borders of
 // initialization/destruction).
 static DTOR_LOCK: Mutex = Mutex::new();
-static mut DTORS: *mut Vec<(Key, Dtor)> = 0 as *mut _;
+static mut DTORS: *mut Vec<(Key, Dtor)> = ptr::null_mut();
 
 // -------------------------------------------------------------------------
 // Native bindings