Skip to content

Commit b7ed5cc

Browse files
committed
---
yaml --- r: 146359 b: refs/heads/try2 c: 7cff3c7 h: refs/heads/master i: 146357: 5f88d2b 146355: 2030b3a 146351: e63674d v: v3
1 parent 8785fe5 commit b7ed5cc

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 415a04315e660aa95473493d8031322f3cbd6bbe
8+
refs/heads/try2: 7cff3c74b8d313154379ab73f18baab57c09bd33
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rand/reseeding.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<R: Rng, Rsdr: Reseeder<R>> Rng for ReseedingRng<R, Rsdr> {
7272
fn fill_bytes(&mut self, dest: &mut [u8]) {
7373
self.reseed_if_necessary();
7474
self.bytes_generated += dest.len();
75-
self.fill_bytes(dest)
75+
self.rng.fill_bytes(dest)
7676
}
7777
}
7878

@@ -201,4 +201,24 @@ mod test {
201201
let string2 = r.gen_ascii_str(100);
202202
assert_eq!(string1, string2);
203203
}
204+
205+
static fill_bytes_v_len: uint = 13579;
206+
#[test]
207+
fn test_rng_fill_bytes() {
208+
use rand::task_rng;
209+
let mut v = ~[0u8, .. fill_bytes_v_len];
210+
task_rng().fill_bytes(v);
211+
212+
// Sanity test: if we've gotten here, `fill_bytes` has not infinitely
213+
// recursed.
214+
assert_eq!(v.len(), fill_bytes_v_len);
215+
216+
// To test that `fill_bytes` actually did something, check that the
217+
// average of `v` is not 0.
218+
let mut sum = 0.0;
219+
for &x in v.iter() {
220+
sum += x as f64;
221+
}
222+
assert!(sum / v.len() as f64 != 0.0);
223+
}
204224
}

branches/try2/src/libstd/rt/io/stdio.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,17 @@ pub fn stderr() -> StdWriter {
112112
do src(libc::STDERR_FILENO, false) |src| { StdWriter { inner: src } }
113113
}
114114

115-
/// Executes a closure with the local task's handle on stdout. By default, this
116-
/// stream is a buffering stream, so the handled yielded to the given closure
117-
/// can be used to flush the stdout stream (if necessary). The buffering used is
118-
/// line-buffering when stdout is attached to a terminal, and a fixed sized
119-
/// buffer if it is not attached to a terminal.
120-
///
121-
/// Note that handles generated via the `stdout()` function all output to the
122-
/// same stream, and output among all task may be interleaved as a result of
123-
/// this. This is provided to have access to the default stream for `print` and
124-
/// `println` (and the related macros) for this task.
125-
///
126-
/// Also note that logging macros do not use this stream. Using the logging
127-
/// macros will emit output to stderr.
128-
pub fn with_task_stdout(f: &fn(&mut Writer)) {
115+
// Helper to access the local task's stdout handle
116+
//
117+
// Note that this is not a safe function to expose because you can create an
118+
// aliased pointer very easily:
119+
//
120+
// do with_task_stdout |io1| {
121+
// do with_task_stdout |io2| {
122+
// // io1 aliases io2
123+
// }
124+
// }
125+
fn with_task_stdout(f: &fn(&mut Writer)) {
129126
use rt::local::Local;
130127
use rt::task::Task;
131128

@@ -153,6 +150,22 @@ pub fn with_task_stdout(f: &fn(&mut Writer)) {
153150
}
154151
}
155152

153+
/// Flushes the local task's stdout handle.
154+
///
155+
/// By default, this stream is a buffering stream, flushing may be necessary to
156+
/// ensure output is on the terminal screen. The buffering used is
157+
/// line-buffering when stdout is attached to a terminal, and a fixed sized
158+
/// buffer if it is not attached to a terminal.
159+
///
160+
/// Note that logging macros do not use this stream. Using the logging macros
161+
/// will emit output to stderr, and while they are line buffered the log
162+
/// messages are always terminated in a newline (no need to flush).
163+
pub fn flush() {
164+
do with_task_stdout |io| {
165+
io.flush();
166+
}
167+
}
168+
156169
/// Prints a string to the stdout of the current process. No newline is emitted
157170
/// after the string is printed.
158171
pub fn print(s: &str) {

0 commit comments

Comments
 (0)