test: Fix tests.
This commit is contained in:
parent
f30f54e9d0
commit
876483dcf4
31 changed files with 114 additions and 190 deletions
|
|
@ -178,8 +178,8 @@ mod tests {
|
|||
let box = @~"box box box"; // refcount 1
|
||||
bump_box_refcount(box); // refcount 2
|
||||
let ptr: *int = transmute(box); // refcount 2
|
||||
let _box1: @~str = reinterpret_cast(&ptr);
|
||||
let _box2: @~str = reinterpret_cast(&ptr);
|
||||
let _box1: @~str = ::cast::transmute_copy(&ptr);
|
||||
let _box2: @~str = ::cast::transmute_copy(&ptr);
|
||||
assert!(*_box1 == ~"box box box");
|
||||
assert!(*_box2 == ~"box box box");
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
|
|
|
|||
|
|
@ -482,10 +482,10 @@ pub impl<T:Copy + Zero> Option<T> {
|
|||
fn test_unwrap_ptr() {
|
||||
unsafe {
|
||||
let x = ~0;
|
||||
let addr_x: *int = transmute(&*x);
|
||||
let addr_x: *int = ::cast::transmute(&*x);
|
||||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
let addr_y: *int = transmute(&*y);
|
||||
let addr_y: *int = ::cast::transmute(&*y);
|
||||
assert!(addr_x == addr_y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ pub struct Thread {
|
|||
|
||||
pub impl Thread {
|
||||
fn start(main: ~fn()) -> Thread {
|
||||
fn substart(main: &fn()) -> *raw_thread {
|
||||
unsafe { rust_raw_thread_start(&main) }
|
||||
fn substart(main: &~fn()) -> *raw_thread {
|
||||
unsafe { rust_raw_thread_start(main) }
|
||||
}
|
||||
let raw = substart(main);
|
||||
let raw = substart(&main);
|
||||
Thread {
|
||||
main: main,
|
||||
raw_thread: raw
|
||||
|
|
@ -39,6 +39,6 @@ impl Drop for Thread {
|
|||
}
|
||||
|
||||
extern {
|
||||
pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
|
||||
pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
|
||||
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -366,14 +366,15 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
|
|||
|
||||
/// Transmute an owned vector to a Buf
|
||||
pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
|
||||
let data = unsafe { malloc(v.len() as size_t) } as *u8;
|
||||
assert!(data.is_not_null());
|
||||
do vec::as_imm_buf(v) |b, l| {
|
||||
let data = data as *mut u8;
|
||||
unsafe { ptr::copy_memory(data, b, l) }
|
||||
unsafe {
|
||||
let data = malloc(v.len() as size_t) as *u8;
|
||||
assert!(data.is_not_null());
|
||||
do vec::as_imm_buf(v) |b, l| {
|
||||
let data = data as *mut u8;
|
||||
ptr::copy_memory(data, b, l)
|
||||
}
|
||||
uvll::buf_init(data, v.len())
|
||||
}
|
||||
let buf = unsafe { uvll::buf_init(data, v.len()) };
|
||||
return buf;
|
||||
}
|
||||
|
||||
/// Transmute a Buf that was once a ~[u8] back to ~[u8]
|
||||
|
|
@ -384,6 +385,7 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
|
|||
return Some(v);
|
||||
} else {
|
||||
// No buffer
|
||||
rtdebug!("No buffer!");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ pub fn pref_align_of_val<T>(_val: &T) -> uint {
|
|||
#[inline(always)]
|
||||
pub fn refcount<T>(t: @T) -> uint {
|
||||
unsafe {
|
||||
let ref_ptr: *uint = cast::transmute(t);
|
||||
let ref_ptr: *uint = cast::transmute_copy(&t);
|
||||
*ref_ptr - 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue