Skip to content

Commit 6c478c7

Browse files
committed
Merge remote-tracking branch 'brson/io' into incoming
Conflicts: mk/rt.mk src/libcore/run.rs
2 parents baa1c18 + f8dffc6 commit 6c478c7

Some content is hidden

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

42 files changed

+1399
-347
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ $(foreach target,$(CFG_TARGET_TRIPLES),\
238238

239239
CORELIB_CRATE := $(S)src/libcore/core.rc
240240
CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
241-
core.rc *.rs */*.rs */*/*rs))
241+
core.rc *.rs */*.rs */*/*rs */*/*/*rs))
242242

243243
######################################################################
244244
# Standard library variables

mk/docs.mk

+35-39
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,8 @@ DOCS :=
1616

1717

1818
######################################################################
19-
# Pandoc (reference-manual related)
19+
# Docs, from pandoc, rustdoc (which runs pandoc), and node
2020
######################################################################
21-
ifeq ($(CFG_PANDOC),)
22-
$(info cfg: no pandoc found, omitting doc/rust.pdf)
23-
else
24-
25-
ifeq ($(CFG_NODE),)
26-
$(info cfg: no node found, omitting doc/tutorial.html)
27-
else
2821

2922
doc/rust.css: rust.css
3023
@$(call E, cp: $@)
@@ -34,6 +27,18 @@ doc/manual.css: manual.css
3427
@$(call E, cp: $@)
3528
$(Q)cp -a $< $@ 2> /dev/null
3629

30+
ifeq ($(CFG_PANDOC),)
31+
$(info cfg: no pandoc found, omitting docs)
32+
NO_DOCS = 1
33+
endif
34+
35+
ifeq ($(CFG_NODE),)
36+
$(info cfg: no node found, omitting docs)
37+
NO_DOCS = 1
38+
endif
39+
40+
ifneq ($(NO_DOCS),1)
41+
3742
DOCS += doc/rust.html
3843
doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css
3944
@$(call E, pandoc: $@)
@@ -47,19 +52,8 @@ doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css
4752
--css=manual.css \
4853
--include-before-body=doc/version_info.html \
4954
--output=$@
50-
endif
5155

52-
ifeq ($(CFG_PDFLATEX),)
53-
$(info cfg: no pdflatex found, omitting doc/rust.pdf)
54-
else
55-
ifeq ($(CFG_XETEX),)
56-
$(info cfg: no xetex found, disabling doc/rust.pdf)
57-
else
58-
ifeq ($(CFG_LUATEX),)
59-
$(info cfg: lacking luatex, disabling pdflatex)
60-
else
61-
62-
DOCS += doc/rust.pdf
56+
DOCS += doc/rust.tex
6357
doc/rust.tex: rust.md doc/version.md
6458
@$(call E, pandoc: $@)
6559
$(Q)$(CFG_NODE) $(S)doc/prep.js $< | \
@@ -70,17 +64,6 @@ doc/rust.tex: rust.md doc/version.md
7064
--from=markdown --to=latex \
7165
--output=$@
7266

73-
doc/rust.pdf: doc/rust.tex
74-
@$(call E, pdflatex: $@)
75-
$(Q)$(CFG_PDFLATEX) \
76-
-interaction=batchmode \
77-
-output-directory=doc \
78-
$<
79-
80-
endif
81-
endif
82-
endif
83-
8467
DOCS += doc/rustpkg.html
8568
doc/rustpkg.html: rustpkg.md doc/version_info.html doc/rust.css doc/manual.css
8669
@$(call E, pandoc: $@)
@@ -95,13 +78,6 @@ doc/rustpkg.html: rustpkg.md doc/version_info.html doc/rust.css doc/manual.css
9578
--include-before-body=doc/version_info.html \
9679
--output=$@
9780

98-
######################################################################
99-
# Node (tutorial related)
100-
######################################################################
101-
ifeq ($(CFG_NODE),)
102-
$(info cfg: no node found, omitting doc/tutorial.html)
103-
else
104-
10581
DOCS += doc/tutorial.html
10682
doc/tutorial.html: tutorial.md doc/version_info.html doc/rust.css
10783
@$(call E, pandoc: $@)
@@ -153,9 +129,29 @@ doc/tutorial-tasks.html: tutorial-tasks.md doc/version_info.html doc/rust.css
153129
--include-before-body=doc/version_info.html \
154130
--output=$@
155131

132+
ifeq ($(CFG_PDFLATEX),)
133+
$(info cfg: no pdflatex found, omitting doc/rust.pdf)
134+
else
135+
ifeq ($(CFG_XETEX),)
136+
$(info cfg: no xetex found, disabling doc/rust.pdf)
137+
else
138+
ifeq ($(CFG_LUATEX),)
139+
$(info cfg: lacking luatex, disabling pdflatex)
140+
else
141+
142+
DOCS += doc/rust.pdf
143+
doc/rust.pdf: doc/rust.tex
144+
@$(call E, pdflatex: $@)
145+
$(Q)$(CFG_PDFLATEX) \
146+
-interaction=batchmode \
147+
-output-directory=doc \
148+
$<
149+
150+
endif
151+
endif
156152
endif
157-
endif
158153

154+
endif # No pandoc / node
159155

160156
######################################################################
161157
# LLnextgen (grammar analysis from refman)

src/libcore/condition.rs

+23
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,27 @@ mod test {
192192

193193
assert!(trapped);
194194
}
195+
196+
// Issue #6009
197+
mod m {
198+
condition! {
199+
sadness: int -> int;
200+
}
201+
202+
mod n {
203+
use super::sadness;
204+
205+
#[test]
206+
fn test_conditions_are_public() {
207+
let mut trapped = false;
208+
do sadness::cond.trap(|_| {
209+
trapped = true;
210+
0
211+
}).in {
212+
sadness::cond.raise(0);
213+
}
214+
assert!(trapped);
215+
}
216+
}
217+
}
195218
}

src/libcore/core.rc

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub mod linkhack {
124124
}
125125
}
126126

127+
// Internal macros
128+
mod macros;
129+
127130
/* The Prelude. */
128131

129132
pub mod prelude;

src/libcore/macros.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[macro_escape];
12+
13+
// Some basic logging
14+
macro_rules! rtdebug_ (
15+
($( $arg:expr),+) => ( {
16+
dumb_println(fmt!( $($arg),+ ));
17+
18+
fn dumb_println(s: &str) {
19+
use io::WriterUtil;
20+
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
21+
dbg.write_str(s);
22+
dbg.write_str("\n");
23+
}
24+
25+
} )
26+
)
27+
28+
// An alternate version with no output, for turning off logging
29+
macro_rules! rtdebug (
30+
($( $arg:expr),+) => ( $(let _ = $arg)*; )
31+
)
32+
33+
macro_rules! abort(
34+
($( $msg:expr),+) => ( {
35+
rtdebug!($($msg),+);
36+
37+
unsafe { ::libc::abort(); }
38+
} )
39+
)
File renamed without changes.

src/libcore/rt/io/file.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
// except according to those terms.
1010

1111
use prelude::*;
12-
use super::misc::PathLike;
12+
use super::support::PathLike;
1313
use super::{Reader, Writer, Seek, Close};
14-
use super::{IoError, SeekStyle};
15-
16-
/// Open a file with the default FileMode and FileAccess
17-
/// # XXX are there sane defaults here?
18-
pub fn open_file<P: PathLike>(_path: &P) -> FileStream { fail!() }
14+
use super::SeekStyle;
1915

2016
/// # XXX
2117
/// * Ugh, this is ridiculous. What is the best way to represent these options?
@@ -46,7 +42,7 @@ impl FileStream {
4642
pub fn open<P: PathLike>(_path: &P,
4743
_mode: FileMode,
4844
_access: FileAccess
49-
) -> Result<FileStream, IoError> {
45+
) -> Option<FileStream> {
5046
fail!()
5147
}
5248
}

src/libcore/rt/io/mem.rs

+62-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
use prelude::*;
1919
use super::*;
20-
20+
use cmp::min;
2121

2222
/// Writes to an owned, growable byte vector
2323
pub struct MemWriter {
@@ -29,13 +29,15 @@ impl MemWriter {
2929
}
3030

3131
impl Writer for MemWriter {
32-
fn write(&mut self, _buf: &[u8]) { fail!() }
32+
fn write(&mut self, buf: &[u8]) {
33+
self.buf.push_all(buf)
34+
}
3335

3436
fn flush(&mut self) { /* no-op */ }
3537
}
3638

3739
impl Seek for MemWriter {
38-
fn tell(&self) -> u64 { fail!() }
40+
fn tell(&self) -> u64 { self.buf.len() as u64 }
3941

4042
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
4143
}
@@ -77,13 +79,27 @@ impl MemReader {
7779
}
7880

7981
impl Reader for MemReader {
80-
fn read(&mut self, _buf: &mut [u8]) -> Option<uint> { fail!() }
82+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
83+
{ if self.eof() { return None; } }
84+
85+
let write_len = min(buf.len(), self.buf.len() - self.pos);
86+
{
87+
let input = self.buf.slice(self.pos, self.pos + write_len);
88+
let output = vec::mut_slice(buf, 0, write_len);
89+
assert!(input.len() == output.len());
90+
vec::bytes::copy_memory(output, input, write_len);
91+
}
92+
self.pos += write_len;
93+
assert!(self.pos <= self.buf.len());
8194

82-
fn eof(&mut self) -> bool { fail!() }
95+
return Some(write_len);
96+
}
97+
98+
fn eof(&mut self) -> bool { self.pos == self.buf.len() }
8399
}
84100

85101
impl Seek for MemReader {
86-
fn tell(&self) -> u64 { fail!() }
102+
fn tell(&self) -> u64 { self.pos as u64 }
87103

88104
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
89105
}
@@ -163,4 +179,43 @@ impl<'self> Seek for BufReader<'self> {
163179
fn tell(&self) -> u64 { fail!() }
164180

165181
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
166-
}
182+
}
183+
184+
#[cfg(test)]
185+
mod test {
186+
use prelude::*;
187+
use super::*;
188+
189+
#[test]
190+
fn test_mem_writer() {
191+
let mut writer = MemWriter::new();
192+
assert!(writer.tell() == 0);
193+
writer.write([0]);
194+
assert!(writer.tell() == 1);
195+
writer.write([1, 2, 3]);
196+
writer.write([4, 5, 6, 7]);
197+
assert!(writer.tell() == 8);
198+
assert!(writer.inner() == ~[0, 1, 2, 3, 4, 5 , 6, 7]);
199+
}
200+
201+
#[test]
202+
fn test_mem_reader() {
203+
let mut reader = MemReader::new(~[0, 1, 2, 3, 4, 5, 6, 7]);
204+
let mut buf = [];
205+
assert!(reader.read(buf) == Some(0));
206+
assert!(reader.tell() == 0);
207+
let mut buf = [0];
208+
assert!(reader.read(buf) == Some(1));
209+
assert!(reader.tell() == 1);
210+
assert!(buf == [0]);
211+
let mut buf = [0, ..4];
212+
assert!(reader.read(buf) == Some(4));
213+
assert!(reader.tell() == 5);
214+
assert!(buf == [1, 2, 3, 4]);
215+
assert!(reader.read(buf) == Some(3));
216+
assert!(buf.slice(0, 3) == [5, 6, 7]);
217+
assert!(reader.eof());
218+
assert!(reader.read(buf) == None);
219+
assert!(reader.eof());
220+
}
221+
}

0 commit comments

Comments
 (0)