Skip to content

Commit 2853791

Browse files
committed
---
yaml --- r: 55601 b: refs/heads/master c: bd75463 h: refs/heads/master i: 55599: 57928bc v: v3
1 parent bdb9436 commit 2853791

Some content is hidden

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

65 files changed

+1752
-862
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d2a81b95c3e2ccfdba0324caae531ce3528ed4e2
2+
refs/heads/master: bd75463839f0b52283b0806166c19eb0ffa75732
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

trunk/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ config.stamp
8686
.DS_Store
8787
src/etc/dl
8888
.settings/
89+
build/

trunk/doc/tutorial.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,9 @@ do spawn {
16691669
}
16701670
~~~~
16711671

1672+
If you want to see the output of `debug!` statements, you will need to turn on `debug!` logging.
1673+
To enable `debug!` logging, set the RUST_LOG environment variable to `debug` (e.g., with bash, `export RUST_LOG=debug`)
1674+
16721675
## For loops
16731676

16741677
The most common way to express iteration in Rust is with a `for`

trunk/mk/rt.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ RUNTIME_CXXS_$(1) := \
7676
rt/boxed_region.cpp \
7777
rt/arch/$$(HOST_$(1))/context.cpp \
7878
rt/arch/$$(HOST_$(1))/gpr.cpp \
79-
rt/rust_android_dummy.cpp
79+
rt/rust_android_dummy.cpp \
80+
rt/rust_test_helpers.cpp
8081

8182
RUNTIME_CS_$(1) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
8283

trunk/src/etc/x86.supp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,11 @@
654654
fun:_ZN5visit30visit_struct_dtor_helper_*
655655
...
656656
}
657+
658+
{
659+
llvm-optimization-reads-uninitialized-memory-16
660+
Memcheck:Cond
661+
fun:_ZN7ast_map6map_fn*
662+
fun:_ZN5visit30visit_struct_dtor_helper*
663+
...
664+
}

trunk/src/libcore/iterator.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub trait IteratorUtil<A> {
2222
// FIXME: #5898: should be called map
2323
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
2424
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, Self>;
25+
fn enumerate(self) -> EnumerateIterator<Self>;
2526
fn advance(&mut self, f: &fn(A) -> bool);
2627
}
2728

@@ -42,6 +43,11 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
4243
FilterIterator{iter: self, predicate: predicate}
4344
}
4445

46+
#[inline(always)]
47+
fn enumerate(self) -> EnumerateIterator<T> {
48+
EnumerateIterator{iter: self, count: 0}
49+
}
50+
4551
/// A shim implementing the `for` loop iteration protocol for iterator objects
4652
#[inline]
4753
fn advance(&mut self, f: &fn(A) -> bool) {
@@ -104,3 +110,22 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
104110
}
105111
}
106112
}
113+
114+
pub struct EnumerateIterator<T> {
115+
priv iter: T,
116+
priv count: uint
117+
}
118+
119+
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
120+
#[inline]
121+
fn next(&mut self) -> Option<(uint, A)> {
122+
match self.iter.next() {
123+
Some(a) => {
124+
let ret = Some((self.count, a));
125+
self.count += 1;
126+
ret
127+
}
128+
_ => None
129+
}
130+
}
131+
}

