Skip to content

Commit 35df55c

Browse files
committed
---
yaml --- r: 94190 b: refs/heads/try c: ec5603b h: refs/heads/master v: v3
1 parent c62e638 commit 35df55c

File tree

8 files changed

+60
-28
lines changed

8 files changed

+60
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: ab3bec91d77150e434ac1480fbb3935213e33dca
5+
refs/heads/try: ec5603bf13ccb95c311fe5ca193a32efe07147a2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustpkg/installed_packages.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use std::io::fs;
1919
pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
2020
let workspaces = rust_path();
2121
for p in workspaces.iter() {
22-
let binfiles = io::ignore_io_error(|| fs::readdir(&p.join("bin")));
22+
let binfiles = {
23+
let _guard = io::ignore_io_error();
24+
fs::readdir(&p.join("bin"))
25+
};
2326
for exec in binfiles.iter() {
2427
// FIXME (#9639): This needs to handle non-utf8 paths
2528
match exec.filestem_str() {
@@ -31,7 +34,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
3134
}
3235
}
3336
}
34-
let libfiles = io::ignore_io_error(|| fs::readdir(&p.join("lib")));
37+
let libfiles = {
38+
let _guard = io::ignore_io_error();
39+
fs::readdir(&p.join("lib"))
40+
};
3541
for lib in libfiles.iter() {
3642
debug!("Full name: {}", lib.display());
3743
match has_library(lib) {
@@ -55,7 +61,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
5561
}
5662

5763
pub fn has_library(p: &Path) -> Option<~str> {
58-
let files = io::ignore_io_error(|| fs::readdir(p));
64+
let files = {
65+
let _guard = io::ignore_io_error();
66+
fs::readdir(p)
67+
};
5968
for path in files.iter() {
6069
if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
6170
let stuff : &str = path.filestem_str().expect("has_library: weird path");

branches/try/src/librustpkg/path_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
217217

218218
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
219219
debug!("Listing directory {}", dir_to_search.display());
220-
let dir_contents = io::ignore_io_error(|| fs::readdir(dir_to_search));
220+
let dir_contents = {
221+
let _guard = io::ignore_io_error();
222+
fs::readdir(dir_to_search)
223+
};
221224
debug!("dir has {:?} entries", dir_contents.len());
222225

223226
let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name);

branches/try/src/libstd/condition.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<T, U> Condition<T, U> {
162162
///
163163
/// Normally this object is not dealt with directly, but rather it's directly
164164
/// used after being returned from `trap`
165-
struct Trap<'self, T, U> {
165+
pub struct Trap<'self, T, U> {
166166
priv cond: &'self Condition<T, U>,
167167
priv handler: @Handler<T, U>
168168
}
@@ -187,10 +187,24 @@ impl<'self, T, U> Trap<'self, T, U> {
187187
local_data::set(self.cond.key, self.handler);
188188
inner()
189189
}
190+
191+
/// Returns a guard that will automatically reset the condition upon
192+
/// exit of the scope. This is useful if you want to use conditions with
193+
/// an RAII pattern.
194+
pub fn guard(&self) -> Guard<'self,T,U> {
195+
let guard = Guard {
196+
cond: self.cond
197+
};
198+
debug!("Guard: pushing handler to TLS");
199+
local_data::set(self.cond.key, self.handler);
200+
guard
201+
}
190202
}
191203

192-
#[doc(hidden)]
193-
struct Guard<'self, T, U> {
204+
/// A guard that will automatically reset the condition handler upon exit of
205+
/// the scope. This is useful if you want to use conditions with an RAII
206+
/// pattern.
207+
pub struct Guard<'self, T, U> {
194208
priv cond: &'self Condition<T, U>
195209
}
196210

branches/try/src/libstd/io/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Out of scope
241241
#[allow(missing_doc)];
242242

243243
use cast;
244+
use condition::Guard;
244245
use container::Container;
245246
use int;
246247
use iter::Iterator;
@@ -394,12 +395,12 @@ condition! {
394395

395396
/// Helper for wrapper calls where you want to
396397
/// ignore any io_errors that might be raised
397-
pub fn ignore_io_error<T>(cb: || -> T) -> T {
398+
pub fn ignore_io_error() -> Guard<'static,IoError,()> {
398399
io_error::cond.trap(|_| {
399400
// just swallow the error.. downstream users
400401
// who can make a decision based on a None result
401402
// won't care
402-
}).inside(|| cb())
403+
}).guard()
403404
}
404405

405406
/// Helper for catching an I/O error and wrapping it in a Result object. The

branches/try/src/libstd/os.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,9 @@ mod tests {
14771477
assert!(*chunk.data == 0xbe);
14781478
close(fd);
14791479
}
1480-
io::ignore_io_error(|| fs::unlink(&path));
1480+
1481+
let _guard = io::ignore_io_error();
1482+
fs::unlink(&path);
14811483
}
14821484

14831485
// More recursive_mkdir tests are in extra::tempfile

branches/try/src/libstd/run.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
#[allow(missing_doc)];
1414

15-
use cell::Cell;
1615
use comm::{stream, SharedChan};
1716
use io::Reader;
1817
use io::process::ProcessExit;
@@ -212,8 +211,8 @@ impl Process {
212211
*/
213212
pub fn finish_with_output(&mut self) -> ProcessOutput {
214213
self.close_input();
215-
let output = Cell::new(self.inner.io[1].take());
216-
let error = Cell::new(self.inner.io[2].take());
214+
let output = self.inner.io[1].take();
215+
let error = self.inner.io[2].take();
217216

218217
// Spawn two entire schedulers to read both stdout and sterr
219218
// in parallel so we don't deadlock while blocking on one
@@ -224,20 +223,20 @@ impl Process {
224223
let ch_clone = ch.clone();
225224

226225
do spawn {
227-
io::ignore_io_error(|| {
228-
match error.take() {
229-
Some(ref mut e) => ch.send((2, e.read_to_end())),
230-
None => ch.send((2, ~[]))
231-
}
232-
})
226+
let _guard = io::ignore_io_error();
227+
let mut error = error;
228+
match error {
229+
Some(ref mut e) => ch.send((2, e.read_to_end())),
230+
None => ch.send((2, ~[]))
231+
}
233232
}
234233
do spawn {
235-
io::ignore_io_error(|| {
236-
match output.take() {
237-
Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
238-
None => ch_clone.send((1, ~[]))
239-
}
240-
})
234+
let _guard = io::ignore_io_error();
235+
let mut output = output;
236+
match output {
237+
Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
238+
None => ch_clone.send((1, ~[]))
239+
}
241240
}
242241

243242
let status = self.finish();

branches/try/src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ fn main() {
189189
let mut proc_mode = false;
190190
191191
loop {
192-
let line = match io::ignore_io_error(|| rdr.read_line()) {
193-
Some(ln) => ln, None => break,
192+
let line = {
193+
let _guard = io::ignore_io_error();
194+
match rdr.read_line() {
195+
Some(ln) => ln,
196+
None => break,
197+
}
194198
};
195199
let line = line.trim().to_owned();
196200

0 commit comments

Comments
 (0)