1
Fork 0

Use ptr::{null, null_mut} instead of 0 as *{const, mut}

This commit is contained in:
Tobias Bucher 2016-06-24 20:54:52 +02:00
parent 2539c15b49
commit 81e95c18b7
12 changed files with 41 additions and 29 deletions

View file

@ -57,6 +57,7 @@
#![allow(private_no_mangle_fns)] #![allow(private_no_mangle_fns)]
use core::any::Any; use core::any::Any;
use core::ptr;
use alloc::boxed::Box; use alloc::boxed::Box;
use unwind as uw; use unwind as uw;
@ -88,7 +89,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
} }
pub fn payload() -> *mut u8 { pub fn payload() -> *mut u8 {
0 as *mut u8 ptr::null_mut()
} }
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> { pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

View file

@ -18,6 +18,7 @@ use alloc::boxed::Box;
use core::any::Any; use core::any::Any;
use core::intrinsics; use core::intrinsics;
use core::ptr;
use dwarf::eh; use dwarf::eh;
use windows as c; use windows as c;
@ -50,7 +51,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
} }
pub fn payload() -> *mut u8 { pub fn payload() -> *mut u8 {
0 as *mut u8 ptr::null_mut()
} }
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> { pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

View file

@ -98,6 +98,7 @@ use libc::c_uint;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::ptr;
use std::rc::Rc; use std::rc::Rc;
use std::str; use std::str;
use std::{i8, i16, i32, i64}; use std::{i8, i16, i32, i64};
@ -2304,7 +2305,7 @@ pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
start_fn, start_fn,
args.as_ptr(), args.as_ptr(),
args.len() as c_uint, args.len() as c_uint,
0 as *mut _, ptr::null_mut(),
noname()); noname());
llvm::LLVMBuildRet(bld, result); llvm::LLVMBuildRet(bld, result);

View file

