Skip to content

Commit d777e51

Browse files
committed
Demode reinterpret_cast
1 parent 6bfc80f commit d777e51

32 files changed

+148
-147
lines changed

src/libcore/at_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern mod rusti {
2929
pure fn capacity<T>(&&v: @[const T]) -> uint {
3030
unsafe {
3131
let repr: **unsafe::VecRepr =
32-
::unsafe::reinterpret_cast(addr_of(v));
32+
::unsafe::reinterpret_cast(&addr_of(v));
3333
(**repr).alloc / sys::size_of::<T>()
3434
}
3535
}
@@ -154,13 +154,13 @@ mod unsafe {
154154
*/
155155
#[inline(always)]
156156
unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
157-
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
157+
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
158158
(**repr).fill = new_len * sys::size_of::<T>();
159159
}
160160

161161
#[inline(always)]
162162
unsafe fn push<T>(&v: @[const T], +initval: T) {
163-
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
163+
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
164164
let fill = (**repr).fill;
165165
if (**repr).alloc > fill {
166166
push_fast(v, initval);
@@ -172,7 +172,7 @@ mod unsafe {
172172
// This doesn't bother to make sure we have space.
173173
#[inline(always)] // really pretty please
174174
unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
175-
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
175+
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
176176
let fill = (**repr).fill;
177177
(**repr).fill += sys::size_of::<T>();
178178
let p = ptr::addr_of((**repr).data);

src/libcore/dvec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
8181
priv impl<A> DVec<A> {
8282
pure fn check_not_borrowed() {
8383
unsafe {
84-
let data: *() = unsafe::reinterpret_cast(self.data);
84+
let data: *() = unsafe::reinterpret_cast(&self.data);
8585
if data.is_null() {
8686
fail ~"Recursive use of dvec";
8787
}
@@ -91,9 +91,9 @@ priv impl<A> DVec<A> {
9191
#[inline(always)]
9292
fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
9393
unsafe {
94-
let mut data = unsafe::reinterpret_cast(null::<()>());
94+
let mut data = unsafe::reinterpret_cast(&null::<()>());
9595
data <-> self.data;
96-
let data_ptr: *() = unsafe::reinterpret_cast(data);
96+
let data_ptr: *() = unsafe::reinterpret_cast(&data);
9797
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
9898
return f(data);
9999
}
@@ -156,9 +156,9 @@ impl<A> DVec<A> {
156156
/// Insert a single item at the front of the list
157157
fn unshift(-t: A) {
158158
unsafe {
159-
let mut data = unsafe::reinterpret_cast(null::<()>());
159+
let mut data = unsafe::reinterpret_cast(&null::<()>());
160160
data <-> self.data;
161-
let data_ptr: *() = unsafe::reinterpret_cast(data);
161+
let data_ptr: *() = unsafe::reinterpret_cast(&data);
162162
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
163163
log(error, ~"a");
164164
self.data <- ~[mut t];

src/libcore/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ mod global_env {
222222
fn getenv(n: &str) -> Option<~str> {
223223
unsafe {
224224
let s = str::as_c_str(n, libc::getenv);
225-
return if ptr::null::<u8>() == unsafe::reinterpret_cast(s) {
225+
return if ptr::null::<u8>() == unsafe::reinterpret_cast(&s) {
226226
option::None::<~str>
227227
} else {
228-
let s = unsafe::reinterpret_cast(s);
228+
let s = unsafe::reinterpret_cast(&s);
229229
option::Some::<~str>(str::unsafe::from_buf(s))
230230
};
231231
}
@@ -595,7 +595,7 @@ fn make_dir(p: &Path, mode: c_int) -> bool {
595595
import win32::*;
596596
// FIXME: turn mode into something useful? #2623
597597
do as_utf16_p(p.to_str()) |buf| {
598-
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) })
598+
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(&0) })
599599
!= (0 as BOOL)
600600
}
601601
}

src/libcore/pipes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ struct PacketHeader {
189189
// thing. You'll proobably want to forget them when you're done.
190190
unsafe fn buf_header() -> ~BufferHeader {
191191
assert self.buffer.is_not_null();
192-
reinterpret_cast(self.buffer)
192+
reinterpret_cast(&self.buffer)
193193
}
194194

195195
fn set_buffer<T: send>(b: ~Buffer<T>) unsafe {
196-
self.buffer = reinterpret_cast(b);
196+
self.buffer = reinterpret_cast(&b);
197197
}
198198
}
199199

@@ -253,7 +253,7 @@ fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
253253
};
254254

255255
unsafe {
256-
b.data.header.buffer = reinterpret_cast(b);
256+
b.data.header.buffer = reinterpret_cast(&b);
257257
}
258258

259259
b
@@ -274,7 +274,7 @@ fn entangle_buffer<T: send, Tstart: send>(
274274
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
275275
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
276276
{
277-
let p = init(unsafe { reinterpret_cast(buffer) }, &buffer.data);
277+
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
278278
unsafe { forget(buffer) }
279279
(SendPacketBuffered(p), RecvPacketBuffered(p))
280280
}

src/libcore/priv.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ unsafe fn chan_from_global_ptr<T: send>(
6363
// This is the proposed global channel
6464
let ch = comm::recv(setup_po);
6565
// 0 is our sentinal value. It is not a valid channel
66-
assert unsafe::reinterpret_cast(ch) != 0u;
66+
assert unsafe::reinterpret_cast(&ch) != 0u;
6767
6868
// Install the channel
6969
log(debug,~"BEFORE COMPARE AND SWAP");
7070
let swapped = compare_and_swap(
71-
global, 0u, unsafe::reinterpret_cast(ch));
71+
global, 0u, unsafe::reinterpret_cast(&ch));
7272
log(debug,fmt!("AFTER .. swapped? %?", swapped));
7373

7474
if swapped {
@@ -78,11 +78,11 @@ unsafe fn chan_from_global_ptr<T: send>(
7878
} else {
7979
// Somebody else got in before we did
8080
comm::send(setup_ch, Abort);
81-
unsafe::reinterpret_cast(*global)
81+
unsafe::reinterpret_cast(&*global)
8282
}
8383
} else {
8484
log(debug, ~"global != 0");
85-
unsafe::reinterpret_cast(*global)
85+
unsafe::reinterpret_cast(&*global)
8686
}
8787
}
8888

@@ -189,7 +189,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
189189
let po = comm::Port();
190190
let ch = comm::Chan(po);
191191
unsafe {
192-
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
192+
rustrt::rust_task_weaken(unsafe::reinterpret_cast(&ch));
193193
}
194194
let _unweaken = Unweaken(ch);
195195
f(po);
@@ -198,7 +198,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
198198
let ch: comm::Chan<()>;
199199
new(ch: comm::Chan<()>) { self.ch = ch; }
200200
drop unsafe {
201-
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
201+
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch));
202202
}
203203
}
204204
}

src/libcore/ptr.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pure fn addr_of<T>(val: T) -> *T { unchecked { rusti::addr_of(val) } }
4545
#[inline(always)]
4646
pure fn mut_addr_of<T>(val: T) -> *mut T {
4747
unsafe {
48-
unsafe::reinterpret_cast(rusti::addr_of(val))
48+
unsafe::reinterpret_cast(&rusti::addr_of(val))
4949
}
5050
}
5151

@@ -89,7 +89,7 @@ unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
8989

9090
/// Create an unsafe null pointer
9191
#[inline(always)]
92-
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(0u) } }
92+
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(&0u) } }
9393

