Skip to content

Commit 3f5b221

Browse files
committed
auto merge of #9901 : alexcrichton/rust/unix-sockets, r=brson
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)
2 parents 61f8c05 + 188e471 commit 3f5b221

File tree

141 files changed

+3937
-5451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+3937
-5451
lines changed

doc/tutorial-conditions.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $ ./example numbers.txt
4343

4444
An example program that does this task reads like this:
4545

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

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

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

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

723-
~~~~
723+
~~~~{.xfail-test}
724724
# #[allow(unused_imports)];
725725
extern mod extra;
726726
use extra::fileinput::FileInput;

doc/tutorial-tasks.md

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ calling the `spawn` function with a closure argument. `spawn` executes the
6969
closure in the new task.
7070

7171
~~~~
72-
# use std::io::println;
7372
# use std::task::spawn;
7473
7574
// Print something profound in a different task using a named function

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2907,12 +2907,12 @@ you just have to import it with an `use` statement.
29072907
For example, it re-exports `println` which is defined in `std::io::println`:
29082908

29092909
~~~
2910-
use puts = std::io::println;
2910+
use puts = std::rt::io::stdio::println;
29112911
29122912
fn main() {
29132913
println("println is imported per default.");
29142914
puts("Doesn't hinder you from importing it under an different name yourself.");
2915-
::std::io::println("Or from not using the automatic import.");
2915+
::std::rt::io::stdio::println("Or from not using the automatic import.");
29162916
}
29172917
~~~
29182918

src/compiletest/runtest.rs

+25-27
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use util;
2121
use util::logv;
2222

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

173-
let mut srcs = ~[io::read_whole_file_str(testfile).unwrap()];
176+
let src = testfile.open_reader(io::Open).read_to_end();
177+
let src = str::from_utf8_owned(src);
178+
let mut srcs = ~[src];
174179

175180
let mut round = 0;
176181
while round < rounds {
@@ -190,7 +195,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
190195
let mut expected = match props.pp_exact {
191196
Some(ref file) => {
192197
let filepath = testfile.dir_path().join(file);
193-
io::read_whole_file_str(&filepath).unwrap()
198+
let s = filepath.open_reader(io::Open).read_to_end();
199+
str::from_utf8_owned(s)
194200
}
195201
None => { srcs[srcs.len() - 2u].clone() }
196202
};
@@ -228,8 +234,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
228234
fn compare_source(expected: &str, actual: &str) {
229235
if expected != actual {
230236
error(~"pretty-printed source does not match expected source");
231-
let msg =
232-
format!("\n\
237+
println!("\n\
233238
expected:\n\
234239
------------------------------------------\n\
235240
{}\n\
@@ -240,7 +245,6 @@ actual:\n\
240245
------------------------------------------\n\
241246
\n",
242247
expected, actual);
243-
io::stdout().write_str(msg);
244248
fail!();
245249
}
246250
}
@@ -741,9 +745,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
741745
fn dump_output_file(config: &config, testfile: &Path,
742746
out: &str, extension: &str) {
743747
let outfile = make_out_name(config, testfile, extension);
744-
let writer =
745-
io::file_writer(&outfile, [io::Create, io::Truncate]).unwrap();
746-
writer.write_str(out);
748+
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
747749
}
748750

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

772774
fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {
773775
if config.verbose {
774-
let sep1 = format!("------{}------------------------------", "stdout");
775-
let sep2 = format!("------{}------------------------------", "stderr");
776-
let sep3 = ~"------------------------------------------";
777-
io::stdout().write_line(sep1);
778-
io::stdout().write_line(out);
779-
io::stdout().write_line(sep2);
780-
io::stdout().write_line(err);
781-
io::stdout().write_line(sep3);
776+
println!("------{}------------------------------", "stdout");
777+
println!("{}", out);
778+
println!("------{}------------------------------", "stderr");
779+
println!("{}", err);
780+
println!("------------------------------------------");
782781
}
783782
}
784783

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

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

789788
fn fatal_ProcRes(err: ~str, ProcRes: &ProcRes) -> ! {
790-
let msg =
791-
format!("\n\
789+
print!("\n\
792790
error: {}\n\
793791
command: {}\n\
794792
stdout:\n\
@@ -801,7 +799,6 @@ stderr:\n\
801799
------------------------------------------\n\
802800
\n",
803801
err, ProcRes.cmdline, ProcRes.stdout, ProcRes.stderr);
804-
io::stdout().write_str(msg);
805802
fail!();
806803
}
807804

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

823820
if config.verbose {
824-
io::stdout().write_str(format!("push ({}) {} {} {}",
821+
println!("push ({}) {} {} {}",
825822
config.target, args.prog,
826-
copy_result.out, copy_result.err));
823+
copy_result.out, copy_result.err);
827824
}
828825

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

915912
if config.verbose {
916-
io::stdout().write_str(format!("push ({}) {} {} {}",
913+
println!("push ({}) {} {} {}",
917914
config.target, file.display(),
918-
copy_result.out, copy_result.err));
915+
copy_result.out, copy_result.err);
919916
}
920917
}
921918
}
@@ -999,7 +996,8 @@ fn disassemble_extract(config: &config, _props: &TestProps,
999996

1000997

1001998
fn count_extracted_lines(p: &Path) -> uint {
1002-
let x = io::read_whole_file_str(&p.with_extension("ll")).unwrap();
999+
let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
1000+
let x = str::from_utf8_owned(x);
10031001
x.line_iter().len()
10041002
}
10051003

src/compiletest/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use common::config;
1212

13-
use std::io;
1413
use std::os::getenv;
1514

1615
/// Conversion table from triple OS name to Rust SYSNAME
@@ -64,5 +63,5 @@ pub fn path_div() -> ~str { ~";" }
6463
6564
pub fn logv(config: &config, s: ~str) {
6665
debug!("{}", s);
67-
if config.verbose { io::println(s); }
66+
if config.verbose { println(s); }
6867
}

src/etc/combine-tests.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def scrub(b):
5656
d.write("extern mod extra;\n")
5757
d.write("extern mod run_pass_stage2;\n")
5858
d.write("use run_pass_stage2::*;\n")
59-
d.write("use std::io::WriterUtil;\n");
60-
d.write("use std::io;\n");
59+
d.write("use std::rt::io;\n");
60+
d.write("use std::rt::io::Writer;\n");
6161
d.write("fn main() {\n");
62-
d.write(" let out = io::stdout();\n");
62+
d.write(" let mut out = io::stdout();\n");
6363
i = 0
6464
for t in stage2_tests:
6565
p = os.path.join("test", "run-pass", t)
6666
p = p.replace("\\", "\\\\")
67-
d.write(" out.write_str(\"run-pass [stage2]: %s\\n\");\n" % p)
67+
d.write(" out.write(\"run-pass [stage2]: %s\\n\".as_bytes());\n" % p)
6868
d.write(" t_%d::main();\n" % i)
6969
i += 1
7070
d.write("}\n")

0 commit comments

Comments
 (0)