Skip to content

Commit 2906f2d

Browse files
committed
core: Rename 'unsafe' mod to 'cast'
1 parent 77480e8 commit 2906f2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+218
-218
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: **raw::VecRepr =
32-
::unsafe::reinterpret_cast(&addr_of(v));
32+
::cast::reinterpret_cast(&addr_of(v));
3333
(**repr).unboxed.alloc / sys::size_of::<T>()
3434
}
3535
}
@@ -154,13 +154,13 @@ mod raw {
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 = ::cast::reinterpret_cast(&addr_of(v));
158158
(**repr).unboxed.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 = ::cast::reinterpret_cast(&addr_of(v));
164164
let fill = (**repr).unboxed.fill;
165165
if (**repr).unboxed.alloc > fill {
166166
push_fast(v, move initval);
@@ -172,7 +172,7 @@ mod raw {
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 = ::cast::reinterpret_cast(&addr_of(v));
176176
let fill = (**repr).unboxed.fill;
177177
(**repr).unboxed.fill += sys::size_of::<T>();
178178
let p = ptr::addr_of((**repr).unboxed.data);
File renamed without changes.

src/libcore/cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libc::{c_char, c_void, intptr_t, uintptr_t};
22
use ptr::{mut_null, null, to_unsafe_ptr};
33
use repr::BoxRepr;
44
use sys::TypeDesc;
5-
use unsafe::transmute;
5+
use cast::transmute;
66

77
export annihilate;
88

src/libcore/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn send<T: Send>(ch: Chan<T>, +data: T) {
181181
let res = rustrt::rust_port_id_send(p, data_ptr);
182182
if res != 0 unsafe {
183183
// Data sent successfully
184-
unsafe::forget(move data);
184+
cast::forget(move data);
185185
}
186186
task::yield();
187187
}

src/libcore/core.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export uint, u8, u16, u32, u64;
4141
export float, f32, f64;
4242
export box, char, str, ptr, vec, at_vec, bool;
4343
export either, option, result, iter;
44-
export gc, io, libc, os, run, rand, sys, unsafe, logging;
44+
export gc, io, libc, os, run, rand, sys, cast, logging;
4545
export comm, task, future, pipes;
4646
export extfmt;
4747
// The test harness links against core, so don't include runtime in tests.
@@ -228,7 +228,7 @@ mod path;
228228
mod rand;
229229
mod run;
230230
mod sys;
231-
mod unsafe;
231+
mod cast;
232232
mod mutable;
233233
mod flate;
234234
mod repr;

src/libcore/dvec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// Note that recursive use is not permitted.
1111

12-
use unsafe::reinterpret_cast;
12+
use cast::reinterpret_cast;
1313
use ptr::null;
1414

1515
export DVec;
@@ -81,7 +81,7 @@ fn unwrap<A>(+d: DVec<A>) -> ~[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: *() = cast::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(-~[A]) -> B) -> B {
9393
unsafe {
94-
let mut data = unsafe::reinterpret_cast(&null::<()>());
94+
let mut data = cast::reinterpret_cast(&null::<()>());
9595
data <-> self.data;
96-
let data_ptr: *() = unsafe::reinterpret_cast(&data);
96+
let data_ptr: *() = cast::reinterpret_cast(&data);
9797
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
9898
return f(move data);
9999
}
@@ -168,9 +168,9 @@ impl<A> DVec<A> {
168168
/// Insert a single item at the front of the list
169169
fn unshift(-t: A) {
170170
unsafe {
171-
let mut data = unsafe::reinterpret_cast(&null::<()>());
171+
let mut data = cast::reinterpret_cast(&null::<()>());
172172
data <-> self.data;
173-
let data_ptr: *() = unsafe::reinterpret_cast(&data);
173+
let data_ptr: *() = cast::reinterpret_cast(&data);
174174
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
175175
log(error, ~"a");
176176
self.data <- ~[move t];

src/libcore/future.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use either::Either;
1919
use pipes::recv;
20-
use unsafe::copy_lifetime;
20+
use cast::copy_lifetime;
2121

2222
export Future;
2323
export extensions;

src/libcore/gc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ extern mod rustrt {
5555
}
5656

5757
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
58-
return unsafe::reinterpret_cast(&ptr::offset(ptr, count));
58+
return cast::reinterpret_cast(&ptr::offset(ptr, count));
5959
}
6060

6161
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
6262
let align = sys::min_align_of::<*T>();
63-
let ptr: uint = unsafe::reinterpret_cast(&ptr);
63+
let ptr: uint = cast::reinterpret_cast(&ptr);
6464
let ptr = (ptr + (align - 1)) & -align;
65-
return unsafe::reinterpret_cast(&ptr);
65+
return cast::reinterpret_cast(&ptr);
6666
}
6767

6868
unsafe fn get_safe_point_count() -> uint {
@@ -101,8 +101,8 @@ type Visitor = fn(root: **Word, tydesc: *Word) -> bool;
101101
// Walks the list of roots for the given safe point, and calls visitor
102102
// on each root.
103103
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
104-
let fp_bytes: *u8 = unsafe::reinterpret_cast(&fp);
105-
let sp_meta: *u32 = unsafe::reinterpret_cast(&sp.sp_meta);
104+
let fp_bytes: *u8 = cast::reinterpret_cast(&fp);
105+
let sp_meta: *u32 = cast::reinterpret_cast(&sp.sp_meta);
106106

107107
let num_stack_roots = *sp_meta as uint;
108108
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
@@ -143,9 +143,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
143143

144144
// Is fp contained in segment?
145145
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
146-
let begin: Word = unsafe::reinterpret_cast(&segment);
147-
let end: Word = unsafe::reinterpret_cast(&(*segment).end);
148-
let frame: Word = unsafe::reinterpret_cast(&fp);
146+
let begin: Word = cast::reinterpret_cast(&segment);
147+
let end: Word = cast::reinterpret_cast(&(*segment).end);
148+
let frame: Word = cast::reinterpret_cast(&fp);
149149

150150
return begin <= frame && frame <= end;
151151
}
@@ -315,7 +315,7 @@ fn cleanup_stack_for_failure() {
315315
// own stack roots on the stack anyway.
316316
let sentinel_box = ~0;
317317
let sentinel: **Word = if expect_sentinel() {
318-
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box))
318+
cast::reinterpret_cast(&ptr::addr_of(sentinel_box))
319319
} else {
320320
ptr::null()
321321
};

src/libcore/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str {
721721
vec::push(v, 0);
722722
assert str::is_utf8(v);
723723
724-
unsafe { move ::unsafe::transmute(v) }
724+
unsafe { move ::cast::transmute(v) }
725725
}
726726
727727
// Utility functions

src/libcore/mutable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mutation when the data structure should be immutable.
1313
#[forbid(deprecated_pattern)];
1414

1515
use util::with;
16-
use unsafe::transmute_immut;
16+
use cast::transmute_immut;
1717

1818
export Mut;
1919

src/libcore/os.rs

Lines changed: 2 additions & 2 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>() == cast::reinterpret_cast(&s) {
226226
option::None::<~str>
227227
} else {
228-
let s = unsafe::reinterpret_cast(&s);
228+
let s = cast::reinterpret_cast(&s);
229229
option::Some::<~str>(str::raw::from_buf(s))
230230
};
231231
}

src/libcore/pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bounded and unbounded protocols allows for less code duplication.
7777
#[forbid(deprecated_pattern)];
7878

7979
use cmp::Eq;
80-
use unsafe::{forget, reinterpret_cast, transmute};
80+
use cast::{forget, reinterpret_cast, transmute};
8181
use either::{Either, Left, Right};
8282
use option::unwrap;
8383

src/libcore/private.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ unsafe fn chan_from_global_ptr<T: Send>(
8989
// Install the channel
9090
log(debug,~"BEFORE COMPARE AND SWAP");
9191
let swapped = compare_and_swap(
92-
unsafe::reinterpret_cast(&global),
93-
0u, unsafe::reinterpret_cast(&ch));
92+
cast::reinterpret_cast(&global),
93+
0u, cast::reinterpret_cast(&ch));
9494
log(debug,fmt!("AFTER .. swapped? %?", swapped));
9595

9696
if swapped {
@@ -100,11 +100,11 @@ unsafe fn chan_from_global_ptr<T: Send>(
100100
} else {
101101
// Somebody else got in before we did
102102
comm::send(setup_ch, Abort);
103-
unsafe::reinterpret_cast(&*global)
103+
cast::reinterpret_cast(&*global)
104104
}
105105
} else {
106106
log(debug, ~"global != 0");
107-
unsafe::reinterpret_cast(&*global)
107+
cast::reinterpret_cast(&*global)
108108
}
109109
}
110110

@@ -211,15 +211,15 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
211211
let po = comm::Port();
212212
let ch = comm::Chan(po);
213213
unsafe {
214-
rustrt::rust_task_weaken(unsafe::reinterpret_cast(&ch));
214+
rustrt::rust_task_weaken(cast::reinterpret_cast(&ch));
215215
}
216216
let _unweaken = Unweaken(ch);
217217
f(po);
218218

219219
struct Unweaken {
220220
ch: comm::Chan<()>,
221221
drop unsafe {
222-
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch));
222+
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
223223
}
224224
}
225225

