Skip to content

Commit 6373861

Browse files
committed
core: Convert reinterpret_cast to transmute in TLS. #6039
1 parent e944c7d commit 6373861

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/libcore/task/local_data_priv.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl<T:Durable> LocalData for @T { }
4949
impl Eq for @LocalData {
5050
fn eq(&self, other: &@LocalData) -> bool {
5151
unsafe {
52-
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
53-
let ptr_b: (uint, uint) = cast::reinterpret_cast(other);
52+
let ptr_a: &(uint, uint) = cast::transmute(self);
53+
let ptr_b: &(uint, uint) = cast::transmute(other);
5454
return ptr_a == ptr_b;
5555
}
5656
}
@@ -68,7 +68,7 @@ fn cleanup_task_local_map(map_ptr: *libc::c_void) {
6868
assert!(!map_ptr.is_null());
6969
// Get and keep the single reference that was created at the
7070
// beginning.
71-
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);
71+
let _map: TaskLocalMap = cast::transmute(map_ptr);
7272
// All local_data will be destroyed along with the map.
7373
}
7474
}
@@ -125,14 +125,9 @@ unsafe fn get_newsched_local_map(local: *mut LocalStorage) -> TaskLocalMap {
125125
&LocalStorage(ref mut map_ptr, ref mut at_exit) => {
126126
assert!((*map_ptr).is_null());
127127
let map: TaskLocalMap = @mut ~[];
128-
// Use reinterpret_cast -- transmute would take map away from us also.
129-
*map_ptr = cast::reinterpret_cast(&map);
128+
*map_ptr = cast::transmute(map);
130129
let at_exit_fn: ~fn(*libc::c_void) = |p|cleanup_task_local_map(p);
131130
*at_exit = Some(at_exit_fn);
132-
// Also need to reference it an extra time to keep it for now.
133-
let nonmut = cast::transmute::<TaskLocalMap,
134-
@~[Option<TaskLocalElement>]>(map);
135-
cast::bump_box_refcount(nonmut);
136131
return map;
137132
}
138133
}
@@ -143,7 +138,7 @@ unsafe fn key_to_key_value<T:Durable>(
143138

144139
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
145140
// Use reintepret_cast -- transmute would leak (forget) the closure.
146-
let pair: (*libc::c_void, *libc::c_void) = cast::reinterpret_cast(&key);
141+
let pair: (*libc::c_void, *libc::c_void) = cast::transmute(key);
147142
pair.first()
148143
}
149144

@@ -213,7 +208,7 @@ pub unsafe fn local_set<T:Durable>(
213208
// own on it can be dropped when the box is destroyed. The unsafe pointer
214209
// does not have a reference associated with it, so it may become invalid
215210
// when the box is destroyed.
216-
let data_ptr = cast::reinterpret_cast(&data);
211+
let data_ptr = *cast::transmute::<&@T, &*libc::c_void>(&data);
217212
let data_box = @data as @LocalData;
218213
// Construct new entry to store in the map.
219214
let new_entry = Some((keyval, data_ptr, data_box));

0 commit comments

Comments
 (0)