Skip to content

Commit 907db6c

Browse files
committed
rollup merge of rust-lang#21444: petrochenkov/null
Conflicts: src/libstd/sync/mpsc/select.rs
2 parents b5de833 + 2c2480d commit 907db6c

File tree

19 files changed

+63
-54
lines changed

19 files changed

+63
-54
lines changed

src/liballoc/heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ mod imp {
280280
if align <= MIN_ALIGN {
281281
libc::malloc(size as libc::size_t) as *mut u8
282282
} else {
283-
let mut out = 0 as *mut libc::c_void;
283+
let mut out = ptr::null();
284284
let ret = posix_memalign(&mut out,
285285
align as libc::size_t,
286286
size as libc::size_t);

src/liblog/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ use std::io::LineBufferedWriter;
180180
use std::io;
181181
use std::mem;
182182
use std::os;
183+
use std::ptr;
183184
use std::rt;
184185
use std::slice;
185186
use std::sync::{Once, ONCE_INIT};
@@ -437,11 +438,11 @@ fn init() {
437438
assert!(!DIRECTIVES.is_null());
438439
let _directives: Box<Vec<directive::LogDirective>> =
439440
mem::transmute(DIRECTIVES);
440-
DIRECTIVES = 0 as *const Vec<directive::LogDirective>;
441+
DIRECTIVES = ptr::null();
441442

442443
if !FILTER.is_null() {
443444
let _filter: Box<Regex> = mem::transmute(FILTER);
444-
FILTER = 0 as *const _;
445+
FILTER = ptr::null();
445446
}
446447
});
447448
}

src/librustc_llvm/diagnostic.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use self::OptimizationDiagnosticKind::*;
1414
pub use self::Diagnostic::*;
1515

1616
use libc::c_char;
17+
use std::ptr;
1718

1819
use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef};
1920