@@ -309,7 +309,7 @@ struct ArcDestruct<T> {
309309
return; // Happens when destructing an unwrapper's handle.
310310
}
311311
do task::unkillable {
312-
let data: ~ArcData<T> = unsafe::reinterpret_cast(&self.data);
312+
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
313313
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
314314
assert new_count >= 0;
315315
if new_count == 0 {
@@ -319,22 +319,22 @@ struct ArcDestruct<T> {
319319
// being here means we're the only *awake* task with the data.
320320
if data.unwrapper != 0 {
321321
let p: UnwrapProto =
322-
unsafe::reinterpret_cast(&data.unwrapper);
322+
cast::reinterpret_cast(&data.unwrapper);
323323
let (message, response) = option::swap_unwrap(p);
324324
// Send 'ready' and wait for a response.
325325
pipes::send_one(move message, ());
326326
// Unkillable wait. Message guaranteed to come.
327327
if pipes::recv_one(move response) {
328328
// Other task got the data.
329-
unsafe::forget(move data);
329+
cast::forget(move data);
330330
} else {
331331
// Other task was killed. drop glue takes over.
332332
}
333333
} else {
334334
// drop glue takes over.
335335
}
336336
} else {
337-
unsafe::forget(move data);
337+
cast::forget(move data);
338338
}
339339
}
340340
}
@@ -359,7 +359,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
359359
pipes::send_one(move response, false);
360360
// Either this swap_unwrap or the one below (at "Got here")
361361
// ought to run.
362-
unsafe::forget(option::swap_unwrap(&mut self.ptr));
362+
cast::forget(option::swap_unwrap(&mut self.ptr));
363363
} else {
364364
assert self.ptr.is_none();
365365
pipes::send_one(move response, true);
@@ -368,11 +368,11 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
368368
}
369369

