Skip to content

Commit edd9237

Browse files
committed
---
yaml --- r: 56983 b: refs/heads/try c: 8796c9f h: refs/heads/master i: 56981: adab9b1 56979: 15a8779 56975: 1abd081 v: v3
1 parent 3300fd2 commit edd9237

Some content is hidden

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

67 files changed

+1823
-807
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: a7f6ec854223772bd5c445d6cd2a17a045009f72
5+
refs/heads/try: 8796c9fe2d4898b9984d1de53a18c15dcb6eaf08
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/.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/

branches/try/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`

branches/try/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

branches/try/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+
}

branches/try/src/libcore/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub trait ReaderUtil {
176176
fn read_bytes(&self, len: uint) -> ~[u8];
177177

178178
/**
179-
* Reads up until a specific character or EOF.
179+
* Reads up until a specific byte is seen or EOF.
180180
*
181181
* The `include` parameter specifies if the character should be included
182182
* in the returned string.
@@ -185,7 +185,7 @@ pub trait ReaderUtil {
185185
*
186186
* None right now.
187187
*/
188-
fn read_until(&self, c: char, include: bool) -> ~str;
188+
fn read_until(&self, c: u8, include: bool) -> ~str;
189189

190190
/**
191191
* Reads up until the first '\n' or EOF.
@@ -577,7 +577,7 @@ impl<T:Reader> ReaderUtil for T {
577577
bytes
578578
}
579579

580-
fn read_until(&self, c: char, include: bool) -> ~str {
580+
fn read_until(&self, c: u8, include: bool) -> ~str {
581581
let mut bytes = ~[];
582582
loop {
583583
let ch = self.read_byte();
@@ -593,7 +593,7 @@ impl<T:Reader> ReaderUtil for T {
593593
}
594594

595595
fn read_line(&self) -> ~str {
596-
self.read_until('\n', false)
596+
self.read_until('\n' as u8, false)
597597
}
598598

599599
fn read_chars(&self, n: uint) -> ~[char] {
@@ -667,7 +667,7 @@ impl<T:Reader> ReaderUtil for T {
667667
}
668668

669669
fn read_c_str(&self) -> ~str {
670-
self.read_until(0 as char, false)
670+
self.read_until(0u8, false)
671671
}
672672

673673
fn read_whole_stream(&self) -> ~[u8] {
@@ -693,7 +693,7 @@ impl<T:Reader> ReaderUtil for T {
693693
// include the \n, so that we can distinguish an entirely empty
694694
// line read after "...\n", and the trailing empty line in
695695
// "...\n\n".
696-
let mut line = self.read_until('\n', true);
696+
let mut line = self.read_until('\n' as u8, true);
697697

698698
// blank line at the end of the reader is ignored
699699
if self.eof() && line.is_empty() { break; }

branches/try/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+
}

branches/try/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)) };

branches/try/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;
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)