diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-25 17:04:37 -0700 | 
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-03 15:15:42 -0800 | 
| commit | 9c1851019f1ef9511fa8731b8f1acb0796d1e97f (patch) | |
| tree | 0cd6d600bfc077e1d19722afdb042c9c016db621 /src/libsyntax/ext/source_util.rs | |
| parent | 7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78 (diff) | |
| download | rust-9c1851019f1ef9511fa8731b8f1acb0796d1e97f.tar.gz rust-9c1851019f1ef9511fa8731b8f1acb0796d1e97f.zip | |
Remove all blocking std::os blocking functions
This commit moves all thread-blocking I/O functions from the std::os module. Their replacements can be found in either std::rt::io::file or in a hidden "old_os" module inside of native::file. I didn't want to outright delete these functions because they have a lot of special casing learned over time for each OS/platform, and I imagine that these will someday get integrated into a blocking implementation of IoFactory. For now, they're moved to a private module to prevent bitrot and still have tests to ensure that they work. I've also expanded the extensions to a few more methods defined on Path, most of which were previously defined in std::os but now have non-thread-blocking implementations as part of using the current IoFactory. The api of io::file is in flux, but I plan on changing it in the next commit as well. Closes #10057
Diffstat (limited to 'src/libsyntax/ext/source_util.rs')
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 25 | 
1 files changed, 8 insertions, 17 deletions
| diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index fda6f782af4..876adf40186 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -21,7 +21,7 @@ use print::pprust; use std::rt::io; use std::rt::io::Reader; -use std::rt::io::file::FileInfo; +use std::rt::io::file; use std::str; // These macros all relate to the file system; they either return @@ -92,17 +92,13 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let file = res_rel_file(cx, sp, &Path::new(file)); - let mut error = None; - let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { - file.open_reader(io::Open).read_to_end() - }; - match error { - Some(e) => { + let bytes = match io::result(|| file::open(&file).read_to_end()) { + Err(e) => { cx.span_fatal(sp, format!("couldn't read {}: {}", file.display(), e.desc)); } - None => {} - } + Ok(bytes) => bytes, + }; match str::from_utf8_owned_opt(bytes) { Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())), None => { @@ -118,17 +114,12 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); let file = res_rel_file(cx, sp, &Path::new(file)); - - let mut error = None; - let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { - file.open_reader(io::Open).read_to_end() - }; - match error { - Some(e) => { + match io::result(|| file::open(&file).read_to_end()) { + Err(e) => { cx.span_fatal(sp, format!("couldn't read {}: {}", file.display(), e.desc)); } - None => { + Ok(bytes) => { let bytes = at_vec::to_managed_move(bytes); base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes))) } | 
