Test fixes and merge conflicts

This commit is contained in:
Alex Crichton 2013-10-17 21:08:48 -07:00
parent 279c351820
commit 620ab3853a
19 changed files with 151 additions and 141 deletions

View File

@ -43,7 +43,7 @@ $ ./example numbers.txt
An example program that does this task reads like this: An example program that does this task reads like this:
~~~~ ~~~~{.xfail-test}
# #[allow(unused_imports)]; # #[allow(unused_imports)];
extern mod extra; extern mod extra;
use extra::fileinput::FileInput; use extra::fileinput::FileInput;
@ -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 For example, this version of the program traps the `malformed_line` condition
and replaces bad input lines with the pair `(-1,-1)`: and replaces bad input lines with the pair `(-1,-1)`:
~~~~ ~~~~{.xfail-test}
# #[allow(unused_imports)]; # #[allow(unused_imports)];
extern mod extra; extern mod extra;
use extra::fileinput::FileInput; use extra::fileinput::FileInput;
@ -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. 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: 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)]; # #[allow(unused_imports)];
extern mod extra; extern mod extra;
use extra::fileinput::FileInput; use extra::fileinput::FileInput;
@ -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. 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`. This can be encoded in the handler API by introducing a helper type: `enum MalformedLineFix`.
~~~~ ~~~~{.xfail-test}
# #[allow(unused_imports)]; # #[allow(unused_imports)];
extern mod extra; extern mod extra;
use extra::fileinput::FileInput; use extra::fileinput::FileInput;
@ -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, 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: a second condition and a helper function will suffice:
~~~~ ~~~~{.xfail-test}
# #[allow(unused_imports)]; # #[allow(unused_imports)];
extern mod extra; extern mod extra;
use extra::fileinput::FileInput; use extra::fileinput::FileInput;

View File

@ -69,7 +69,6 @@ calling the `spawn` function with a closure argument. `spawn` executes the
closure in the new task. closure in the new task.
~~~~ ~~~~
# use std::io::println;
# use std::task::spawn; # use std::task::spawn;
// Print something profound in a different task using a named function // Print something profound in a different task using a named function

View File

@ -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`: 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() { fn main() {
println("println is imported per default."); println("println is imported per default.");
puts("Doesn't hinder you from importing it under an different name yourself."); 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.");
} }
~~~ ~~~

View File

