Skip to content

Commit 620ab38

Browse files
committed
Test fixes and merge conflicts
1 parent 279c351 commit 620ab38

File tree

19 files changed

+158
-148
lines changed

19 files changed

+158
-148
lines changed

doc/tutorial-conditions.md

Lines changed: 5 additions & 5 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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/libstd/os.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ pub fn env() -> ~[(~str,~str)] {
189189
#[cfg(windows)]
190190
unsafe fn get_env_pairs() -> ~[~str] {
191191
#[fixed_stack_segment]; #[inline(never)];
192+
use c_str;
193+
use str::StrSlice;
192194

193195
use libc::funcs::extra::kernel32::{
194196
GetEnvironmentStringsA,
@@ -201,7 +203,7 @@ pub fn env() -> ~[(~str,~str)] {
201203
}
202204
let mut result = ~[];
203205
do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| {
204-
result.push(cstr.as_str().to_owned());
206+
result.push(cstr.as_str().unwrap().to_owned());
205207
};
206208
FreeEnvironmentStringsA(ch);
207209
result

src/libstd/rt/io/native/file.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ use os;
1717
use prelude::*;
1818
use super::super::*;
1919

20-
fn raise_error() {
20+
#[cfg(windows)]
21+
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
22+
match errno {
23+
libc::EOF => (EndOfFile, "end of file"),
24+
_ => (OtherIoError, "unknown error"),
25+
}
26+
}
27+
28+
#[cfg(not(windows))]
29+
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
2130
// XXX: this should probably be a bit more descriptive...
22-
let (kind, desc) = match os::errno() as i32 {
31+
match errno {
2332
libc::EOF => (EndOfFile, "end of file"),
2433

2534
// These two constants can have the same value on some systems, but
@@ -28,8 +37,11 @@ fn raise_error() {
2837
(ResourceUnavailable, "resource temporarily unavailable"),
2938

3039
_ => (OtherIoError, "unknown error"),
31-
};
40+
}
41+
}
3242

43+
fn raise_error() {
44+
let (kind, desc) = get_err(os::errno() as i32);
3345
io_error::cond.raise(IoError {
3446
kind: kind,
3547
desc: desc,

src/libstd/rt/io/net/addrinfo.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> {
9191
/// # Failure
9292
///
9393
/// On failure, this will raise on the `io_error` condition.
94-
pub fn lookup(hostname: Option<&str>, servname: Option<&str>,
95-
hint: Option<Hint>) -> Option<~[Info]> {
94+
///
95+
/// XXX: this is not public because the `Hint` structure is not ready for public
96+
/// consumption just yet.
97+
fn lookup(hostname: Option<&str>, servname: Option<&str>,
98+
hint: Option<Hint>) -> Option<~[Info]> {
9699
do with_local_io |io| {
97100
match io.get_host_addresses(hostname, servname, hint) {
98101
Ok(i) => Some(i),

src/libstd/rt/util.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,22 @@ pub fn default_sched_threads() -> uint {
7272
pub fn dumb_println(args: &fmt::Arguments) {
7373
use rt::io::native::stdio::stderr;
7474
use rt::io::{Writer, io_error, ResourceUnavailable};
75+
use rt::task::Task;
76+
use rt::local::Local;
7577

7678
let mut out = stderr();
77-
let mut again = true;
78-
do io_error::cond.trap(|e| {
79-
again = e.kind == ResourceUnavailable;
80-
}).inside {
81-
while again {
82-
again = false;
83-
fmt::writeln(&mut out as &mut Writer, args);
79+
if Local::exists(None::<Task>) {
80+
let mut again = true;
81+
do io_error::cond.trap(|e| {
82+
again = e.kind == ResourceUnavailable;
83+
}).inside {
84+
while again {
85+
again = false;
86+
fmt::writeln(&mut out as &mut Writer, args);
87+
}
8488
}
89+
} else {
90+
fmt::writeln(&mut out as &mut Writer, args);
8591
}
8692
}
8793

src/libstd/rt/uv/addrinfo.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ impl GetAddrInfoRequest {
7373
cb(req, addrinfo, err)
7474
};
7575

76-
let hint = hints.map(|hint| unsafe {
76+
let hint = hints.map(|hint| {
7777
let mut flags = 0;
7878
do each_ai_flag |cval, aival| {
7979
if hint.flags & (aival as uint) != 0 {
8080
flags |= cval as i32;
8181
}
8282
}
83+
/* XXX: do we really want to support these?
8384
let socktype = match hint.socktype {
8485
Some(ai::Stream) => uvll::rust_SOCK_STREAM(),
8586
Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(),
@@ -91,6 +92,9 @@ impl GetAddrInfoRequest {
9192
Some(ai::TCP) => uvll::rust_IPPROTO_TCP(),
9293
_ => 0,
9394
};
95+
*/
96+
let socktype = 0;
97+
let protocol = 0;
9498

9599
uvll::addrinfo {
96100
ai_flags: flags,
@@ -167,7 +171,8 @@ impl GetAddrInfoRequest {
167171
}
168172
}
169173

170-
fn each_ai_flag(f: &fn(c_int, ai::Flag)) {
174+
fn each_ai_flag(_f: &fn(c_int, ai::Flag)) {
175+
/* XXX: do we really want to support these?
171176
unsafe {
172177
f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig);
173178
f(uvll::rust_AI_ALL(), ai::All);
@@ -177,6 +182,7 @@ fn each_ai_flag(f: &fn(c_int, ai::Flag)) {
177182
f(uvll::rust_AI_PASSIVE(), ai::Passive);
178183
f(uvll::rust_AI_V4MAPPED(), ai::V4Mapped);
179184
}
185+
*/
180186
}
181187

182188
// 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] {
197203
}
198204
}
199205

206+
/* XXX: do we really want to support these
200207
let protocol = match (*addr).ai_protocol {
201208
p if p == uvll::rust_IPPROTO_UDP() => Some(ai::UDP),
202209
p if p == uvll::rust_IPPROTO_TCP() => Some(ai::TCP),
@@ -208,6 +215,9 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
208215
p if p == uvll::rust_SOCK_RAW() => Some(ai::Raw),
209216
_ => None,
210217
};
218+
*/
219+
let protocol = None;
220+
let socktype = None;
211221

212222
addrs.push(ai::Info {
213223
address: rustaddr,

src/libstd/rt/uv/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
336336
/// The uv buffer type
337337
pub type Buf = uvll::uv_buf_t;
338338
339+
pub fn empty_buf() -> Buf {
340+
uvll::uv_buf_t {
341+
base: null(),
342+
len: 0,
343+
}
344+
}
345+
339346
/// Borrow a slice to a Buf
340347
pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
341348
let data = vec::raw::to_ptr(v);

src/libstd/rt/uv/net.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rt::uv::uvll;
1414
use rt::uv::uvll::*;
1515
use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback};
1616
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle,
17-
status_to_maybe_uv_error, vec_to_uv_buf};
17+
status_to_maybe_uv_error, empty_buf};
1818
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
1919
use vec;
2020
use str;
@@ -119,23 +119,17 @@ impl Watcher for StreamWatcher { }
119119

120120
impl StreamWatcher {
121121
pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
122-
{
123-
let data = self.get_watcher_data();
124-
data.alloc_cb = Some(alloc);
125-
data.read_cb = Some(cb);
126-
}
127-
128-
let ret = unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb) };
129-
130-
if ret != 0 {
131-
// uvll::read_start failed, so read_cb will not be called.
132-
// Call it manually for scheduling.
133-
call_read_cb(self.native_handle(), ret as ssize_t);
134-
}
135-
136-
fn call_read_cb(stream: *uvll::uv_stream_t, errno: ssize_t) {
137-
#[fixed_stack_segment]; #[inline(never)];
138-
read_cb(stream, errno, vec_to_uv_buf(~[]));
122+
unsafe {
123+
match uvll::read_start(self.native_handle(), alloc_cb, read_cb) {
124+
0 => {
125+
let data = self.get_watcher_data();
126+
data.alloc_cb = Some(alloc);
127+
data.read_cb = Some(cb);
128+
}
129+
n => {
130+
cb(*self, 0, empty_buf(), Some(UvError(n)))
131+
}
132+
}
139133
}
140134

141135
extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
@@ -163,16 +157,21 @@ impl StreamWatcher {
163157
}
164158

165159
pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
166-
{
167-
let data = self.get_watcher_data();
168-
assert!(data.write_cb.is_none());
169-
data.write_cb = Some(cb);
170-
}
171-
172160
let req = WriteRequest::new();
173-
unsafe {
174-
assert_eq!(0, uvll::write(req.native_handle(), self.native_handle(), [buf], write_cb));
175-
}
161+
return unsafe {
162+
match uvll::write(req.native_handle(), self.native_handle(),
163+
[buf], write_cb) {
164+
0 => {
165+
let data = self.get_watcher_data();
166+
assert!(data.write_cb.is_none());
167+
data.write_cb = Some(cb);
168+
}
169+
n => {
170+
req.delete();
171+
cb(*self, Some(UvError(n)))
172+
}
173+
}
174+
};
176175

177176
extern fn write_cb(req: *uvll::uv_write_t, status: c_int) {
178177
let write_request: WriteRequest = NativeHandle::from_native_handle(req);

src/libstd/rt/uv/uvio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl EventLoop for UvEventLoop {
229229
}
230230
}
231231

232-
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback{
232+
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback {
233233
~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback
234234
}
235235

src/libstd/rt/uv/uvll.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,17 +1146,18 @@ extern {
11461146
height: *c_int) -> c_int;
11471147
fn rust_uv_guess_handle(fd: c_int) -> uv_handle_type;
11481148

1149+
// XXX: see comments in addrinfo.rs
11491150
// These should all really be constants...
1150-
#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int;
1151-
#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int;
1152-
#[rust_stack] pub fn rust_SOCK_RAW() -> c_int;
1153-
#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int;
1154-
#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int;
1155-
#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int;
1156-
#[rust_stack] pub fn rust_AI_ALL() -> c_int;
1157-
#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int;
1158-
#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int;
1159-
#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int;
1160-
#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int;
1161-
#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int;
1151+
//#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int;
1152+
//#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int;
1153+
//#[rust_stack] pub fn rust_SOCK_RAW() -> c_int;
1154+
//#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int;
1155+
//#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int;
1156+
//#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int;
1157+
//#[rust_stack] pub fn rust_AI_ALL() -> c_int;
1158+
//#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int;
1159+
//#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int;
1160+
//#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int;
1161+
//#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int;
1162+
//#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int;
11621163
}

src/libstd/run.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use libc;
1919
use prelude::*;
2020
use rt::io::native::process;
2121
use rt::io;
22+
use rt::io::extensions::ReaderUtil;
2223
use task;
2324

2425
/**
@@ -189,18 +190,6 @@ impl Process {
189190
let output = Cell::new(self.inner.take_output());
190191
let error = Cell::new(self.inner.take_error());
191192

192-
fn read_everything(r: &mut io::Reader) -> ~[u8] {
193-
let mut ret = ~[];
194-
let mut buf = [0, ..1024];
195-
loop {
196-
match r.read(buf) {
197-
Some(n) => { ret.push_all(buf.slice_to(n)); }
198-
None => break
199-
}
200-
}
201-
return ret;
202-
}
203-
204193
// Spawn two entire schedulers to read both stdout and sterr
205194
// in parallel so we don't deadlock while blocking on one
206195
// or the other. FIXME (#2625): Surely there's a much more
@@ -210,13 +199,13 @@ impl Process {
210199
let ch_clone = ch.clone();
211200
do task::spawn_sched(task::SingleThreaded) {
212201
match error.take() {
213-
Some(ref mut e) => ch.send((2, read_everything(*e))),
202+
Some(ref mut e) => ch.send((2, e.read_to_end())),
214203
None => ch.send((2, ~[]))
215204
}
216205
}
217206
do task::spawn_sched(task::SingleThreaded) {
218207
match output.take() {
219-
Some(ref mut e) => ch_clone.send((1, read_everything(*e))),
208+
Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
220209
None => ch_clone.send((1, ~[]))
221210
}
222211
}

0 commit comments

Comments
 (0)