Skip to content

Commit

Permalink
auto merge of #9901 : alexcrichton/rust/unix-sockets, r=brson
Browse files Browse the repository at this point in the history
Large topics:

* Implemented `rt::io::net::unix`. We've got an implementation backed by "named pipes" for windows for free from libuv, so I'm not sure if these should be `cfg(unix)` or whether they'd be better placed in `rt::io::pipe` (which is currently kinda useless), or to leave in `unix`. Regardless, we probably shouldn't deny windows of functionality which it certainly has.
* Fully implemented `net::addrinfo`, or at least fully implemented in the sense of making the best attempt to wrap libuv's `getaddrinfo` api
* Moved standard I/O to a libuv TTY instead of just a plain old file descriptor. I found that this interacted better when closing stdin, and it has the added bonus of getting things like terminal dimentions (someone should make a progress bar now!)
* Migrate to `~Trait` instead of a typedef'd object where possible. There are only two more types which are blocked on this, and those are traits which have a method which takes by-value self (there's an open issue on this)
* Drop `rt::io::support::PathLike` in favor of just `ToCStr`. We recently had a lot of Path work done, but it still wasn't getting passed down to libuv (there was an intermediate string conversion), and this allows true paths to work all the way down to libuv (and anything else that can become a C string).
* Removes `extra::fileinput` and `extra::io_util`


Closes #9895 
Closes #9975
Closes #8330
Closes #6850 (ported lots of libraries away from std::io)
cc #4248 (implemented unix/dns)
cc #9128 (made everything truly trait objects)
  • Loading branch information
bors committed Oct 24, 2013
2 parents 61f8c05 + 188e471 commit 3f5b221
Show file tree
Hide file tree
Showing 141 changed files with 3,937 additions and 5,451 deletions.
10 changes: 5 additions & 5 deletions doc/tutorial-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $ ./example numbers.txt

An example program that does this task reads like this:

~~~~
~~~~{.xfail-test}
# #[allow(unused_imports)];
extern mod extra;
use extra::fileinput::FileInput;
Expand Down Expand Up @@ -430,7 +430,7 @@ To trap a condition, use `Condition::trap` in some caller of the site that calls
For example, this version of the program traps the `malformed_line` condition
and replaces bad input lines with the pair `(-1,-1)`:

~~~~
~~~~{.xfail-test}
# #[allow(unused_imports)];
extern mod extra;
use extra::fileinput::FileInput;
Expand Down Expand Up @@ -507,7 +507,7 @@ In the example program, the first form of the `malformed_line` API implicitly as
This assumption may not be correct; some callers may wish to skip malformed lines, for example.
Changing the condition's return type from `(int,int)` to `Option<(int,int)>` will suffice to support this type of recovery:

~~~~
~~~~{.xfail-test}
# #[allow(unused_imports)];
extern mod extra;
use extra::fileinput::FileInput;
Expand Down Expand Up @@ -594,7 +594,7 @@ until all relevant combinations encountered in practice are encoded.
In the example, suppose a third possible recovery form arose: reusing the previous value read.
This can be encoded in the handler API by introducing a helper type: `enum MalformedLineFix`.

~~~~
~~~~{.xfail-test}
# #[allow(unused_imports)];
extern mod extra;
use extra::fileinput::FileInput;
Expand Down Expand Up @@ -720,7 +720,7 @@ task <unnamed> failed at 'called `Option::unwrap()` on a `None` value', .../libs
To make the program robust -- or at least flexible -- in the face of this potential failure,
a second condition and a helper function will suffice:

~~~~
~~~~{.xfail-test}
# #[allow(unused_imports)];
extern mod extra;
use extra::fileinput::FileInput;
Expand Down
1 change: 0 additions & 1 deletion doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ calling the `spawn` function with a closure argument. `spawn` executes the
closure in the new task.

~~~~
# use std::io::println;
# use std::task::spawn;
// Print something profound in a different task using a named function
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2907,12 +2907,12 @@ you just have to import it with an `use` statement.
For example, it re-exports `println` which is defined in `std::io::println`:

~~~
use puts = std::io::println;
use puts = std::rt::io::stdio::println;
fn main() {
println("println is imported per default.");
puts("Doesn't hinder you from importing it under an different name yourself.");
::std::io::println("Or from not using the automatic import.");
::std::rt::io::stdio::println("Or from not using the automatic import.");
}
~~~

Expand Down
52 changes: 25 additions & 27 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use util;
use util::logv;

