Skip to content

Commit 835e963

Browse files
committed
std::rt: Improve the error message when the thread-local ptr is null
Also fix some incorrect comments and variable names.
1 parent 3d14470 commit 835e963

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/libstd/rt/local_ptr.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub unsafe fn put<T>(sched: ~T) {
5252
pub unsafe fn take<T>() -> ~T {
5353
let key = tls_key();
5454
let void_ptr: *mut c_void = tls::get(key);
55-
rtassert!(void_ptr.is_not_null());
55+
if void_ptr.is_null() {
56+
rtabort!("thread-local pointer is null. bogus!");
57+
}
5658
let ptr: ~T = cast::transmute(void_ptr);
5759
tls::set(key, ptr::mut_null());
5860
return ptr;
@@ -68,8 +70,8 @@ pub fn exists() -> bool {
6870
}
6971
}
7072

71-
/// Borrow the thread-local scheduler from thread-local storage.
72-
/// While the scheduler is borrowed it is not available in TLS.
73+
/// Borrow the thread-local value from thread-local storage.
74+
/// While the value is borrowed it is not available in TLS.
7375
///
7476
/// # Safety note
7577
///
@@ -88,21 +90,23 @@ pub unsafe fn borrow<T>(f: &fn(&mut T)) {
8890
}
8991
}
9092

91-
/// Borrow a mutable reference to the thread-local Scheduler
93+
/// Borrow a mutable reference to the thread-local value
9294
///
9395
/// # Safety Note
9496
///
95-
/// Because this leaves the Scheduler in thread-local storage it is possible
97+
/// Because this leaves the value in thread-local storage it is possible
9698
/// For the Scheduler pointer to be aliased
9799
pub unsafe fn unsafe_borrow<T>() -> *mut T {
98100
let key = tls_key();
99-
let mut void_sched: *mut c_void = tls::get(key);
100-
rtassert!(void_sched.is_not_null());
101+
let mut void_ptr: *mut c_void = tls::get(key);
102+
if void_ptr.is_null() {
103+
rtabort!("thread-local pointer is null. bogus!");
104+
}
101105
{
102-
let sched: *mut *mut c_void = &mut void_sched;
103-
let sched: *mut ~T = sched as *mut ~T;
104-
let sched: *mut T = &mut **sched;
105-
return sched;
106+
let ptr: *mut *mut c_void = &mut void_ptr;
107+
let ptr: *mut ~T = ptr as *mut ~T;
108+
let ptr: *mut T = &mut **ptr;
109+
return ptr;
106110
}
107111
}
108112

0 commit comments

Comments
 (0)