@ -177,7 +177,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
check_call("invoke", llfn, args); check_call("invoke", llfn, args);
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _); let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
unsafe { unsafe {
llvm::LLVMRustBuildInvoke(self.llbuilder, llvm::LLVMRustBuildInvoke(self.llbuilder,
@ -859,7 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
check_call("call", llfn, args); check_call("call", llfn, args);
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _); let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
unsafe { unsafe {
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(), llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@ -961,7 +961,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.count_insn("trap"); self.count_insn("trap");
llvm::LLVMRustBuildCall(self.llbuilder, t, llvm::LLVMRustBuildCall(self.llbuilder, t,
args.as_ptr(), args.len() as c_uint, args.as_ptr(), args.len() as c_uint,
0 as *mut _, ptr::null_mut(),
noname()); noname());
} }
} }
@ -1000,7 +1000,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
parent: Option<ValueRef>, parent: Option<ValueRef>,
args: &[ValueRef]) -> ValueRef { args: &[ValueRef]) -> ValueRef {
self.count_insn("cleanuppad"); self.count_insn("cleanuppad");
let parent = parent.unwrap_or(0 as *mut _); let parent = parent.unwrap_or(ptr::null_mut());
let name = CString::new("cleanuppad").unwrap(); let name = CString::new("cleanuppad").unwrap();
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCleanupPad(self.llbuilder, llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@ -1016,7 +1016,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn cleanup_ret(&self, cleanup: ValueRef, pub fn cleanup_ret(&self, cleanup: ValueRef,
unwind: Option<BasicBlockRef>) -> ValueRef { unwind: Option<BasicBlockRef>) -> ValueRef {
self.count_insn("cleanupret"); self.count_insn("cleanupret");
let unwind = unwind.unwrap_or(0 as *mut _); let unwind = unwind.unwrap_or(ptr::null_mut());
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind) llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
}; };
@ -1052,8 +1052,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
unwind: Option<BasicBlockRef>, unwind: Option<BasicBlockRef>,
num_handlers: usize) -> ValueRef { num_handlers: usize) -> ValueRef {
self.count_insn("catchswitch"); self.count_insn("catchswitch");
let parent = parent.unwrap_or(0 as *mut _); let parent = parent.unwrap_or(ptr::null_mut());
let unwind = unwind.unwrap_or(0 as *mut _); let unwind = unwind.unwrap_or(ptr::null_mut());
let name = CString::new("catchswitch").unwrap(); let name = CString::new("catchswitch").unwrap();
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind, llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

View file

@ -65,6 +65,7 @@
// it! // it!
use marker; use marker;
use ptr;
use sync::atomic::{AtomicUsize, AtomicBool, Ordering}; use sync::atomic::{AtomicUsize, AtomicBool, Ordering};
use thread::{self, Thread}; use thread::{self, Thread};
@ -297,7 +298,7 @@ impl Once {
let mut node = Waiter { let mut node = Waiter {
thread: Some(thread::current()), thread: Some(thread::current()),
signaled: AtomicBool::new(false), signaled: AtomicBool::new(false),
next: 0 as *mut Waiter, next: ptr::null_mut(),
}; };
let me = &mut node as *mut Waiter as usize; let me = &mut node as *mut Waiter as usize;
assert!(me & STATE_MASK == 0); assert!(me & STATE_MASK == 0);

View file

@ -227,11 +227,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
libc::KERN_PROC_ARGV]; libc::KERN_PROC_ARGV];
let mib = mib.as_mut_ptr(); let mib = mib.as_mut_ptr();
let mut argv_len = 0; let mut argv_len = 0;
cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len,
0 as *mut _, 0))?; ptr::null_mut(), 0))?;
let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize);
cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _,
&mut argv_len, 0 as *mut _, 0))?; &mut argv_len, ptr::null_mut(), 0))?;
argv.set_len(argv_len as usize); argv.set_len(argv_len as usize);
if argv[0].is_null() { if argv[0].is_null() {
return Err(io::Error::new(io::ErrorKind::Other, return Err(io::Error::new(io::ErrorKind::Other,

View file

@ -14,6 +14,7 @@ use cmp;
use io; use io;
use libc::{self, c_int}; use libc::{self, c_int};
use mem; use mem;
use ptr;
use sys::cvt_r; use sys::cvt_r;
use sys::fd::FileDesc; use sys::fd::FileDesc;
@ -92,8 +93,8 @@ pub fn read2(p1: AnonPipe,
let mut read: libc::fd_set = mem::zeroed(); let mut read: libc::fd_set = mem::zeroed();
libc::FD_SET(p1.raw(), &mut read); libc::FD_SET(p1.raw(), &mut read);
libc::FD_SET(p2.raw(), &mut read); libc::FD_SET(p2.raw(), &mut read);
libc::select(max + 1, &mut read, 0 as *mut _, 0 as *mut _, libc::select(max + 1, &mut read, ptr::null_mut(), ptr::null_mut(),
0 as *mut _) ptr::null_mut())
})?; })?;
// Read as much as we can from each pipe, ignoring EWOULDBLOCK or // Read as much as we can from each pipe, ignoring EWOULDBLOCK or

View file

@ -96,7 +96,7 @@ impl Command {
let mut saw_nul = false; let mut saw_nul = false;
let program = os2c(program, &mut saw_nul); let program = os2c(program, &mut saw_nul);
Command { Command {
argv: vec![program.as_ptr(), 0 as *const _], argv: vec![program.as_ptr(), ptr::null()],
program: program, program: program,
args: Vec::new(), args: Vec::new(),
env: None, env: None,
@ -117,7 +117,7 @@ impl Command {
// pointer. // pointer.
let arg = os2c(arg, &mut self.saw_nul); let arg = os2c(arg, &mut self.saw_nul);
self.argv[self.args.len() + 1] = arg.as_ptr(); self.argv[self.args.len() + 1] = arg.as_ptr();
self.argv.push(0 as *const _); self.argv.push(ptr::null());
// Also make sure we keep track of the owned value to schedule a // Also make sure we keep track of the owned value to schedule a
// destructor for this memory. // destructor for this memory.
@ -134,7 +134,7 @@ impl Command {
envp.push(s.as_ptr()); envp.push(s.as_ptr());
map.insert(k, (envp.len() - 1, s)); map.insert(k, (envp.len() - 1, s));
} }
envp.push(0 as *const _); envp.push(ptr::null());
self.env = Some(map); self.env = Some(map);
self.envp = Some(envp); self.envp = Some(envp);
} }
@ -158,7 +158,7 @@ impl Command {
Entry::Vacant(e) => { Entry::Vacant(e) => {
let len = envp.len(); let len = envp.len();
envp[len - 1] = new_key.as_ptr(); envp[len - 1] = new_key.as_ptr();
envp.push(0 as *const _); envp.push(ptr::null());
e.insert((len - 1, new_key)); e.insert((len - 1, new_key));
} }
} }
@ -183,7 +183,7 @@ impl Command {
pub fn env_clear(&mut self) { pub fn env_clear(&mut self) {
self.env = Some(HashMap::new()); self.env = Some(HashMap::new());
self.envp = Some(vec![0 as *const _]); self.envp = Some(vec![ptr::null()]);
} }
pub fn cwd(&mut self, dir: &OsStr) { pub fn cwd(&mut self, dir: &OsStr) {

View file

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
use cmp::Ordering; use cmp::Ordering;
use time::Duration;
use libc; use libc;
use time::Duration;
pub use self::inner::{Instant, SystemTime, UNIX_EPOCH}; pub use self::inner::{Instant, SystemTime, UNIX_EPOCH};
@ -164,12 +164,14 @@ mod inner {
impl SystemTime { impl SystemTime {
pub fn now() -> SystemTime { pub fn now() -> SystemTime {
use ptr;
let mut s = libc::timeval { let mut s = libc::timeval {
tv_sec: 0, tv_sec: 0,
tv_usec: 0, tv_usec: 0,
}; };
cvt(unsafe { cvt(unsafe {
libc::gettimeofday(&mut s, 0 as *mut _) libc::gettimeofday(&mut s, ptr::null_mut())
}).unwrap(); }).unwrap();
return SystemTime::from(s) return SystemTime::from(s)
} }

View file

@ -46,10 +46,10 @@ impl Handle {
pub fn new_event(manual: bool, init: bool) -> io::Result<Handle> { pub fn new_event(manual: bool, init: bool) -> io::Result<Handle> {
unsafe { unsafe {
let event = c::CreateEventW(0 as *mut _, let event = c::CreateEventW(ptr::null_mut(),
manual as c::BOOL, manual as c::BOOL,
init as c::BOOL, init as c::BOOL,
0 as *const _); ptr::null());
if event.is_null() { if event.is_null() {
Err(io::Error::last_os_error()) Err(io::Error::last_os_error())
} else { } else {

View file

@ -12,9 +12,10 @@ use prelude::v1::*;
use os::windows::prelude::*; use os::windows::prelude::*;
use ffi::OsStr; use ffi::OsStr;
use path::Path;
use io; use io;
use mem; use mem;
use path::Path;
use ptr;
use rand::{self, Rng}; use rand::{self, Rng};
use slice; use slice;
use sys::c; use sys::c;
@ -66,7 +67,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
4096, 4096,
4096, 4096,
0, 0,
0 as *mut _); ptr::null_mut());
// We pass the FILE_FLAG_FIRST_PIPE_INSTANCE flag above, and we're // We pass the FILE_FLAG_FIRST_PIPE_INSTANCE flag above, and we're
// also just doing a best effort at selecting a unique name. If // also just doing a best effort at selecting a unique name. If

View file

@ -959,6 +959,8 @@ fn get_concurrency() -> usize {
target_os = "bitrig", target_os = "bitrig",
target_os = "netbsd"))] target_os = "netbsd"))]
fn num_cpus() -> usize { fn num_cpus() -> usize {
use std::ptr;
let mut cpus: libc::c_uint = 0; let mut cpus: libc::c_uint = 0;
let mut cpus_size = std::mem::size_of_val(&cpus); let mut cpus_size = std::mem::size_of_val(&cpus);
@ -972,7 +974,7 @@ fn get_concurrency() -> usize {
2, 2,
&mut cpus as *mut _ as *mut _, &mut cpus as *mut _ as *mut _,
&mut cpus_size as *mut _ as *mut _, &mut cpus_size as *mut _ as *mut _,
0 as *mut _, ptr::null_mut(),
0); 0);
} }
if cpus < 1 { if cpus < 1 {
@ -984,6 +986,8 @@ fn get_concurrency() -> usize {
#[cfg(target_os = "openbsd")] #[cfg(target_os = "openbsd")]
fn num_cpus() -> usize { fn num_cpus() -> usize {
use std::ptr;
let mut cpus: libc::c_uint = 0; let mut cpus: libc::c_uint = 0;
let mut cpus_size = std::mem::size_of_val(&cpus); let mut cpus_size = std::mem::size_of_val(&cpus);
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0]; let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
@ -993,7 +997,7 @@ fn get_concurrency() -> usize {
2, 2,
&mut cpus as *mut _ as *mut _, &mut cpus as *mut _ as *mut _,
&mut cpus_size as *mut _ as *mut _, &mut cpus_size as *mut _ as *mut _,
0 as *mut _, ptr::null_mut(),
0); 0);
} }
if cpus < 1 { if cpus < 1 {