Skip to content

Commit

Permalink
test: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Apr 29, 2013
1 parent f30f54e commit 876483d
Show file tree
Hide file tree
Showing 31 changed files with 114 additions and 190 deletions.
4 changes: 2 additions & 2 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/rt/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
16 changes: 9 additions & 7 deletions src/libcore/rt/uv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,16 @@ pub fn trans_intrinsic(ccx: @CrateContext,
_ => fail!(~"transmute has non-expr arg"),
};
let pluralize = |n| if 1u == n { "" } else { "s" };
ccx.sess.span_err(sp,
fmt!("transmute called on types with \
different sizes: %s (%u bit%s) to \
%s (%u bit%s)",
ty_to_str(ccx.tcx, in_type),
in_type_size,
pluralize(in_type_size),
ty_to_str(ccx.tcx, out_type),
out_type_size,
pluralize(out_type_size)));
ccx.sess.span_fatal(sp,
fmt!("transmute called on types with \
different sizes: %s (%u bit%s) to \
%s (%u bit%s)",
ty_to_str(ccx.tcx, in_type),
in_type_size,
pluralize(in_type_size),
ty_to_str(ccx.tcx, out_type),
out_type_size,
pluralize(out_type_size)));
}

if !ty::type_is_nil(out_type) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3467,11 +3467,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int(tcx))),
ty::mk_int())),
arg(ty::mk_int()),
arg(ty::mk_int())
],
ty::mk_int(tcx))
ty::mk_int())
}
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
Expand All @@ -3480,7 +3480,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int(tcx))),
ty::mk_int())),
arg(ty::mk_int())
],
ty::mk_int())
Expand Down Expand Up @@ -3550,7 +3550,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
})),
arg(ty::mk_u64())
],
ty::mk_nil(tcx))
ty::mk_nil())
}
~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
Expand Down
44 changes: 26 additions & 18 deletions src/libstd/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,18 +828,22 @@ mod tests {
let m = ~Mutex();
let m2 = m.clone();
let mut sharedstate = ~0;
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };
access_shared(sharedstate, m2, 10);
c.send(());
{
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };
access_shared(sharedstate, m2, 10);
c.send(());

}
}
access_shared(sharedstate, m, 10);
let _ = p.recv();
{
access_shared(sharedstate, m, 10);
let _ = p.recv();

assert!(*sharedstate == 20);
assert!(*sharedstate == 20);
}

fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) {
for n.times {
Expand Down Expand Up @@ -1106,17 +1110,21 @@ mod tests {
let (p,c) = comm::stream();
let x2 = (*x).clone();
let mut sharedstate = ~0;
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };
access_shared(sharedstate, &x2, mode1, 10);
c.send(());
{
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };
access_shared(sharedstate, &x2, mode1, 10);
c.send(());
}
}
access_shared(sharedstate, x, mode2, 10);
let _ = p.recv();
{
access_shared(sharedstate, x, mode2, 10);
let _ = p.recv();

assert!(*sharedstate == 20);
assert!(*sharedstate == 20);
}

fn access_shared(sharedstate: &mut int, x: &RWlock, mode: RWlockMode,
n: uint) {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,9 +1396,9 @@ mod test {
// not set the data on the connect_req
// until its initialized
set_data_for_req(connect_req_ptr as *libc::c_void,
transmute(&client_data));
&client_data);
set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void,
transmute(&client_data));
&client_data);
debug!(~"before run tcp req loop");
run(test_loop);
debug!(~"after run tcp req loop");
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/pipes/pipec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ impl gen_init for protocol {
|s| ext_cx.parse_stmt(
fmt!("data.%s.set_buffer(buffer)",
s.name))),
ext_cx.parse_expr(fmt!("&(data.%s)", self.states[0].name))));
ext_cx.parse_expr(fmt!(
"::core::ptr::to_unsafe_ptr(&(data.%s))",
self.states[0].name))));