use std::cell::Cell;
use std::io;
use std::rt::io;
use std::rt::io::Writer;
use std::rt::io::extensions::ReaderUtil;
use std::rt::io::file::FileInfo;
use std::os;
use std::str;
use std::task::{spawn_sched, SingleThreaded};
Expand Down Expand Up @@ -60,7 +63,7 @@ pub fn run(config: config, testfile: ~str) {
pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {
if config.verbose {
// We're going to be dumping a lot of info. Start on a new line.
io::stdout().write_str("\n\n");
print!("\n\n");
}
let testfile = Path::new(testfile);
debug!("running {}", testfile.display());
Expand Down Expand Up @@ -170,7 +173,9 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let rounds =
match props.pp_exact { Some(_) => 1, None => 2 };

let mut srcs = ~[io::read_whole_file_str(testfile).unwrap()];
let src = testfile.open_reader(io::Open).read_to_end();
let src = str::from_utf8_owned(src);
let mut srcs = ~[src];

let mut round = 0;
while round < rounds {
Expand All @@ -190,7 +195,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let mut expected = match props.pp_exact {
Some(ref file) => {
let filepath = testfile.dir_path().join(file);
io::read_whole_file_str(&filepath).unwrap()
let s = filepath.open_reader(io::Open).read_to_end();
str::from_utf8_owned(s)
}
None => { srcs[srcs.len() - 2u].clone() }
};
Expand Down Expand Up @@ -228,8 +234,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
fn compare_source(expected: &str, actual: &str) {
if expected != actual {
error(~"pretty-printed source does not match expected source");
let msg =
format!("\n\
println!("\n\
expected:\n\
------------------------------------------\n\
{}\n\
Expand All @@ -240,7 +245,6 @@ actual:\n\
------------------------------------------\n\
\n",
expected, actual);
io::stdout().write_str(msg);
fail!();
}
}
Expand Down Expand Up @@ -741,9 +745,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &config, testfile: &Path,
out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension);
let writer =
io::file_writer(&outfile, [io::Create, io::Truncate]).unwrap();
writer.write_str(out);
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
}

fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
Expand Down Expand Up @@ -771,24 +773,20 @@ fn output_base_name(config: &config, testfile: &Path) -> Path {

fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {
if config.verbose {
let sep1 = format!("------{}------------------------------", "stdout");
let sep2 = format!("------{}------------------------------", "stderr");
let sep3 = ~"------------------------------------------";
io::stdout().write_line(sep1);
io::stdout().write_line(out);
io::stdout().write_line(sep2);
io::stdout().write_line(err);
io::stdout().write_line(sep3);
println!("------{}------------------------------", "stdout");
println!("{}", out);
println!("------{}------------------------------", "stderr");
println!("{}", err);
println!("------------------------------------------");
}
}

fn error(err: ~str) { io::stdout().write_line(format!("\nerror: {}", err)); }
fn error(err: ~str) { println!("\nerror: {}", err); }

fn fatal(err: ~str) -> ! { error(err); fail!(); }

fn fatal_ProcRes(err: ~str, ProcRes: &ProcRes) -> ! {
let msg =
format!("\n\
print!("\n\
error: {}\n\
command: {}\n\
stdout:\n\
Expand All @@ -801,7 +799,6 @@ stderr:\n\
------------------------------------------\n\
\n",
err, ProcRes.cmdline, ProcRes.stdout, ProcRes.stderr);
io::stdout().write_str(msg);
fail!();
}

Expand All @@ -821,9 +818,9 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
~[(~"",~"")], Some(~""));

if config.verbose {
io::stdout().write_str(format!("push ({}) {} {} {}",
println!("push ({}) {} {} {}",
config.target, args.prog,
copy_result.out, copy_result.err));
copy_result.out, copy_result.err);
}

logv(config, format!("executing ({}) {}", config.target, cmdline));
Expand Down Expand Up @@ -913,9 +910,9 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
~[(~"",~"")], Some(~""));

if config.verbose {
io::stdout().write_str(format!("push ({}) {} {} {}",
println!("push ({}) {} {} {}",
config.target, file.display(),
copy_result.out, copy_result.err));
copy_result.out, copy_result.err);
}
}
}
Expand Down Expand Up @@ -999,7 +996,8 @@ fn disassemble_extract(config: &config, _props: &TestProps,


fn count_extracted_lines(p: &Path) -> uint {
let x = io::read_whole_file_str(&p.with_extension("ll")).unwrap();
let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
let x = str::from_utf8_owned(x);
x.line_iter().len()
}

Expand Down
3 changes: 1 addition & 2 deletions src/compiletest/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use common::config;

use std::io;
use std::os::getenv;

/// Conversion table from triple OS name to Rust SYSNAME
Expand Down Expand Up @@ -64,5 +63,5 @@ pub fn path_div() -> ~str { ~";" }
pub fn logv(config: &config, s: ~str) {
debug!("{}", s);
if config.verbose { io::println(s); }
if config.verbose { println(s); }
}
8 changes: 4 additions & 4 deletions src/etc/combine-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def scrub(b):
d.write("extern mod extra;\n")
d.write("extern mod run_pass_stage2;\n")
d.write("use run_pass_stage2::*;\n")
d.write("use std::io::WriterUtil;\n");
d.write("use std::io;\n");
d.write("use std::rt::io;\n");
d.write("use std::rt::io::Writer;\n");
d.write("fn main() {\n");
d.write(" let out = io::stdout();\n");
d.write(" let mut out = io::stdout();\n");
i = 0
for t in stage2_tests:
p = os.path.join("test", "run-pass", t)
p = p.replace("\\", "\\\\")
d.write(" out.write_str(\"run-pass [stage2]: %s\\n\");\n" % p)
d.write(" out.write(\"run-pass [stage2]: %s\\n\".as_bytes());\n" % p)
d.write(" t_%d::main();\n" % i)
i += 1
d.write("}\n")
Loading

0 comments on commit 3f5b221

Please sign in to comment.