@ -189,6 +189,8 @@ pub fn env() -> ~[(~str,~str)] {
#[cfg(windows)] #[cfg(windows)]
unsafe fn get_env_pairs() -> ~[~str] { unsafe fn get_env_pairs() -> ~[~str] {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
use c_str;
use str::StrSlice;
use libc::funcs::extra::kernel32::{ use libc::funcs::extra::kernel32::{
GetEnvironmentStringsA, GetEnvironmentStringsA,
@ -201,7 +203,7 @@ pub fn env() -> ~[(~str,~str)] {
} }
let mut result = ~[]; let mut result = ~[];
do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| { do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| {
result.push(cstr.as_str().to_owned()); result.push(cstr.as_str().unwrap().to_owned());
}; };
FreeEnvironmentStringsA(ch); FreeEnvironmentStringsA(ch);
result result

View File

@ -17,9 +17,18 @@ use os;
use prelude::*; use prelude::*;
use super::super::*; use super::super::*;
fn raise_error() { #[cfg(windows)]
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
match errno {
libc::EOF => (EndOfFile, "end of file"),
_ => (OtherIoError, "unknown error"),
}
}
#[cfg(not(windows))]
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
// XXX: this should probably be a bit more descriptive... // XXX: this should probably be a bit more descriptive...
let (kind, desc) = match os::errno() as i32 { match errno {
libc::EOF => (EndOfFile, "end of file"), libc::EOF => (EndOfFile, "end of file"),
// These two constants can have the same value on some systems, but // These two constants can have the same value on some systems, but
@ -28,8 +37,11 @@ fn raise_error() {
(ResourceUnavailable, "resource temporarily unavailable"), (ResourceUnavailable, "resource temporarily unavailable"),
_ => (OtherIoError, "unknown error"), _ => (OtherIoError, "unknown error"),
}; }
}
fn raise_error() {
let (kind, desc) = get_err(os::errno() as i32);
io_error::cond.raise(IoError { io_error::cond.raise(IoError {
kind: kind, kind: kind,
desc: desc, desc: desc,

View File

@ -91,8 +91,11 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> {
/// # Failure /// # Failure
/// ///
/// On failure, this will raise on the `io_error` condition. /// On failure, this will raise on the `io_error` condition.
pub fn lookup(hostname: Option<&str>, servname: Option<&str>, ///
hint: Option<Hint>) -> Option<~[Info]> { /// XXX: this is not public because the `Hint` structure is not ready for public
/// consumption just yet.
fn lookup(hostname: Option<&str>, servname: Option<&str>,
hint: Option<Hint>) -> Option<~[Info]> {
do with_local_io |io| { do with_local_io |io| {
match io.get_host_addresses(hostname, servname, hint) { match io.get_host_addresses(hostname, servname, hint) {
Ok(i) => Some(i), Ok(i) => Some(i),

View File

@ -72,16 +72,22 @@ pub fn default_sched_threads() -> uint {
pub fn dumb_println(args: &fmt::Arguments) { pub fn dumb_println(args: &fmt::Arguments) {
use rt::io::native::stdio::stderr; use rt::io::native::stdio::stderr;
use rt::io::{Writer, io_error, ResourceUnavailable}; use rt::io::{Writer, io_error, ResourceUnavailable};
use rt::task::Task;
use rt::local::Local;
let mut out = stderr(); let mut out = stderr();
let mut again = true; if Local::exists(None::<Task>) {
do io_error::cond.trap(|e| { let mut again = true;
again = e.kind == ResourceUnavailable; do io_error::cond.trap(|e| {
}).inside { again = e.kind == ResourceUnavailable;
while again { }).inside {
again = false; while again {
fmt::writeln(&mut out as &mut Writer, args); again = false;
fmt::writeln(&mut out as &mut Writer, args);
}
} }
} else {
fmt::writeln(&mut out as &mut Writer, args);
} }
} }

View File

@ -73,13 +73,14 @@ impl GetAddrInfoRequest {
cb(req, addrinfo, err) cb(req, addrinfo, err)
}; };
let hint = hints.map(|hint| unsafe { let hint = hints.map(|hint| {
let mut flags = 0; let mut flags = 0;
do each_ai_flag |cval, aival| { do each_ai_flag |cval, aival| {
if hint.flags & (aival as uint) != 0 { if hint.flags & (aival as uint) != 0 {
flags |= cval as i32; flags |= cval as i32;
} }
} }
/* XXX: do we really want to support these?
let socktype = match hint.socktype { let socktype = match hint.socktype {
Some(ai::Stream) => uvll::rust_SOCK_STREAM(), Some(ai::Stream) => uvll::rust_SOCK_STREAM(),
Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(), Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(),
@ -91,6 +92,9 @@ impl GetAddrInfoRequest {
Some(ai::TCP) => uvll::rust_IPPROTO_TCP(), Some(ai::TCP) => uvll::rust_IPPROTO_TCP(),
_ => 0, _ => 0,
}; };
*/
let socktype = 0;
let protocol = 0;
uvll::addrinfo { uvll::addrinfo {
ai_flags: flags, ai_flags: flags,
@ -167,7 +171,8 @@ impl GetAddrInfoRequest {
} }
} }
fn each_ai_flag(f: &fn(c_int, ai::Flag)) { fn each_ai_flag(_f: &fn(c_int, ai::Flag)) {
/* XXX: do we really want to support these?
unsafe { unsafe {
f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig); f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig);
f(uvll::rust_AI_ALL(), ai::All); f(uvll::rust_AI_ALL(), ai::All);
@ -177,6 +182,7 @@ fn each_ai_flag(f: &fn(c_int, ai::Flag)) {
f(uvll::rust_AI_PASSIVE(), ai::Passive); f(uvll::rust_AI_PASSIVE(), ai::Passive);
f(uvll::rust_AI_V4MAPPED(), ai::V4Mapped); f(uvll::rust_AI_V4MAPPED(), ai::V4Mapped);
} }
*/
} }
// Traverse the addrinfo linked list, producing a vector of Rust socket addresses // Traverse the addrinfo linked list, producing a vector of Rust socket addresses
@ -197,6 +203,7 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
} }
} }
/* XXX: do we really want to support these
let protocol = match (*addr).ai_protocol { let protocol = match (*addr).ai_protocol {
p if p == uvll::rust_IPPROTO_UDP() => Some(ai::UDP), p if p == uvll::rust_IPPROTO_UDP() => Some(ai::UDP),
p if p == uvll::rust_IPPROTO_TCP() => Some(ai::TCP), p if p == uvll::rust_IPPROTO_TCP() => Some(ai::TCP),
@ -208,6 +215,9 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
p if p == uvll::rust_SOCK_RAW() => Some(ai::Raw), p if p == uvll::rust_SOCK_RAW() => Some(ai::Raw),
_ => None, _ => None,
}; };
*/
let protocol = None;
let socktype = None;
addrs.push(ai::Info { addrs.push(ai::Info {
address: rustaddr, address: rustaddr,

View File

@ -336,6 +336,13 @@ pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
/// The uv buffer type /// The uv buffer type
pub type Buf = uvll::uv_buf_t; pub type Buf = uvll::uv_buf_t;
pub fn empty_buf() -> Buf {
uvll::uv_buf_t {
base: null(),
len: 0,
}
}
/// Borrow a slice to a Buf /// Borrow a slice to a Buf
pub fn slice_to_uv_buf(v: &[u8]) -> Buf { pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
let data = vec::raw::to_ptr(v); let data = vec::raw::to_ptr(v);

View File

@ -14,7 +14,7 @@ use rt::uv::uvll;
use rt::uv::uvll::*; use rt::uv::uvll::*;
use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback}; use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback};
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle,
status_to_maybe_uv_error, vec_to_uv_buf}; status_to_maybe_uv_error, empty_buf};
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
use vec; use vec;
use str; use str;
@ -119,23 +119,17 @@ impl Watcher for StreamWatcher { }
impl StreamWatcher { impl StreamWatcher {
pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) { pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
{ unsafe {
let data = self.get_watcher_data(); match uvll::read_start(self.native_handle(), alloc_cb, read_cb) {
data.alloc_cb = Some(alloc); 0 => {
data.read_cb = Some(cb); let data = self.get_watcher_data();
} data.alloc_cb = Some(alloc);
data.read_cb = Some(cb);
let ret = unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb) }; }
n => {
if ret != 0 { cb(*self, 0, empty_buf(), Some(UvError(n)))
// uvll::read_start failed, so read_cb will not be called. }
// Call it manually for scheduling. }
call_read_cb(self.native_handle(), ret as ssize_t);
}
fn call_read_cb(stream: *uvll::uv_stream_t, errno: ssize_t) {
#[fixed_stack_segment]; #[inline(never)];
read_cb(stream, errno, vec_to_uv_buf(~[]));
} }
extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf { extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
@ -163,16 +157,21 @@ impl StreamWatcher {
} }
pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) { pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
{
let data = self.get_watcher_data();
assert!(data.write_cb.is_none());
data.write_cb = Some(cb);
}
let req = WriteRequest::new(); let req = WriteRequest::new();
unsafe { return unsafe {
assert_eq!(0, uvll::write(req.native_handle(), self.native_handle(), [buf], write_cb)); match uvll::write(req.native_handle(), self.native_handle(),
} [buf], write_cb) {
0 => {
let data = self.get_watcher_data();
assert!(data.write_cb.is_none());
data.write_cb = Some(cb);
}
n => {
req.delete();
cb(*self, Some(UvError(n)))
}
}
};
extern fn write_cb(req: *uvll::uv_write_t, status: c_int) { extern fn write_cb(req: *uvll::uv_write_t, status: c_int) {
let write_request: WriteRequest = NativeHandle::from_native_handle(req); let write_request: WriteRequest = NativeHandle::from_native_handle(req);

View File

@ -229,7 +229,7 @@ impl EventLoop for UvEventLoop {
} }
} }
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback{ fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback {
~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback ~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback
} }

View File

@ -1146,17 +1146,18 @@ extern {
height: *c_int) -> c_int; height: *c_int) -> c_int;
fn rust_uv_guess_handle(fd: c_int) -> uv_handle_type; fn rust_uv_guess_handle(fd: c_int) -> uv_handle_type;
// XXX: see comments in addrinfo.rs
// These should all really be constants... // These should all really be constants...
#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int; //#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int;
#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int; //#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int;
#[rust_stack] pub fn rust_SOCK_RAW() -> c_int; //#[rust_stack] pub fn rust_SOCK_RAW() -> c_int;
#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int; //#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int;
#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int; //#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int;
#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int; //#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int;
#[rust_stack] pub fn rust_AI_ALL() -> c_int; //#[rust_stack] pub fn rust_AI_ALL() -> c_int;
#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int; //#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int;
#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int; //#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int;
#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int; //#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int;
#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int; //#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int;
#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int; //#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int;
} }

View File

@ -19,6 +19,7 @@ use libc;
use prelude::*; use prelude::*;
use rt::io::native::process; use rt::io::native::process;
use rt::io; use rt::io;
use rt::io::extensions::ReaderUtil;
use task; use task;
/** /**
@ -189,18 +190,6 @@ impl Process {
let output = Cell::new(self.inner.take_output()); let output = Cell::new(self.inner.take_output());
let error = Cell::new(self.inner.take_error()); let error = Cell::new(self.inner.take_error());
fn read_everything(r: &mut io::Reader) -> ~[u8] {
let mut ret = ~[];
let mut buf = [0, ..1024];
loop {
match r.read(buf) {
Some(n) => { ret.push_all(buf.slice_to(n)); }
None => break
}
}
return ret;
}
// Spawn two entire schedulers to read both stdout and sterr // Spawn two entire schedulers to read both stdout and sterr
// in parallel so we don't deadlock while blocking on one // in parallel so we don't deadlock while blocking on one
// or the other. FIXME (#2625): Surely there's a much more // or the other. FIXME (#2625): Surely there's a much more
@ -210,13 +199,13 @@ impl Process {
let ch_clone = ch.clone(); let ch_clone = ch.clone();
do task::spawn_sched(task::SingleThreaded) { do task::spawn_sched(task::SingleThreaded) {
match error.take() { match error.take() {
Some(ref mut e) => ch.send((2, read_everything(*e))), Some(ref mut e) => ch.send((2, e.read_to_end())),
None => ch.send((2, ~[])) None => ch.send((2, ~[]))
} }
} }
do task::spawn_sched(task::SingleThreaded) { do task::spawn_sched(task::SingleThreaded) {
match output.take() { match output.take() {
Some(ref mut e) => ch_clone.send((1, read_everything(*e))), Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
None => ch_clone.send((1, ~[])) None => ch_clone.send((1, ~[]))
} }
} }

View File

@ -129,6 +129,7 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
file.display(), e.desc)); file.display(), e.desc));
} }
None => { None => {
let bytes = at_vec::to_managed_move(bytes);
base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes))) base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes)))
} }
} }

View File

@ -638,19 +638,6 @@ rust_uv_pipe_init(uv_loop_t *loop, uv_pipe_t* p, int ipc) {
return uv_pipe_init(loop, p, ipc); return uv_pipe_init(loop, p, ipc);
} }
extern "C" int rust_SOCK_STREAM() { return SOCK_STREAM; }
extern "C" int rust_SOCK_DGRAM() { return SOCK_DGRAM; }
extern "C" int rust_SOCK_RAW() { return SOCK_RAW; }
extern "C" int rust_IPPROTO_UDP() { return IPPROTO_UDP; }
extern "C" int rust_IPPROTO_TCP() { return IPPROTO_TCP; }
extern "C" int rust_AI_ADDRCONFIG() { return AI_ADDRCONFIG; }
extern "C" int rust_AI_ALL() { return AI_ALL; }
extern "C" int rust_AI_CANONNAME() { return AI_CANONNAME; }
extern "C" int rust_AI_NUMERICHOST() { return AI_NUMERICHOST; }
extern "C" int rust_AI_NUMERICSERV() { return AI_NUMERICSERV; }
extern "C" int rust_AI_PASSIVE() { return AI_PASSIVE; }
extern "C" int rust_AI_V4MAPPED() { return AI_V4MAPPED; }
extern "C" int extern "C" int
rust_uv_pipe_open(uv_pipe_t *pipe, int file) { rust_uv_pipe_open(uv_pipe_t *pipe, int file) {
return uv_pipe_open(pipe, file); return uv_pipe_open(pipe, file);

View File

@ -199,18 +199,6 @@ bufrelease
bufnew bufnew
rust_take_dlerror_lock rust_take_dlerror_lock
rust_drop_dlerror_lock rust_drop_dlerror_lock
rust_SOCK_STREAM
rust_SOCK_DGRAM
rust_SOCK_RAW
rust_IPPROTO_UDP
rust_IPPROTO_TCP
rust_AI_ADDRCONFIG
rust_AI_ALL
rust_AI_CANONNAME
rust_AI_NUMERICHOST
rust_AI_NUMERICSERV
rust_AI_PASSIVE
rust_AI_V4MAPPED
rust_uv_pipe_open rust_uv_pipe_open
rust_uv_pipe_bind rust_uv_pipe_bind
rust_uv_pipe_connect rust_uv_pipe_connect

View File

@ -111,6 +111,7 @@ fn acid(ch: char, prob: u32) -> AminoAcids {
} }
fn main() { fn main() {
use std::rt::io::file::FileInfo;
let args = os::args(); let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() { let args = if os::getenv("RUST_BENCH").is_some() {
// alioth tests k-nucleotide with this data at 25,000,000 // alioth tests k-nucleotide with this data at 25,000,000
@ -122,7 +123,7 @@ fn main() {
}; };
let writer = if os::getenv("RUST_BENCH").is_some() { let writer = if os::getenv("RUST_BENCH").is_some() {
let file = "./shootout-fasta.data".open_writer(io::CreateOrTruncate); let file = Path::new("./shootout-fasta.data").open_writer(io::CreateOrTruncate);
@mut file as @mut io::Writer @mut file as @mut io::Writer
} else { } else {
@mut io::stdout() as @mut io::Writer @mut io::stdout() as @mut io::Writer

View File

@ -20,6 +20,7 @@ use std::comm;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use std::option; use std::option;
use std::os; use std::os;
use std::rt::io;
use std::str; use std::str;
use std::task; use std::task;
use std::util; use std::util;
@ -193,48 +194,48 @@ fn main() {
let mut proc_mode = false; let mut proc_mode = false;
loop { loop {
let line = match rdr.read_line() { let line = match io::ignore_io_error(|| rdr.read_line()) {
Some(ln) => ln, None => break, Some(ln) => ln, None => break,
}; };
let line = line.trim().to_owned(); let line = line.trim().to_owned();
if line.len() == 0u { continue; } if line.len() == 0u { continue; }
match (line[0] as char, proc_mode) { match (line[0] as char, proc_mode) {
// start processing if this is the one // start processing if this is the one
('>', false) => { ('>', false) => {
match line.slice_from(1).find_str("THREE") { match line.slice_from(1).find_str("THREE") {
option::Some(_) => { proc_mode = true; } option::Some(_) => { proc_mode = true; }
option::None => { } option::None => { }
} }
} }
// break our processing // break our processing
('>', true) => { break; } ('>', true) => { break; }
// process the sequence for k-mers // process the sequence for k-mers
(_, true) => { (_, true) => {
let line_bytes = line.as_bytes(); let line_bytes = line.as_bytes();
for (ii, _sz) in sizes.iter().enumerate() { for (ii, _sz) in sizes.iter().enumerate() {
let lb = line_bytes.to_owned(); let lb = line_bytes.to_owned();
to_child[ii].send(lb); to_child[ii].send(lb);
} }
} }
// whatever // whatever
_ => { } _ => { }
} }
} }
// finish... // finish...
for (ii, _sz) in sizes.iter().enumerate() { for (ii, _sz) in sizes.iter().enumerate() {
to_child[ii].send(~[]); to_child[ii].send(~[]);
} }
// now fetch and print result messages // now fetch and print result messages
for (ii, _sz) in sizes.iter().enumerate() { for (ii, _sz) in sizes.iter().enumerate() {
println(from_child[ii].recv()); println(from_child[ii].recv());
} }
} }

View File

@ -15,6 +15,8 @@
extern mod extra; extern mod extra;
use std::rt::io; use std::rt::io;
use std::rt::io::stdio::StdReader;
use std::rt::io::buffered::BufferedReader;
use std::os; use std::os;
use std::uint; use std::uint;
use std::unstable::intrinsics::cttz16; use std::unstable::intrinsics::cttz16;
@ -66,12 +68,14 @@ impl Sudoku {
return true; return true;
} }
pub fn read(reader: @mut io::Reader) -> Sudoku { pub fn read(mut reader: BufferedReader<StdReader>) -> Sudoku {
assert!(reader.read_line() == ~"9,9"); /* assert first line is exactly "9,9" */ assert!(reader.read_line().unwrap() == ~"9,9"); /* assert first line is exactly "9,9" */
let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] }); let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] });
while !reader.eof() { loop {
let line = reader.read_line(); let line = match reader.read_line() {
Some(ln) => ln, None => break
};
let comps: ~[&str] = line.trim().split_iter(',').collect(); let comps: ~[&str] = line.trim().split_iter(',').collect();
if comps.len() == 3u { if comps.len() == 3u {
@ -88,11 +92,11 @@ impl Sudoku {
pub fn write(&self, writer: @mut io::Writer) { pub fn write(&self, writer: @mut io::Writer) {
for row in range(0u8, 9u8) { for row in range(0u8, 9u8) {
writer.write_str(format!("{}", self.grid[row][0] as uint)); write!(writer, "{}", self.grid[row][0]);
for col in range(1u8, 9u8) { for col in range(1u8, 9u8) {
writer.write_str(format!(" {}", self.grid[row][col] as uint)); write!(writer, " {}", self.grid[row][col]);
} }
writer.write_char('\n'); write!(writer, "\n");
} }
} }
@ -277,7 +281,7 @@ fn main() {
let mut sudoku = if use_default { let mut sudoku = if use_default {
Sudoku::from_vec(&DEFAULT_SUDOKU) Sudoku::from_vec(&DEFAULT_SUDOKU)
} else { } else {
Sudoku::read(@mut io::stdin() as @mut io::Reader) Sudoku::read(BufferedReader::new(io::stdin()))
}; };
sudoku.solve(); sudoku.solve();
sudoku.write(@mut io::stdout() as @mut io::Writer); sudoku.write(@mut io::stdout() as @mut io::Writer);