9494
/// Returns true if the pointer is equal to the null pointer.
9595
pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
@@ -137,7 +137,7 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
137137
*/
138138
#[inline(always)]
139139
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
140-
unsafe::reinterpret_cast(thing)
140+
unsafe::reinterpret_cast(&thing)
141141
}
142142

143143
/**
@@ -149,7 +149,7 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
149149
*/
150150
#[inline(always)]
151151
fn to_uint<T>(thing: &T) -> uint unsafe {
152-
unsafe::reinterpret_cast(thing)
152+
unsafe::reinterpret_cast(&thing)
153153
}
154154

155155
/// Determine if two borrowed pointers point to the same thing.
@@ -175,32 +175,32 @@ impl<T> *T: Ptr {
175175
// Equality for pointers
176176
impl<T> *const T : Eq {
177177
pure fn eq(&&other: *const T) -> bool unsafe {
178-
let a: uint = unsafe::reinterpret_cast(self);
179-
let b: uint = unsafe::reinterpret_cast(other);
178+
let a: uint = unsafe::reinterpret_cast(&self);
179+
let b: uint = unsafe::reinterpret_cast(&other);
180180
return a == b;
181181
}
182182
}
183183

184184
// Comparison for pointers
185185
impl<T> *const T : Ord {
186186
pure fn lt(&&other: *const T) -> bool unsafe {
187-
let a: uint = unsafe::reinterpret_cast(self);
188-
let b: uint = unsafe::reinterpret_cast(other);
187+
let a: uint = unsafe::reinterpret_cast(&self);
188+
let b: uint = unsafe::reinterpret_cast(&other);
189189
return a < b;
190190
}
191191
pure fn le(&&other: *const T) -> bool unsafe {
192-
let a: uint = unsafe::reinterpret_cast(self);
193-
let b: uint = unsafe::reinterpret_cast(other);
192+
let a: uint = unsafe::reinterpret_cast(&self);
193+
let b: uint = unsafe::reinterpret_cast(&other);
194194
return a <= b;
195195
}
196196
pure fn ge(&&other: *const T) -> bool unsafe {
197-
let a: uint = unsafe::reinterpret_cast(self);
198-
let b: uint = unsafe::reinterpret_cast(other);
197+
let a: uint = unsafe::reinterpret_cast(&self);
198+
let b: uint = unsafe::reinterpret_cast(&other);
199199
return a >= b;
200200
}
201201
pure fn gt(&&other: *const T) -> bool unsafe {
202-
let a: uint = unsafe::reinterpret_cast(self);
203-
let b: uint = unsafe::reinterpret_cast(other);
202+
let a: uint = unsafe::reinterpret_cast(&self);
203+
let b: uint = unsafe::reinterpret_cast(&other);
204204
return a > b;
205205
}
206206
}
@@ -226,7 +226,7 @@ fn test() {
226226
type Pair = {mut fst: int, mut snd: int};
227227
let p = {mut fst: 10, mut snd: 20};
228228
let pptr: *mut Pair = mut_addr_of(p);
229-
let iptr: *mut int = unsafe::reinterpret_cast(pptr);
229+
let iptr: *mut int = unsafe::reinterpret_cast(&pptr);
230230
assert (*iptr == 10);;
231231
*iptr = 30;
232232
assert (*iptr == 30);

src/libcore/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
113113
}
114114
vec::push(ptrs, ptr::null());
115115
vec::as_buf(ptrs, |p, _len|
116-
unsafe { cb(::unsafe::reinterpret_cast(p)) }
116+
unsafe { cb(::unsafe::reinterpret_cast(&p)) }
117117
)
118118
}
119119
_ => cb(ptr::null())
@@ -133,12 +133,12 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
133133
for vec::each(es) |e| {
134134
let (k,v) = e;
135135
let t = fmt!("%s=%s", k, v);
136-
let mut v : ~[u8] = ::unsafe::reinterpret_cast(t);
136+
let mut v : ~[u8] = ::unsafe::reinterpret_cast(&t);
137137
blk += v;
138138
::unsafe::forget(v);
139139
}
140140
blk += ~[0_u8];
141-
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p)))
141+
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p)))
142142
}
143143
_ => cb(ptr::null())
144144
}

