Skip to content

Commit 2816809

Browse files
committed
---
yaml --- r: 150462 b: refs/heads/try2 c: 129cf09 h: refs/heads/master v: v3
1 parent 5eeb6e1 commit 2816809

File tree

33 files changed

+499
-411
lines changed

33 files changed

+499
-411
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: 361d79142a011078437559af33b8fab9b4d6e408
8+
refs/heads/try2: 129cf09209f457cd79e5c3cdf513fd65e488d29e
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-pointers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ sense, they're simple: just keep whatever ownership the data already has. For
332332
example:
333333

334334
~~~rust
335+
use std::num::sqrt;
336+
335337
struct Point {
336338
x: f32,
337339
y: f32,
@@ -341,7 +343,7 @@ fn compute_distance(p1: &Point, p2: &Point) -> f32 {
341343
let x_d = p1.x - p2.x;
342344
let y_d = p1.y - p2.y;
343345

344-
(x_d * x_d + y_d * y_d).sqrt()
346+
sqrt(x_d * x_d + y_d * y_d)
345347
}
346348

347349
fn main() {

branches/try2/src/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,14 +826,14 @@ Use declarations support a number of convenient shortcuts:
826826
An example of `use` declarations:
827827

828828
~~~~
829-
use std::iter::range_step;
829+
use std::num::sin;
830830
use std::option::{Some, None};
831831
832832
# fn foo<T>(_: T){}
833833
834834
fn main() {
835-
// Equivalent to 'std::iter::range_step(0, 10, 2);'
836-
range_step(0, 10, 2);
835+
// Equivalent to 'std::num::sin(1.0);'
836+
sin(1.0);
837837
838838
// Equivalent to 'foo(~[std::option::Some(1.0), std::option::None]);'
839839
foo(~[Some(1.0), None]);

branches/try2/src/doc/tutorial.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,13 @@ matching in order to bind names to the contents of data types.
504504
505505
~~~~
506506
use std::f64;
507+
use std::num::atan;
507508
fn angle(vector: (f64, f64)) -> f64 {
508509
let pi = f64::consts::PI;
509510
match vector {
510511
(0.0, y) if y < 0.0 => 1.5 * pi,
511512
(0.0, _) => 0.5 * pi,
512-
(x, y) => (y / x).atan()
513+
(x, y) => atan(y / x)
513514
}
514515
}
515516
~~~~
@@ -1429,11 +1430,12 @@ bad, but often copies are expensive. So we’d like to define a function
14291430
that takes the points by pointer. We can use references to do this:
14301431
14311432
~~~
1433+
use std::num::sqrt;
14321434
# struct Point { x: f64, y: f64 }
14331435
fn compute_distance(p1: &Point, p2: &Point) -> f64 {
14341436
let x_d = p1.x - p2.x;
14351437
let y_d = p1.y - p2.y;
1436-
(x_d * x_d + y_d * y_d).sqrt()
1438+
sqrt(x_d * x_d + y_d * y_d)
14371439
}
14381440
~~~
14391441
@@ -2301,7 +2303,7 @@ impl Shape for Circle {
23012303
fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } }
23022304
}
23032305
impl Shape for Square {
2304-
fn new(area: f64) -> Square { Square { length: area.sqrt() } }
2306+
fn new(area: f64) -> Square { Square { length: (area).sqrt() } }
23052307
}
23062308
23072309
let area = 42.5;

branches/try2/src/libcollections/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub mod bench {
5252
map: &mut M,
5353
bh: &mut BenchHarness) {
5454
// setup
55-
let mut rng = rand::weak_rng();
55+
let mut rng = rand::XorShiftRng::new();
5656

5757
map.clear();
5858
for _ in range(0, n) {
@@ -89,7 +89,7 @@ pub mod bench {
8989
map: &mut M,
9090
bh: &mut BenchHarness) {
9191
// setup
92-
let mut rng = rand::weak_rng();
92+
let mut rng = rand::XorShiftRng::new();
9393
let mut keys = slice::from_fn(n, |_| rng.gen::<uint>() % n);
9494

9595
for k in keys.iter() {

branches/try2/src/libgreen/sched.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,7 @@ impl ClosureConverter for UnsafeTaskReceiver {
967967
// worry there.
968968
#[cfg(windows)]
969969
fn new_sched_rng() -> XorShiftRng {
970-
match XorShiftRng::new() {
971-
Ok(r) => r,
972-
Err(e) => {
973-
rtabort!("sched: failed to create seeded RNG: {}", e)
974-
}
975-
}
970+
XorShiftRng::new()
976971
}
977972
#[cfg(unix)]
978973
fn new_sched_rng() -> XorShiftRng {

branches/try2/src/libnative/io/addrinfo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ extern "system" {
9696

9797
#[cfg(windows)]
9898
fn get_error(_: c_int) -> IoError {
99+
use super::translate_error;
100+
99101
unsafe {
100-
IoError::from_errno(WSAGetLastError() as uint, true)
102+
translate_error(WSAGetLastError() as i32, true)
101103
}
102104
}
103105

branches/try2/src/libnative/io/mod.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,73 @@ fn unimpl() -> IoError {
8686
}
8787
}
8888

89-
fn last_error() -> IoError {
90-
IoError::last_error()
89+
fn translate_error(errno: i32, detail: bool) -> IoError {
90+
#[cfg(windows)]
91+
fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
92+
match errno {
93+
libc::EOF => (io::EndOfFile, "end of file"),
94+
libc::ERROR_NO_DATA => (io::BrokenPipe, "the pipe is being closed"),
95+
libc::ERROR_FILE_NOT_FOUND => (io::FileNotFound, "file not found"),
96+
libc::ERROR_INVALID_NAME => (io::InvalidInput, "invalid file name"),
97+
libc::WSAECONNREFUSED => (io::ConnectionRefused, "connection refused"),
98+
libc::WSAECONNRESET => (io::ConnectionReset, "connection reset"),
99+
libc::WSAEACCES => (io::PermissionDenied, "permission denied"),
100+
libc::WSAEWOULDBLOCK => {
101+
(io::ResourceUnavailable, "resource temporarily unavailable")
102+
}
103+
libc::WSAENOTCONN => (io::NotConnected, "not connected"),
104+
libc::WSAECONNABORTED => (io::ConnectionAborted, "connection aborted"),
105+
libc::WSAEADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
106+
libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"),
107+
libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"),
108+
109+
// libuv maps this error code to EISDIR. we do too. if it is found
110+
// to be incorrect, we can add in some more machinery to only
111+
// return this message when ERROR_INVALID_FUNCTION after certain
112+
// win32 calls.
113+
libc::ERROR_INVALID_FUNCTION => (io::InvalidInput,
114+
"illegal operation on a directory"),
115+
116+
_ => (io::OtherIoError, "unknown error")
117+
}
118+
}
119+
120+
#[cfg(not(windows))]
121+
fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
122+
// FIXME: this should probably be a bit more descriptive...
123+
match errno {
124+
libc::EOF => (io::EndOfFile, "end of file"),
125+
libc::ECONNREFUSED => (io::ConnectionRefused, "connection refused"),
126+
libc::ECONNRESET => (io::ConnectionReset, "connection reset"),
127+
libc::EPERM | libc::EACCES =>
128+
(io::PermissionDenied, "permission denied"),
129+
libc::EPIPE => (io::BrokenPipe, "broken pipe"),
130+
libc::ENOTCONN => (io::NotConnected, "not connected"),
131+
libc::ECONNABORTED => (io::ConnectionAborted, "connection aborted"),
132+
libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
133+
libc::EADDRINUSE => (io::ConnectionRefused, "address in use"),
134+
libc::ENOENT => (io::FileNotFound, "no such file or directory"),
135+
libc::EISDIR => (io::InvalidInput, "illegal operation on a directory"),
136+
137+
// These two constants can have the same value on some systems, but
138+
// different values on others, so we can't use a match clause
139+
x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
140+
(io::ResourceUnavailable, "resource temporarily unavailable"),
141+
142+
_ => (io::OtherIoError, "unknown error")
143+
}
144+
}
145+
146+
let (kind, desc) = get_err(errno);
147+
IoError {
148+
kind: kind,
149+
desc: desc,
150+
detail: if detail {Some(os::last_os_error())} else {None},
151+
}
91152
}
92153

154+
fn last_error() -> IoError { translate_error(os::errno() as i32, true) }
155+
93156
// unix has nonzero values as errors
94157
fn mkerr_libc(ret: libc::c_int) -> IoResult<()> {
95158
if ret != 0 {

branches/try2/src/libnative/io/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn last_error() -> io::IoError {
120120
extern "system" {
121121
fn WSAGetLastError() -> libc::c_int;
122122
}
123-
io::IoError::from_errno(unsafe { WSAGetLastError() } as uint, true)
123+
super::translate_error(unsafe { WSAGetLastError() }, true)
124124
}
125125

126126
#[cfg(not(windows))]

branches/try2/src/libnative/io/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ fn spawn_process_os(config: p::ProcessConfig,
481481
(bytes[1] << 16) as i32 |
482482
(bytes[2] << 8) as i32 |
483483
(bytes[3] << 0) as i32;
484-
Err(io::IoError::from_errno(errno as uint, false))
484+
Err(super::translate_error(errno, false))
485485
}
486486
Err(e) => {
487487
assert!(e.kind == io::BrokenPipe ||

branches/try2/src/librand/distributions/exponential.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mod bench {
126126

127127
#[bench]
128128
fn rand_exp(bh: &mut BenchHarness) {
129-
let mut rng = XorShiftRng::new().unwrap();
129+
let mut rng = XorShiftRng::new();
130130
let mut exp = Exp::new(2.71828 * 3.14159);
131131

132132
bh.iter(|| {

branches/try2/src/librand/distributions/gamma.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! The Gamma and derived distributions.
1212
1313
use std::num::Float;
14+
use std::num;
1415
use {Rng, Open01};
1516
use super::normal::StandardNormal;
1617
use super::{IndependentSample, Sample, Exp};
@@ -113,7 +114,7 @@ impl GammaLargeShape {
113114
GammaLargeShape {
114115
shape: shape,
115116
scale: scale,
116-
c: 1. / (9. * d).sqrt(),
117+
c: 1. / num::sqrt(9. * d),
117118
d: d
118119
}
119120
}
@@ -142,7 +143,7 @@ impl IndependentSample<f64> for GammaSmallShape {
142143
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
143144
let Open01(u) = rng.gen::<Open01<f64>>();
144145

145-
self.large_shape.ind_sample(rng) * u.powf(&self.inv_shape)
146+
self.large_shape.ind_sample(rng) * num::powf(u, self.inv_shape)
146147
}
147148
}
148149
impl IndependentSample<f64> for GammaLargeShape {
@@ -159,7 +160,7 @@ impl IndependentSample<f64> for GammaLargeShape {
159160

160161
let x_sqr = x * x;
161162
if u < 1.0 - 0.0331 * x_sqr * x_sqr ||
162-
u.ln() < 0.5 * x_sqr + self.d * (1.0 - v + v.ln()) {
163+
num::ln(u) < 0.5 * x_sqr + self.d * (1.0 - v + num::ln(v)) {
163164
return self.d * v * self.scale
164165
}
165166
}
@@ -369,14 +370,14 @@ mod bench {
369370
use self::test::BenchHarness;
370371
use std::mem::size_of;
371372
use distributions::IndependentSample;
372-
use {XorShiftRng, RAND_BENCH_N};
373+
use {StdRng, RAND_BENCH_N};
373374
use super::Gamma;
374375

375376

376377
#[bench]
377378
fn bench_gamma_large_shape(bh: &mut BenchHarness) {
378379
let gamma = Gamma::new(10., 1.0);
379-
let mut rng = XorShiftRng::new().unwrap();
380+
let mut rng = StdRng::new();
380381

381382
bh.iter(|| {
382383
for _ in range(0, RAND_BENCH_N) {
@@ -389,7 +390,7 @@ mod bench {
389390
#[bench]
390391
fn bench_gamma_small_shape(bh: &mut BenchHarness) {
391392
let gamma = Gamma::new(0.1, 1.0);
392-
let mut rng = XorShiftRng::new().unwrap();
393+
let mut rng = StdRng::new();
393394

394395
bh.iter(|| {
395396
for _ in range(0, RAND_BENCH_N) {

branches/try2/src/librand/distributions/normal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ mod bench {
193193

194194
#[bench]
195195
fn rand_normal(bh: &mut BenchHarness) {
196-
let mut rng = XorShiftRng::new().unwrap();
196+
let mut rng = XorShiftRng::new();
197197
let mut normal = Normal::new(-2.71828, 3.14159);
198198

199199
bh.iter(|| {

0 commit comments

Comments
 (0)