quote_expr!({
let buffer = $buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/llvm
8 changes: 4 additions & 4 deletions src/test/bench/graph500-bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
}

/// A parallel version of the bfs function.
fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
// This works by doing functional updates of a color vector.

enum color {
Expand All @@ -236,7 +236,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
black(node_id)
};

let graph_vec = arc::get(&graph); // FIXME #3387 requires this temp
let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
if i as node_id == key {
gray(key)
Expand Down Expand Up @@ -271,7 +271,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
let color_vec = arc::get(&color); // FIXME #3387 requires this temp
colors = do par::mapi(*color_vec) {
let colors = arc::clone(&color);
let graph = arc::clone(&graph);
let graph = arc::clone(graph);
let result: ~fn(+x: uint, +y: &color) -> color = |i, c| {
let colors = arc::get(&colors);
let graph = arc::get(&graph);
Expand Down Expand Up @@ -496,7 +496,7 @@ fn main() {
}

let start = time::precise_time_s();
let bfs_tree = pbfs(graph_arc, *root);
let bfs_tree = pbfs(&graph_arc, *root);
let stop = time::precise_time_s();

total_par += stop - start;
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/msgsend-pipes-shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum request {
stop
}

fn server(requests: Port<request>, responses: comm::Chan<uint>) {
fn server(requests: &Port<request>, responses: &comm::Chan<uint>) {
let mut count = 0u;
let mut done = false;
while !done {
Expand Down Expand Up @@ -76,7 +76,7 @@ fn run(args: &[~str]) {
};
}
do task::spawn || {
server(from_parent, to_parent);
server(&from_parent, &to_parent);
}

for vec::each(worker_results) |r| {
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/msgsend-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum request {
stop
}

fn server(requests: PortSet<request>, responses: Chan<uint>) {
fn server(requests: &PortSet<request>, responses: &Chan<uint>) {
let mut count = 0;
let mut done = false;
while !done {
Expand Down Expand Up @@ -73,7 +73,7 @@ fn run(args: &[~str]) {
};
}
do task::spawn || {
server(from_parent, to_parent);
server(&from_parent, &to_parent);
}

for vec::each(worker_results) |r| {
Expand Down
8 changes: 4 additions & 4 deletions src/test/bench/shootout-k-nucleotide-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ fn windows_with_carry(bb: &[u8], nn: uint,
}

fn make_sequence_processor(sz: uint,
from_parent: comm::Port<~[u8]>,
to_parent: comm::Chan<~str>) {
from_parent: &comm::Port<~[u8]>,
to_parent: &comm::Chan<~str>) {
let mut freqs: HashMap<~[u8], uint> = HashMap::new();
let mut carry: ~[u8] = ~[];
let mut total: uint = 0u;
Expand Down Expand Up @@ -140,7 +140,7 @@ fn make_sequence_processor(sz: uint,
// given a FASTA file on stdin, process sequence THREE
fn main() {
let args = os::args();
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
// FIXME: Using this compile-time env variable is a crummy way to
// get to this massive data set, but include_bin! chokes on it (#2598)
let path = Path(env!("CFG_SRC_DIR"))
Expand Down Expand Up @@ -168,7 +168,7 @@ fn main() {
let (from_parent, to_child) = comm::stream();

do task::spawn_with(from_parent) |from_parent| {
make_sequence_processor(sz, from_parent, to_parent_);
make_sequence_processor(sz, &from_parent, &to_parent_);
};

to_child
Expand Down
8 changes: 4 additions & 4 deletions src/test/bench/shootout-pfib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ use core::result;
use core::result::{Ok, Err};

fn fib(n: int) -> int {
fn pfib(c: Chan<int>, n: int) {
fn pfib(c: &Chan<int>, n: int) {
if n == 0 {
c.send(0);
} else if n <= 2 {
c.send(1);
} else {
let p = PortSet::new();
let ch = p.chan();
task::spawn(|| pfib(ch, n - 1) );
task::spawn(|| pfib(&ch, n - 1) );
let ch = p.chan();
task::spawn(|| pfib(ch, n - 2) );
task::spawn(|| pfib(&ch, n - 2) );
c.send(p.recv() + p.recv());
}
}

let (p, ch) = stream();
let _t = task::spawn(|| pfib(ch, n) );
let _t = task::spawn(|| pfib(&ch, n) );
p.recv()
}

Expand Down
15 changes: 0 additions & 15 deletions src/test/compile-fail/arg-style-mismatch.rs

This file was deleted.

Loading

0 comments on commit 876483d

Please sign in to comment.