trunk/src/libcore/num/int-template.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -199,30 +199,6 @@ impl ops::Modulo<T,T> for T {
199199
impl ops::Neg<T> for T {
200200
fn neg(&self) -> T { -*self }
201201
}
202-
#[cfg(notest)]
203-
impl ops::BitOr<T,T> for T {
204-
fn bitor(&self, other: &T) -> T { *self | *other }
205-
}
206-
#[cfg(notest)]
207-
impl ops::BitAnd<T,T> for T {
208-
fn bitand(&self, other: &T) -> T { *self & *other }
209-
}
210-
#[cfg(notest)]
211-
impl ops::BitXor<T,T> for T {
212-
fn bitxor(&self, other: &T) -> T { *self ^ *other }
213-
}
214-
#[cfg(notest)]
215-
impl ops::Shl<T,T> for T {
216-
fn shl(&self, other: &T) -> T { *self << *other }
217-
}
218-
#[cfg(notest)]
219-
impl ops::Shr<T,T> for T {
220-
fn shr(&self, other: &T) -> T { *self >> *other }
221-
}
222-
#[cfg(notest)]
223-
impl ops::Not<T> for T {
224-
fn not(&self) -> T { !*self }
225-
}
226202
227203
// String conversion functions and impl str -> num
228204
@@ -307,16 +283,6 @@ mod tests {
307283
use super::inst::T;
308284
use prelude::*;
309285
310-
#[test]
311-
fn test_bitwise_ops() {
312-
assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T)));
313-
assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T)));
314-
assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T)));
315-
assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T)));
316-
assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T)));
317-
assert!(-(0b11 as T) - (1 as T) == (0b11 as T).not());
318-
}
319-
320286
#[test]
321287
fn test_from_str() {
322288
assert!(from_str(~"0") == Some(0 as T));

trunk/src/libcore/num/uint-template.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,30 +164,6 @@ impl ops::Modulo<T,T> for T {
164164
impl ops::Neg<T> for T {
165165
fn neg(&self) -> T { -*self }
166166
}
167-
#[cfg(notest)]
168-
impl ops::BitOr<T,T> for T {
169-
fn bitor(&self, other: &T) -> T { *self | *other }
170-
}
171-
#[cfg(notest)]
172-
impl ops::BitAnd<T,T> for T {
173-
fn bitand(&self, other: &T) -> T { *self & *other }
174-
}
175-
#[cfg(notest)]
176-
impl ops::BitXor<T,T> for T {
177-
fn bitxor(&self, other: &T) -> T { *self ^ *other }
178-
}
179-
#[cfg(notest)]
180-
impl ops::Shl<T,T> for T {
181-
fn shl(&self, other: &T) -> T { *self << *other }
182-
}
183-
#[cfg(notest)]
184-
impl ops::Shr<T,T> for T {
185-
fn shr(&self, other: &T) -> T { *self >> *other }
186-
}
187-
#[cfg(notest)]
188-
impl ops::Not<T> for T {
189-
fn not(&self) -> T { !*self }
190-
}
191167
192168
// String conversion functions and impl str -> num
193169
@@ -271,17 +247,6 @@ mod tests {
271247
use super::*;
272248
use super::inst::T;
273249
use prelude::*;
274-
275-
#[test]
276-
fn test_bitwise_ops() {
277-
assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T)));
278-
assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T)));
279-
assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T)));
280-
assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T)));
281-
assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T)));
282-
assert!(max_value - (0b1011 as T) == (0b1011 as T).not());
283-
}
284-
285250
#[test]
286251
pub fn test_to_str() {
287252
assert!(to_str_radix(0 as T, 10u) == ~"0");

trunk/src/libcore/repr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use io::{Writer, WriterUtil};
2323
use libc::c_void;
2424
use managed;
2525
use ptr;
26+
#[cfg(stage0)] use sys;
2627
use reflect;
2728
use reflect::{MovePtr, align};
28-
use sys;
2929
use to_str::ToStr;
3030
use vec::UnboxedVecRepr;
3131
use vec::raw::{VecRepr, SliceRepr};
@@ -479,7 +479,7 @@ impl TyVisitor for ReprVisitor {
479479
}
480480

481481
#[cfg(not(stage0))]
482-
fn visit_enter_enum(&self, n_variants: uint,
482+
fn visit_enter_enum(&self, _n_variants: uint,
483483
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
484484
_sz: uint, _align: uint) -> bool {
485485
let disr = unsafe { get_disr(transmute(self.ptr)) };

trunk/src/libcore/rt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ macro_rules! rtdebug (
3232
($( $arg:expr),+) => ( $(let _ = $arg)*; )
3333
)
3434

35+
#[path = "sched/mod.rs"]
3536
mod sched;
3637
mod rtio;
3738
pub mod uvll;

trunk/src/libcore/rt/sched/local.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2013 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+
//! Access to the thread-local Scheduler
12+
13+
use ptr::mut_null;
14+
use libc::c_void;
15+
use cast::transmute;
16+
17+
use super::Scheduler;
18+
use tls = super::super::thread_local_storage;
19+
#[cfg(test)] use super::super::uvio::UvEventLoop;
20+
21+
/// Give the Scheduler to thread-local storage
22+
pub fn put(sched: ~Scheduler) {
23+
unsafe {
24+
let key = tls_key();
25+
let void_sched: *mut c_void = transmute::<~Scheduler, *mut c_void>(sched);
26+
tls::set(key, void_sched);
27+
}
28+
}
29+
30+
/// Take ownership of the Scheduler from thread-local storage
31+
pub fn take() -> ~Scheduler {
32+
unsafe {
33+
let key = tls_key();
34+
let void_sched: *mut c_void = tls::get(key);
35+
assert!(void_sched.is_not_null());
36+
let sched = transmute::<*mut c_void, ~Scheduler>(void_sched);
37+
tls::set(key, mut_null());
38+
return sched;
39+
}
40+
}
41+
42+
/// Borrow a mutable reference to the thread-local Scheduler
43+
/// # Safety Note
44+
/// Because this leaves the Scheduler in thread-local storage it is possible
45+
/// For the Scheduler pointer to be aliased
46+
pub unsafe fn borrow() -> &mut Scheduler {
47+
unsafe {
48+
let key = tls_key();
49+
let mut void_sched: *mut c_void = tls::get(key);
50+
assert!(void_sched.is_not_null());
51+
{
52+
let void_sched_ptr = &mut void_sched;
53+
let sched: &mut ~Scheduler = {
54+
transmute::<&mut *mut c_void, &mut ~Scheduler>(void_sched_ptr)
55+
};
56+
let sched: &mut Scheduler = &mut **sched;
57+
return sched;
58+
}
59+
}
60+
}
61+
62+
fn tls_key() -> tls::Key {
63+
unsafe {
64+
let key: *mut c_void = rust_get_sched_tls_key();
65+
let key: &mut tls::Key = transmute(key);
66+
return *key;
67+
}
68+
}
69+
70+
extern {
71+
fn rust_get_sched_tls_key() -> *mut c_void;
72+
}
73+
74+
#[test]
75+
fn thread_local_scheduler_smoke_test() {
76+
let scheduler = ~UvEventLoop::new_scheduler();
77+
put(scheduler);
78+
let _scheduler = take();
79+
}
80+
81+
#[test]
82+
fn thread_local_scheduler_two_instances() {
83+
let scheduler = ~UvEventLoop::new_scheduler();
84+
put(scheduler);
85+
let _scheduler = take();
86+
let scheduler = ~UvEventLoop::new_scheduler();
87+
put(scheduler);
88+
let _scheduler = take();
89+
}
90+
91+
#[test]
92+
fn borrow_smoke_test() {
93+
let scheduler = ~UvEventLoop::new_scheduler();
94+
put(scheduler);
95+
unsafe {
96+
let _scheduler = borrow();
97+
}
98+
let _scheduler = take();
99+
}
100+

0 commit comments

Comments
 (0)