about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-04-20 01:00:49 -0700
committerbors <bors@rust-lang.org>2013-04-20 01:00:49 -0700
commit4ff701b7db609cabe59832d47779832a16627b5f (patch)
tree49317e2439d493b798412dad2c92b60e366f229f /src/libstd
parent028dc589d1cfb7e44b36b978ea1dcc304d70cee0 (diff)
parentcd982ad3f74673c55af6034a4f757e60be9b381c (diff)
downloadrust-4ff701b7db609cabe59832d47779832a16627b5f.tar.gz
rust-4ff701b7db609cabe59832d47779832a16627b5f.zip
auto merge of #5965 : alexcrichton/rust/issue-4364, r=pcwalton
This closes #4364. I came into rust after modes had begun to be phased out, so I'm not exactly sure what they all did. My strategy was basically to turn on the compilation warnings and then when everything compiles and passes all the tests it's all good.

In most cases, I just dropped the mode, but in others I converted things to use `&` pointers when otherwise a move would happen.

This depends on #5963. When running the tests, everything passed except for a few compile-fail tests. These tests leaked memory, causing the task to abort differently. By suppressing the ICE from #5963, no leaks happen and the tests all pass. I would have looked into where the leaks were coming from, but I wasn't sure where or how to debug them (I found `RUSTRT_TRACK_ALLOCATIONS`, but it wasn't all that useful).
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_vec.rs6
-rw-r--r--src/libstd/rope.rs22
-rw-r--r--src/libstd/uv_iotask.rs114
-rw-r--r--src/libstd/uv_ll.rs106
4 files changed, 116 insertions, 132 deletions
diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs
index a59c76c809b..dd85e886b1e 100644
--- a/src/libstd/c_vec.rs
+++ b/src/libstd/c_vec.rs
@@ -159,8 +159,8 @@ mod tests {
 
             assert!(mem as int != 0);
 
-            return unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
-                                         || unsafe { free(mem) }) };
+            return c_vec_with_dtor(mem as *mut u8, n as uint,
+                                   || unsafe { free(mem) });
         }
     }
 