@@ -52,10 +53,10 @@ impl OptimizationDiagnostic {
5253

5354
let mut opt = OptimizationDiagnostic {
5455
kind: kind,
55-
pass_name: 0 as *const c_char,
56-
function: 0 as ValueRef,
57-
debug_loc: 0 as DebugLocRef,
58-
message: 0 as TwineRef,
56+
pass_name: ptr::null(),
57+
function: ptr::null_mut(),
58+
debug_loc: ptr::null_mut(),
59+
message: ptr::null_mut(),
5960
};
6061

6162
super::LLVMUnpackOptimizationDiagnostic(di,

src/librustc_llvm/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub use self::Linkage::*;
5353

5454
use std::ffi::CString;
5555
use std::cell::RefCell;
56-
use std::{raw, mem};
56+
use std::{raw, mem, ptr};
5757
use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
5858
use libc::{c_longlong, c_ulonglong, c_void};
5959
use debuginfo::{DIBuilderRef, DIDescriptor,
@@ -2262,19 +2262,18 @@ pub unsafe fn static_link_hack_this_sucks() {
22622262
LLVMInitializePowerPCAsmPrinter();
22632263
LLVMInitializePowerPCAsmParser();
22642264

2265-
LLVMRustSetLLVMOptions(0 as c_int,
2266-
0 as *const _);
2265+
LLVMRustSetLLVMOptions(0 as c_int, ptr::null());
22672266

2268-
LLVMPassManagerBuilderPopulateModulePassManager(0 as *mut _, 0 as *mut _);
2269-
LLVMPassManagerBuilderPopulateLTOPassManager(0 as *mut _, 0 as *mut _, False, False);
2270-
LLVMPassManagerBuilderPopulateFunctionPassManager(0 as *mut _, 0 as *mut _);
2271-
LLVMPassManagerBuilderSetOptLevel(0 as *mut _, 0 as c_uint);
2272-
LLVMPassManagerBuilderUseInlinerWithThreshold(0 as *mut _, 0 as c_uint);
2273-
LLVMWriteBitcodeToFile(0 as *mut _, 0 as *const _);
2267+
LLVMPassManagerBuilderPopulateModulePassManager(ptr::null_mut(), ptr::null_mut());
2268+
LLVMPassManagerBuilderPopulateLTOPassManager(ptr::null_mut(), ptr::null_mut(), False, False);
2269+
LLVMPassManagerBuilderPopulateFunctionPassManager(ptr::null_mut(), ptr::null_mut());
2270+
LLVMPassManagerBuilderSetOptLevel(ptr::null_mut(), 0 as c_uint);
2271+
LLVMPassManagerBuilderUseInlinerWithThreshold(ptr::null_mut(), 0 as c_uint);
2272+
LLVMWriteBitcodeToFile(ptr::null_mut(), ptr::null());
22742273
LLVMPassManagerBuilderCreate();
2275-
LLVMPassManagerBuilderDispose(0 as *mut _);
2274+
LLVMPassManagerBuilderDispose(ptr::null_mut());
22762275

2277-
LLVMRustLinkInExternalBitcode(0 as *mut _, 0 as *const _, 0 as size_t);
2276+
LLVMRustLinkInExternalBitcode(ptr::null_mut(), ptr::null(), 0 as size_t);
22782277

22792278
LLVMLinkInMCJIT();
22802279
LLVMLinkInInterpreter();

src/librustc_trans/trans/type_.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use syntax::ast;
2121

2222
use std::ffi::CString;
2323
use std::mem;
24+
use std::ptr;
2425
use std::cell::RefCell;
2526
use std::iter::repeat;
2627

@@ -295,7 +296,7 @@ impl Type {
295296
if n_elts == 0 {
296297
return Vec::new();
297298
}
298-
let mut elts: Vec<_> = repeat(Type { rf: 0 as TypeRef }).take(n_elts).collect();
299+
let mut elts: Vec<_> = repeat(Type { rf: ptr::null_mut() }).take(n_elts).collect();
299300
llvm::LLVMGetStructElementTypes(self.to_ref(),
300301
elts.as_mut_ptr() as *mut TypeRef);
301302
elts
@@ -309,7 +310,7 @@ impl Type {
309310
pub fn func_params(&self) -> Vec<Type> {
310311
unsafe {
311312
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint;
312-
let mut args: Vec<_> = repeat(Type { rf: 0 as TypeRef }).take(n_args).collect();
313+
let mut args: Vec<_> = repeat(Type { rf: ptr::null_mut() }).take(n_args).collect();
313314
llvm::LLVMGetParamTypes(self.to_ref(),
314315
args.as_mut_ptr() as *mut TypeRef);
315316
args

src/libstd/io/stdio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use mem;
4040
use option::Option;
4141
use option::Option::{Some, None};
4242
use ops::{Deref, DerefMut, FnOnce};
43+
use ptr;
4344
use result::Result::{Ok, Err};
4445
use rt;
4546
use slice::SliceExt;
@@ -238,7 +239,7 @@ pub fn stdin() -> StdinReader {
238239
// Make sure to free it at exit
239240
rt::at_exit(|| {
240241
mem::transmute::<_, Box<StdinReader>>(STDIN);
241-
STDIN = 0 as *const _;
242+
STDIN = ptr::null();
242243
});
243244
});
244245

src/libstd/sync/mpsc/mpsc_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use core::prelude::*;
4646

4747
use alloc::boxed::Box;
4848
use core::mem;
49+
use core::ptr;
4950
use core::cell::UnsafeCell;
5051

5152
use sync::atomic::{AtomicPtr, Ordering};
@@ -82,7 +83,7 @@ unsafe impl<T:Send> Sync for Queue<T> { }
8283
impl<T> Node<T> {
8384
unsafe fn new(v: Option<T>) -> *mut Node<T> {
8485
mem::transmute(box Node {
85-
next: AtomicPtr::new(0 as *mut Node<T>),
86+
next: AtomicPtr::new(ptr::null_mut()),
8687
value: v,
8788
})
8889
}

src/libstd/sync/mpsc/select.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use core::prelude::*;
5959
use core::cell::Cell;
6060
use core::marker;
6161
use core::mem;
62+
use core::ptr;
6263
use core::uint;
6364

6465
use sync::mpsc::{Receiver, RecvError};
@@ -109,16 +110,15 @@ pub trait Packet {
109110
}
110111

111112
impl Select {
112-
113113
/// Creates a new selection structure. This set is initially empty and
114114
/// `wait` will panic!() if called.
115115
///
116116
/// Usage of this struct directly can sometimes be burdensome, and usage is
117117
/// rather much easier through the `select!` macro.
118118
pub fn new() -> Select {
119119
Select {
120-
head: 0 as *mut Handle<'static, ()>,
121-
tail: 0 as *mut Handle<'static, ()>,
120+
head: ptr::null_mut(),
121+
tail: ptr::null_mut(),
122122
next_id: Cell::new(1),
123123
}
124124
}
@@ -132,8 +132,8 @@ impl Select {
132132
Handle {
133133
id: id,
134134
selector: self,
135-
next: 0 as *mut Handle<'static, ()>,
136-
prev: 0 as *mut Handle<'static, ()>,
135+
next: ptr::null_mut(),
136+
prev: ptr::null_mut(),
137137
added: false,
138138
rx: rx,
139139
packet: rx,
@@ -298,8 +298,8 @@ impl<'rx, T: Send> Handle<'rx, T> {
298298
(*self.next).prev = self.prev;
299299
}
300300

301-
self.next = 0 as *mut Handle<'static, ()>;
302-
self.prev = 0 as *mut Handle<'static, ()>;
301+
self.next = ptr::null_mut();
302+
self.prev = ptr::null_mut();
303303

304304
self.added = false;
305305
}

src/libstd/sync/mpsc/spsc_queue.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use core::prelude::*;
3939

4040
use alloc::boxed::Box;
4141
use core::mem;
42+
use core::ptr;
4243
use core::cell::UnsafeCell;
4344

4445
use sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
@@ -82,7 +83,7 @@ impl<T: Send> Node<T> {
8283
unsafe {
8384
mem::transmute(box Node {
8485
value: None,
85-
next: AtomicPtr::new(0 as *mut Node<T>),
86+
next: AtomicPtr::new(ptr::null_mut::<Node<T>>()),
8687
})
8788
}
8889
}
@@ -131,7 +132,7 @@ impl<T: Send> Queue<T> {
131132
let n = self.alloc();
132133
assert!((*n).value.is_none());
133134
(*n).value = Some(t);
134-
(*n).next.store(0 as *mut Node<T>, Ordering::Relaxed);
135+
(*n).next.store(ptr::null_mut(), Ordering::Relaxed);
135136
(**self.head.get()).next.store(n, Ordering::Release);
136137
*self.head.get() = n;
137138
}

src/libstd/sync/mpsc/sync.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use self::Blocker::*;
4040

4141
use vec::Vec;
4242
use core::mem;
43+
use core::ptr;
4344

4445
use sync::atomic::{Ordering, AtomicUsize};
4546
use sync::mpsc::blocking::{self, WaitToken, SignalToken};
@@ -145,8 +146,8 @@ impl<T: Send> Packet<T> {
145146
cap: cap,
146147
canceled: None,
147148
queue: Queue {
148-
head: 0 as *mut Node,
149-
tail: 0 as *mut Node,
149+
head: ptr::null_mut(),
150+
tail: ptr::null_mut(),
150151
},
151152
buf: Buffer {
152153
buf: range(0, cap + if cap == 0 {1} else {0}).map(|_| None).collect(),
@@ -160,7 +161,7 @@ impl<T: Send> Packet<T> {
160161
// wait until a send slot is available, returning locked access to
161162
// the channel state.
162163
fn acquire_send_slot(&self) -> MutexGuard<State<T>> {
163-
let mut node = Node { token: None, next: 0 as *mut Node };
164+
let mut node = Node { token: None, next: ptr::null_mut() };
164165
loop {
165166
let mut guard = self.lock.lock().unwrap();
166167
// are we ready to go?
@@ -343,8 +344,8 @@ impl<T: Send> Packet<T> {
343344
Vec::new()
344345
};
345346
let mut queue = mem::replace(&mut guard.queue, Queue {
346-
head: 0 as *mut Node,
347-
tail: 0 as *mut Node,
347+
head: ptr::null_mut(),
348+
tail: ptr::null_mut(),
348349
});
349350

350351
let waiter = match mem::replace(&mut guard.blocker, NoneBlocked) {
@@ -453,7 +454,7 @@ impl Queue {
453454
fn enqueue(&mut self, node: &mut Node) -> WaitToken {
454455
let (wait_token, signal_token) = blocking::tokens();
455456
node.token = Some(signal_token);
456-
node.next = 0 as *mut Node;
457+
node.next = ptr::null_mut();
457458

458459
if self.tail.is_null() {
459460
self.head = node as *mut Node;
@@ -475,10 +476,10 @@ impl Queue {
475476
let node = self.head;
476477
self.head = unsafe { (*node).next };
477478
if self.head.is_null() {
478-
self.tail = 0 as *mut Node;
479+
self.tail = ptr::null_mut();
479480
}
480481
unsafe {
481-
(*node).next = 0 as *mut Node;
482+
(*node).next = ptr::null_mut();
482483
Some((*node).token.take().unwrap())
483484
}
484485
}

src/libstd/sys/common/helper_thread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use prelude::v1::*;
2424

2525
use cell::UnsafeCell;
2626
use mem;
27+
use ptr;
2728
use rt;
2829
use sync::{StaticMutex, StaticCondvar};
2930
use sync::mpsc::{channel, Sender, Receiver};
@@ -132,7 +133,7 @@ impl<M: Send> Helper<M> {
132133

133134
// Close the channel by destroying it
134135
let chan: Box<Sender<M>> = mem::transmute(*self.chan.get());
135-
*self.chan.get() = 0 as *mut Sender<M>;
136+
*self.chan.get() = ptr::null_mut();
136137
drop(chan);
137138
helper_signal::signal(*self.signal.get() as helper_signal::signal);
138139

src/libstd/sys/unix/backtrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
353353
if state.is_null() {
354354
return output(w, idx, addr, None)
355355
}
356-
let mut data = 0 as *const libc::c_char;
356+
let mut data = ptr::null();
357357
let data_addr = &mut data as *mut *const libc::c_char;
358358
let ret = unsafe {
359359
backtrace_syminfo(state, addr as libc::uintptr_t,

src/libstd/sys/unix/condvar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use cell::UnsafeCell;
1212
use libc;
13+
use ptr;
1314
use std::option::Option::{Some, None};
1415
use sys::mutex::{self, Mutex};
1516
use sys::time;
@@ -62,7 +63,7 @@ impl Condvar {
6263
// time.
6364
let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 };
6465
let stable_now = time::SteadyTime::now();
65-
let r = ffi::gettimeofday(&mut sys_now, 0 as *mut _);
66+
let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut());
6667
debug_assert_eq!(r, 0);
6768

6869
let seconds = NumCast::from(dur.num_seconds());

src/libstd/sys/unix/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append};
1919
use io;
2020
use libc::{self, c_int, c_void};
2121
use mem;
22+
use ptr;
2223
use sys::retry;
2324
use sys_common::{keep_going, eof, mkerr_libc};
2425

@@ -207,7 +208,7 @@ pub fn readdir(p: &Path) -> IoResult<Vec<Path>> {
207208

208209
if dir_ptr as uint != 0 {
209210
let mut paths = vec!();
210-
let mut entry_ptr = 0 as *mut dirent_t;
211+
let mut entry_ptr = ptr::null_mut();
211212
while unsafe { readdir_r(dir_ptr, ptr, &mut entry_ptr) == 0 } {
212213
if entry_ptr.is_null() { break }
213214
paths.push(unsafe {

src/libstd/sys/unix/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub unsafe fn get_env_pairs() -> Vec<Vec<u8>> {
143143
os::last_os_error());
144144
}
145145
let mut result = Vec::new();
146-
while *environ != 0 as *const _ {
146+
while *environ != ptr::null() {
147147
let env_pair = ffi::c_str_to_bytes(&*environ).to_vec();
148148
result.push(env_pair);
149149
environ = environ.offset(1);

src/libstd/sys/unix/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl Process {
251251
fn setgroups(ngroups: libc::c_int,
252252
ptr: *const libc::c_void) -> libc::c_int;
253253
}
254-
let _ = setgroups(0, 0 as *const libc::c_void);
254+
let _ = setgroups(0, ptr::null());
255255

256256
if libc::setuid(u as libc::uid_t) != 0 {
257257
fail(&mut output);

src/libstd/sys/windows/backtrace.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,18 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
327327
let image = arch::init_frame(&mut frame, &context);
328328

329329
// Initialize this process's symbols
330-
let ret = SymInitialize(process, 0 as *mut libc::c_void, libc::TRUE);
330+
let ret = SymInitialize(process, ptr::null_mut(), libc::TRUE);
331331
if ret != libc::TRUE { return Ok(()) }
332332
let _c = Cleanup { handle: process, SymCleanup: SymCleanup };
333333

334334
// And now that we're done with all the setup, do the stack walking!
335335
let mut i = 0i;
336336
try!(write!(w, "stack backtrace:\n"));
337337
while StackWalk64(image, process, thread, &mut frame, &mut context,
338-
0 as *mut libc::c_void,
339-
0 as *mut libc::c_void,
340-
0 as *mut libc::c_void,
341-
0 as *mut libc::c_void) == libc::TRUE{
338+
ptr::null_mut(),
339+
ptr::null_mut(),
340+
ptr::null_mut(),
341+
ptr::null_mut()) == libc::TRUE{
342342
let addr = frame.AddrPC.Offset;
343343
if addr == frame.AddrReturn.Offset || addr == 0 ||
344344
frame.AddrReturn.Offset == 0 { break }

0 commit comments

Comments
 (0)