src/libcore/stackwalk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ fn walk_stack(visit: fn(Frame) -> bool) {
2020

2121
do frame_address |frame_pointer| {
2222
let mut frame_address: *Word = unsafe {
23-
reinterpret_cast(frame_pointer)
23+
reinterpret_cast(&frame_pointer)
2424
};
2525
loop {
2626
let fr = Frame(frame_address);
2727

28-
debug!("frame: %x", unsafe { reinterpret_cast(fr.fp) });
28+
debug!("frame: %x", unsafe { reinterpret_cast(&fr.fp) });
2929
visit(fr);
3030

3131
unsafe {
32-
let next_fp: **Word = reinterpret_cast(frame_address);
32+
let next_fp: **Word = reinterpret_cast(&frame_address);
3333
frame_address = *next_fp;
3434
if *frame_address == 0u {
3535
debug!("encountered task_start_wrapper. ending walk");

src/libcore/str.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn push_char(&s: ~str, ch: char) {
164164
reserve_at_least(s, new_len);
165165
let off = len;
166166
do as_buf(s) |buf, _len| {
167-
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
167+
let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf);
168168
if nb == 1u {
169169
*ptr::mut_offset(buf, off) =
170170
code as u8;
@@ -1746,7 +1746,7 @@ const tag_six_b: uint = 252u;
17461746
*/
17471747
pure fn as_bytes<T>(s: ~str, f: fn(~[u8]) -> T) -> T {
17481748
unsafe {
1749-
let v: *~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
1749+
let v: *~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
17501750
f(*v)
17511751
}
17521752
}
@@ -1790,7 +1790,7 @@ pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
17901790
#[inline(always)]
17911791
pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
17921792
unsafe {
1793-
let v : *(*u8,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s));
1793+
let v : *(*u8,uint) = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
17941794
let (buf,len) = *v;
17951795
f(buf, len)
17961796
}
@@ -1814,7 +1814,7 @@ pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
18141814
*/
18151815
fn reserve(&s: ~str, n: uint) {
18161816
unsafe {
1817-
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
1817+
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
18181818
vec::reserve(*v, n + 1);
18191819
}
18201820
}
@@ -1917,18 +1917,18 @@ mod unsafe {
19171917
/// without copying
19181918
unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str {
19191919
let v = (*buf, len + 1);
1920-
assert is_utf8(::unsafe::reinterpret_cast(v));
1920+
assert is_utf8(::unsafe::reinterpret_cast(&v));
19211921
return ::unsafe::transmute(v);
19221922
}
19231923

19241924
/// Create a Rust string from a null-terminated C string
19251925
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
1926-
from_buf(::unsafe::reinterpret_cast(c_str))
1926+
from_buf(::unsafe::reinterpret_cast(&c_str))
19271927
}
19281928

19291929
/// Create a Rust string from a `*c_char` buffer of the given length
19301930
unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str {
1931-
from_buf_len(::unsafe::reinterpret_cast(c_str), len)
1931+
from_buf_len(::unsafe::reinterpret_cast(&c_str), len)
19321932
}
19331933

19341934
/// Converts a vector of bytes to a string.
@@ -1987,15 +1987,15 @@ mod unsafe {
19871987
assert (end <= n);
19881988

19891989
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
1990-
::unsafe::reinterpret_cast(tuple)
1990+
::unsafe::reinterpret_cast(&tuple)
19911991
}
19921992
}
19931993

19941994
/// Appends a byte to a string. (Not UTF-8 safe).
19951995
unsafe fn push_byte(&s: ~str, b: u8) {
19961996
reserve_at_least(s, s.len() + 1);
19971997
do as_buf(s) |buf, len| {
1998-
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
1998+
let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf);
19991999
*ptr::mut_offset(buf, len) = b;
20002000
}
20012001
set_len(s, s.len() + 1);
@@ -2027,7 +2027,7 @@ mod unsafe {
20272027

20282028
/// Sets the length of the string and adds the null terminator
20292029
unsafe fn set_len(&v: ~str, new_len: uint) {
2030-
let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(v);
2030+
let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(&v);
20312031
(*repr).fill = new_len + 1u;
20322032
let null = ptr::mut_offset(ptr::mut_addr_of((*repr).data), new_len);
20332033
*null = 0u8;

0 commit comments

Comments
 (0)