@@ -196,7 +196,7 @@ mod tests {
     #[test]
     fn test_and_I_mean_it() {
         let cv = malloc(16u as size_t);
-        let p = unsafe { ptr(cv) };
+        let p = ptr(cv);
 
         set(cv, 0u, 32u8);
         set(cv, 1u, 33u8);
diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs
index 653283f2e78..890712a9708 100644
--- a/src/libstd/rope.rs
+++ b/src/libstd/rope.rs
@@ -1287,18 +1287,16 @@ mod tests {
           node::Content(x) => {
             let str = @mut ~"";
             fn aux(str: @mut ~str, node: @node::Node) {
-                unsafe {
-                    match (*node) {
-                      node::Leaf(x) => {
-                        *str += str::slice(
-                            *x.content, x.byte_offset,
-                            x.byte_offset + x.byte_len).to_owned();
-                      }
-                      node::Concat(ref x) => {
-                        aux(str, x.left);
-                        aux(str, x.right);
-                      }
-                    }
+                match (*node) {
+                  node::Leaf(x) => {
+                    *str += str::slice(
+                        *x.content, x.byte_offset,
+                        x.byte_offset + x.byte_len).to_owned();
+                  }
+                  node::Concat(ref x) => {
+                    aux(str, x.left);
+                    aux(str, x.right);
+                  }
                 }
             }
             aux(str, x);
diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs
index c7a78f38919..7e1c9d858ce 100644
--- a/src/libstd/uv_iotask.rs
+++ b/src/libstd/uv_iotask.rs
@@ -224,36 +224,32 @@ struct AhData {
 
 #[cfg(test)]
 fn impl_uv_iotask_async(iotask: &IoTask) {
-    unsafe {
-        let async_handle = ll::async_t();
-        let ah_ptr = ptr::addr_of(&async_handle);
-        let (exit_po, exit_ch) = stream::<()>();
-        let ah_data = AhData {
-            iotask: iotask.clone(),
-            exit_ch: SharedChan::new(exit_ch)
-        };
-        let ah_data_ptr: *AhData = unsafe {
-            ptr::to_unsafe_ptr(&ah_data)
-        };
-        debug!("about to interact");
-        do interact(iotask) |loop_ptr| {
-            unsafe {
-                debug!("interacting");
-                ll::async_init(loop_ptr, ah_ptr, async_handle_cb);
-                ll::set_data_for_uv_handle(
-                    ah_ptr, ah_data_ptr as *libc::c_void);
-                ll::async_send(ah_ptr);
-            }
-        };
-        debug!("waiting for async close");
-        exit_po.recv();
-    }
+    let async_handle = ll::async_t();
+    let ah_ptr = ptr::addr_of(&async_handle);
+    let (exit_po, exit_ch) = stream::<()>();
+    let ah_data = AhData {
+        iotask: iotask.clone(),
+        exit_ch: SharedChan::new(exit_ch)
+    };
+    let ah_data_ptr: *AhData = ptr::to_unsafe_ptr(&ah_data);
+    debug!("about to interact");
+    do interact(iotask) |loop_ptr| {
+        unsafe {
+            debug!("interacting");
+            ll::async_init(loop_ptr, ah_ptr, async_handle_cb);
+            ll::set_data_for_uv_handle(
+                ah_ptr, ah_data_ptr as *libc::c_void);
+            ll::async_send(ah_ptr);
+        }
+    };
+    debug!("waiting for async close");
+    exit_po.recv();
 }
 
 // this fn documents the bear minimum neccesary to roll your own
 // high_level_loop
 #[cfg(test)]
-unsafe fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask {
+fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask {
     let (iotask_port, iotask_ch) = stream::<IoTask>();
     do task::spawn_sched(task::ManualThreads(1u)) {
         debug!("about to run a test loop");
@@ -265,9 +261,7 @@ unsafe fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask {
 
 #[cfg(test)]
 extern fn lifetime_handle_close(handle: *libc::c_void) {
-    unsafe {
-        debug!("lifetime_handle_close ptr %?", handle);
-    }
+    debug!("lifetime_handle_close ptr %?", handle);
 }
 
 #[cfg(test)]
@@ -279,38 +273,36 @@ extern fn lifetime_async_callback(handle: *libc::c_void,
 
 #[test]
 fn test_uv_iotask_async() {
-    unsafe {
-        let (exit_po, exit_ch) = stream::<()>();
-        let iotask = &spawn_test_loop(~exit_ch);
-
-        debug!("spawned iotask");
-
-        // using this handle to manage the lifetime of the
-        // high_level_loop, as it will exit the first time one of
-        // the impl_uv_hl_async() is cleaned up with no one ref'd
-        // handles on the loop (Which can happen under
-        // race-condition type situations.. this ensures that the
-        // loop lives until, at least, all of the
-        // impl_uv_hl_async() runs have been called, at least.
-        let (work_exit_po, work_exit_ch) = stream::<()>();
-        let work_exit_ch = SharedChan::new(work_exit_ch);
-        for iter::repeat(7u) {
-            let iotask_clone = iotask.clone();
-            let work_exit_ch_clone = work_exit_ch.clone();
-            do task::spawn_sched(task::ManualThreads(1u)) {
-                debug!("async");
-                impl_uv_iotask_async(&iotask_clone);
-                debug!("done async");
-                work_exit_ch_clone.send(());
-            };
+    let (exit_po, exit_ch) = stream::<()>();
+    let iotask = &spawn_test_loop(~exit_ch);
+
+    debug!("spawned iotask");
+
+    // using this handle to manage the lifetime of the
+    // high_level_loop, as it will exit the first time one of
+    // the impl_uv_hl_async() is cleaned up with no one ref'd
+    // handles on the loop (Which can happen under
+    // race-condition type situations.. this ensures that the
+    // loop lives until, at least, all of the
+    // impl_uv_hl_async() runs have been called, at least.
+    let (work_exit_po, work_exit_ch) = stream::<()>();
+    let work_exit_ch = SharedChan::new(work_exit_ch);
+    for iter::repeat(7u) {
+        let iotask_clone = iotask.clone();
+        let work_exit_ch_clone = work_exit_ch.clone();
+        do task::spawn_sched(task::ManualThreads(1u)) {
+            debug!("async");
+            impl_uv_iotask_async(&iotask_clone);
+            debug!("done async");
+            work_exit_ch_clone.send(());
         };
-        for iter::repeat(7u) {
-            debug!("waiting");
-            work_exit_po.recv();
-        };
-        debug!(~"sending teardown_loop msg..");
-        exit(iotask);
-        exit_po.recv();
-        debug!(~"after recv on exit_po.. exiting..");
-    }
+    };
+    for iter::repeat(7u) {
+        debug!("waiting");
+        work_exit_po.recv();
+    };
+    debug!(~"sending teardown_loop msg..");
+    exit(iotask);
+    exit_po.recv();
+    debug!(~"after recv on exit_po.. exiting..");
 }
diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs
index 98d76c6b9aa..a5c53100400 100644
--- a/src/libstd/uv_ll.rs
+++ b/src/libstd/uv_ll.rs
@@ -1422,10 +1422,8 @@ mod test {
     }
 
     extern fn server_after_close_cb(handle: *libc::c_void) {
-        unsafe {
-            debug!("SERVER server stream closed, should exit. h: %?",
-                       handle);
-        }
+        debug!("SERVER server stream closed, should exit. h: %?",
+                   handle);
     }
 
     extern fn client_stream_after_close_cb(handle: *libc::c_void) {
@@ -1709,48 +1707,46 @@ mod test {
     // this is the impl for a test that is (maybe) ran on a
     // per-platform/arch basis below
     pub fn impl_uv_tcp_server_and_request() {
-        unsafe {
-            let bind_ip = ~"0.0.0.0";
-            let request_ip = ~"127.0.0.1";
-            let port = 8886;
-            let kill_server_msg = ~"does a dog have buddha nature?";
-            let server_resp_msg = ~"mu!";
-            let (client_port, client_chan) = stream::<~str>();
-            let client_chan = SharedChan::new(client_chan);
-            let (server_port, server_chan) = stream::<~str>();
-            let server_chan = SharedChan::new(server_chan);
-
-            let (continue_port, continue_chan) = stream::<bool>();
-            let continue_chan = SharedChan::new(continue_chan);
-
-            let kill_server_msg_copy = copy kill_server_msg;
-            let server_resp_msg_copy = copy server_resp_msg;
-            do task::spawn_sched(task::ManualThreads(1)) {
-                impl_uv_tcp_server(bind_ip, port,
-                                   copy kill_server_msg_copy,
-                                   copy server_resp_msg_copy,
-                                   server_chan.clone(),
-                                   continue_chan.clone());
-            };
-
-            // block until the server up is.. possibly a race?
-            debug!(~"before receiving on server continue_port");
-            continue_port.recv();
-            debug!(~"received on continue port, set up tcp client");
-
-            let kill_server_msg_copy = copy kill_server_msg;
-            do task::spawn_sched(task::ManualThreads(1u)) {
-                impl_uv_tcp_request(request_ip, port,
-                                   kill_server_msg_copy,
-                                   client_chan.clone());
-            };
-
-            let msg_from_client = server_port.recv();
-            let msg_from_server = client_port.recv();
-
-            assert!(str::contains(msg_from_client, kill_server_msg));
-            assert!(str::contains(msg_from_server, server_resp_msg));
-        }
+        let bind_ip = ~"0.0.0.0";
+        let request_ip = ~"127.0.0.1";
+        let port = 8886;
+        let kill_server_msg = ~"does a dog have buddha nature?";
+        let server_resp_msg = ~"mu!";
+        let (client_port, client_chan) = stream::<~str>();
+        let client_chan = SharedChan::new(client_chan);
+        let (server_port, server_chan) = stream::<~str>();
+        let server_chan = SharedChan::new(server_chan);
+
+        let (continue_port, continue_chan) = stream::<bool>();
+        let continue_chan = SharedChan::new(continue_chan);
+
+        let kill_server_msg_copy = copy kill_server_msg;
+        let server_resp_msg_copy = copy server_resp_msg;
+        do task::spawn_sched(task::ManualThreads(1)) {
+            impl_uv_tcp_server(bind_ip, port,
+                               copy kill_server_msg_copy,
+                               copy server_resp_msg_copy,
+                               server_chan.clone(),
+                               continue_chan.clone());
+        };
+
+        // block until the server up is.. possibly a race?
+        debug!(~"before receiving on server continue_port");
+        continue_port.recv();
+        debug!(~"received on continue port, set up tcp client");
+
+        let kill_server_msg_copy = copy kill_server_msg;
+        do task::spawn_sched(task::ManualThreads(1u)) {
+            impl_uv_tcp_request(request_ip, port,
+                               kill_server_msg_copy,
+                               client_chan.clone());
+        };
+
+        let msg_from_client = server_port.recv();
+        let msg_from_server = client_port.recv();
+
+        assert!(str::contains(msg_from_client, kill_server_msg));
+        assert!(str::contains(msg_from_server, server_resp_msg));
     }
 
     // FIXME don't run on fbsd or linux 32 bit(#2064)
@@ -1784,17 +1780,15 @@ mod test {
 
     fn struct_size_check_common<TStruct>(t_name: ~str,
                                          foreign_size: libc::c_uint) {
-        unsafe {
-            let rust_size = sys::size_of::<TStruct>();
-            let sizes_match = foreign_size as uint == rust_size;
-            if !sizes_match {
-                let output = fmt!(
-                    "STRUCT_SIZE FAILURE: %s -- actual: %u expected: %u",
-                    t_name, rust_size, foreign_size as uint);
-                debug!(output);
-            }
-            assert!(sizes_match);
+        let rust_size = sys::size_of::<TStruct>();
+        let sizes_match = foreign_size as uint == rust_size;
+        if !sizes_match {
+            let output = fmt!(
+                "STRUCT_SIZE FAILURE: %s -- actual: %u expected: %u",
+                t_name, rust_size, foreign_size as uint);
+            debug!(output);
         }
+        assert!(sizes_match);
     }
 
     // struct size tests