about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-11-07 20:13:25 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-11-10 01:37:12 -0800
commit86a321b65dcc5253f61202b2fdaac41f275344ce (patch)
treee6dd37093bbab2dad2ae7f2f6175b44bb53d9adb /src/libstd/rt
parent3a3eefc5c3ce95de3001d8ee830296345c2f6bc9 (diff)
downloadrust-86a321b65dcc5253f61202b2fdaac41f275344ce.tar.gz
rust-86a321b65dcc5253f61202b2fdaac41f275344ce.zip
Another round of test fixes from previous commits
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/io/mod.rs6
-rw-r--r--src/libstd/rt/io/native/file.rs16
-rw-r--r--src/libstd/rt/io/native/process.rs6
-rw-r--r--src/libstd/rt/io/native/stdio.rs8
-rw-r--r--src/libstd/rt/io/timer.rs6
-rw-r--r--src/libstd/rt/macros.rs5
6 files changed, 23 insertions, 24 deletions
diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs
index e8ab4670233..ce9504a5b43 100644
--- a/src/libstd/rt/io/mod.rs
+++ b/src/libstd/rt/io/mod.rs
@@ -423,7 +423,11 @@ pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
 /// closure if no error occurred.
 pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
     let mut err = None;
-    let ret = io_error::cond.trap(|e| err = Some(e)).inside(cb);
+    let ret = io_error::cond.trap(|e| {
+        if err.is_none() {
+            err = Some(e);
+        }
+    }).inside(cb);
     match err {
         Some(e) => Err(e),
         None => Ok(ret),
diff --git a/src/libstd/rt/io/native/file.rs b/src/libstd/rt/io/native/file.rs
index 35057f475cf..6d4f29182dd 100644
--- a/src/libstd/rt/io/native/file.rs
+++ b/src/libstd/rt/io/native/file.rs
@@ -80,18 +80,20 @@ pub type fd_t = libc::c_int;
 
 pub struct FileDesc {
     priv fd: fd_t,
+    priv close_on_drop: bool,
 }
 
 impl FileDesc {
     /// Create a `FileDesc` from an open C file descriptor.
     ///
     /// The `FileDesc` will take ownership of the specified file descriptor and
-    /// close it upon destruction.
+    /// close it upon destruction if the `close_on_drop` flag is true, otherwise
+    /// it will not close the file descriptor when this `FileDesc` is dropped.
     ///
     /// Note that all I/O operations done on this object will be *blocking*, but
     /// they do not require the runtime to be active.
-    pub fn new(fd: fd_t) -> FileDesc {
-        FileDesc { fd: fd }
+    pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc {
+        FileDesc { fd: fd, close_on_drop: close_on_drop }
     }
 }
 
@@ -137,7 +139,9 @@ impl Writer for FileDesc {
 impl Drop for FileDesc {
     #[fixed_stack_segment] #[inline(never)]
     fn drop(&mut self) {
-        unsafe { libc::close(self.fd); }
+        if self.close_on_drop {
+            unsafe { libc::close(self.fd); }
+        }
     }
 }
 
@@ -245,8 +249,8 @@ mod tests {
         // opening or closing files.
         unsafe {
             let os::Pipe { input, out } = os::pipe();
-            let mut reader = FileDesc::new(input);
-            let mut writer = FileDesc::new(out);
+            let mut reader = FileDesc::new(input, true);
+            let mut writer = FileDesc::new(out, true);
 
             writer.write(bytes!("test"));
             let mut buf = [0u8, ..4];
diff --git a/src/libstd/rt/io/native/process.rs b/src/libstd/rt/io/native/process.rs
index 0fa454b94d0..f5c39de1bf4 100644
--- a/src/libstd/rt/io/native/process.rs
+++ b/src/libstd/rt/io/native/process.rs
@@ -105,9 +105,9 @@ impl Process {
         Process {
             pid: res.pid,
             handle: res.handle,
-            input: in_pipe.map(|pipe| file::FileDesc::new(pipe.out)),
-            output: out_pipe.map(|pipe| file::FileDesc::new(pipe.input)),
-            error: err_pipe.map(|pipe| file::FileDesc::new(pipe.input)),
+            input: in_pipe.map(|pipe| file::FileDesc::new(pipe.out, true)),
+            output: out_pipe.map(|pipe| file::FileDesc::new(pipe.input, true)),
+            error: err_pipe.map(|pipe| file::FileDesc::new(pipe.input, true)),
             exit_code: None,
         }
     }
diff --git a/src/libstd/rt/io/native/stdio.rs b/src/libstd/rt/io/native/stdio.rs
index 5661725d77b..ddfbb9a8f8c 100644
--- a/src/libstd/rt/io/native/stdio.rs
+++ b/src/libstd/rt/io/native/stdio.rs
@@ -36,10 +36,8 @@ pub struct StdIn {
 
 impl StdIn {
     /// Duplicates the stdin file descriptor, returning an io::Reader
-    #[fixed_stack_segment] #[inline(never)]
     pub fn new() -> StdIn {
-        let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
-        StdIn { fd: file::FileDesc::new(fd) }
+        StdIn { fd: file::FileDesc::new(libc::STDIN_FILENO, false) }
     }
 }
 
@@ -54,10 +52,8 @@ pub struct StdOut {
 
 impl StdOut {
     /// Duplicates the specified file descriptor, returning an io::Writer
-    #[fixed_stack_segment] #[inline(never)]
     pub fn new(fd: file::fd_t) -> StdOut {
-        let fd = unsafe { libc::dup(fd) };
-        StdOut { fd: file::FileDesc::new(fd) }
+        StdOut { fd: file::FileDesc::new(fd, false) }
     }
 }
 
diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs
index 36092dfbe34..fed6b9daa64 100644
--- a/src/libstd/rt/io/timer.rs
+++ b/src/libstd/rt/io/timer.rs
@@ -160,11 +160,7 @@ mod test {
             let port = timer.oneshot(100000000000);
             timer.sleep(1); // this should invalidate the port
 
-            let port = Cell::new(port);
-            let ret = do task::try {
-                port.take().recv();
-            };
-            assert!(ret.is_err());
+            assert_eq!(port.try_recv(), None);
         }
     }
 
diff --git a/src/libstd/rt/macros.rs b/src/libstd/rt/macros.rs
index 2c89bfd8c76..3ef57710344 100644
--- a/src/libstd/rt/macros.rs
+++ b/src/libstd/rt/macros.rs
@@ -42,8 +42,7 @@ macro_rules! rtassert (
 
 
 macro_rules! rtabort (
-    ($msg:expr $($arg:tt)*) => ( {
-        ::rt::util::abort(format!(concat!(file!(), ":", line!(), " ", $msg)
-                                  $($arg)*));
+    ($($arg:tt)*) => ( {
+        ::rt::util::abort(format!($($arg)*));
     } )
 )