370370
do task::unkillable {
371-
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&rc.data);
371+
let ptr: ~ArcData<T> = cast::reinterpret_cast(&rc.data);
372372
let (c1,p1) = pipes::oneshot(); // ()
373373
let (c2,p2) = pipes::oneshot(); // bool
374374
let server: UnwrapProto = ~mut Some((move c1,move p2));
375-
let serverp: libc::uintptr_t = unsafe::transmute(move server);
375+
let serverp: libc::uintptr_t = cast::transmute(move server);
376376
// Try to put our server end in the unwrapper slot.
377377
if rustrt::rust_compare_and_swap_ptr(&mut ptr.unwrapper, 0, serverp) {
378378
// Got in. Step 0: Tell destructor not to run. We are now it.
@@ -383,7 +383,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
383383
if new_count == 0 {
384384
// We were the last owner. Can unwrap immediately.
385385
// Also we have to free the server endpoints.
386-
let _server: UnwrapProto = unsafe::transmute(move serverp);
386+
let _server: UnwrapProto = cast::transmute(move serverp);
387387
option::swap_unwrap(&mut ptr.data)
388388
// drop glue takes over.
389389
} else {
@@ -403,9 +403,9 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
403403
}
404404
} else {
405405
// Somebody else was trying to unwrap. Avoid guaranteed deadlock.
406-
unsafe::forget(move ptr);
406+
cast::forget(move ptr);
407407
// Also we have to free the (rejected) server endpoints.
408-
let _server: UnwrapProto = unsafe::transmute(move serverp);
408+
let _server: UnwrapProto = cast::transmute(move serverp);
409409
fail ~"Another task is already unwrapping this ARC!";
410410
}
411411
}
@@ -422,7 +422,7 @@ type SharedMutableState<T: Send> = ArcDestruct<T>;
422422
unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> {
423423
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) };
424424
unsafe {
425-
let ptr = unsafe::transmute(move data);
425+
let ptr = cast::transmute(move data);
426426
ArcDestruct(ptr)
427427
}
428428
}
@@ -431,34 +431,34 @@ unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> {
431431
unsafe fn get_shared_mutable_state<T: Send>(rc: &a/SharedMutableState<T>)
432432
-> &a/mut T {
433433
unsafe {
434-
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
434+
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
435435
assert ptr.count > 0;
436436
// Cast us back into the correct region
437-
let r = unsafe::transmute_region(option::get_ref(&ptr.data));
438-
unsafe::forget(move ptr);
439-
return unsafe::transmute_mut(r);
437+
let r = cast::transmute_region(option::get_ref(&ptr.data));
438+
cast::forget(move ptr);
439+
return cast::transmute_mut(r);
440440
}
441441
}
442442
#[inline(always)]
443443
unsafe fn get_shared_immutable_state<T: Send>(rc: &a/SharedMutableState<T>)
444444
-> &a/T {
445445
unsafe {
446-
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
446+
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
447447
assert ptr.count > 0;
448448
// Cast us back into the correct region
449-
let r = unsafe::transmute_region(option::get_ref(&ptr.data));
450-
unsafe::forget(move ptr);
449+
let r = cast::transmute_region(option::get_ref(&ptr.data));
450+
cast::forget(move ptr);
451451
return r;
452452
}
453453
}
454454

455455
unsafe fn clone_shared_mutable_state<T: Send>(rc: &SharedMutableState<T>)
456456
-> SharedMutableState<T> {
457457
unsafe {
458-
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
458+
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
459459
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
460460
assert new_count >= 2;
461-
unsafe::forget(move ptr);
461+
cast::forget(move ptr);
462462
}
463463
ArcDestruct((*rc).data)
464464
}
@@ -543,7 +543,7 @@ impl<T: Send> Exclusive<T> {
543543
#[inline(always)]
544544
unsafe fn with_imm<U>(f: fn(x: &T) -> U) -> U {
545545
do self.with |x| {
546-
f(unsafe::transmute_immut(x))
546+
f(cast::transmute_immut(x))
547547
}
548548
}
549549
}

0 commit comments

Comments
 (0)