libstd: Get rid of move
.
This commit is contained in:
parent
9727008ed0
commit
4cf51c2531
31 changed files with 357 additions and 363 deletions
|
@ -81,7 +81,7 @@ struct ARC<T> { x: SharedMutableState<T> }
|
||||||
|
|
||||||
/// Create an atomically reference counted wrapper.
|
/// Create an atomically reference counted wrapper.
|
||||||
pub fn ARC<T: Const Owned>(data: T) -> ARC<T> {
|
pub fn ARC<T: Const Owned>(data: T) -> ARC<T> {
|
||||||
ARC { x: unsafe { shared_mutable_state(move data) } }
|
ARC { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,8 +113,8 @@ pub fn clone<T: Const Owned>(rc: &ARC<T>) -> ARC<T> {
|
||||||
* guaranteed to deadlock.
|
* guaranteed to deadlock.
|
||||||
*/
|
*/
|
||||||
pub fn unwrap<T: Const Owned>(rc: ARC<T>) -> T {
|
pub fn unwrap<T: Const Owned>(rc: ARC<T>) -> T {
|
||||||
let ARC { x: x } = move rc;
|
let ARC { x: x } = rc;
|
||||||
unsafe { unwrap_shared_mutable_state(move x) }
|
unsafe { unwrap_shared_mutable_state(x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> Clone for ARC<T> {
|
impl<T: Const Owned> Clone for ARC<T> {
|
||||||
|
@ -134,7 +134,7 @@ struct MutexARC<T> { x: SharedMutableState<MutexARCInner<T>> }
|
||||||
|
|
||||||
/// Create a mutex-protected ARC with the supplied data.
|
/// Create a mutex-protected ARC with the supplied data.
|
||||||
pub fn MutexARC<T: Owned>(user_data: T) -> MutexARC<T> {
|
pub fn MutexARC<T: Owned>(user_data: T) -> MutexARC<T> {
|
||||||
mutex_arc_with_condvars(move user_data, 1)
|
mutex_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a mutex-protected ARC with the supplied data and a specified number
|
* Create a mutex-protected ARC with the supplied data and a specified number
|
||||||
|
@ -144,8 +144,8 @@ pub fn mutex_arc_with_condvars<T: Owned>(user_data: T,
|
||||||
num_condvars: uint) -> MutexARC<T> {
|
num_condvars: uint) -> MutexARC<T> {
|
||||||
let data =
|
let data =
|
||||||
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
||||||
failed: false, data: move user_data };
|
failed: false, data: user_data };
|
||||||
MutexARC { x: unsafe { shared_mutable_state(move data) } }
|
MutexARC { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Clone for MutexARC<T> {
|
impl<T: Owned> Clone for MutexARC<T> {
|
||||||
|
@ -220,13 +220,13 @@ impl<T: Owned> &MutexARC<T> {
|
||||||
*/
|
*/
|
||||||
// FIXME(#3724) make this a by-move method on the arc
|
// FIXME(#3724) make this a by-move method on the arc
|
||||||
pub fn unwrap_mutex_arc<T: Owned>(arc: MutexARC<T>) -> T {
|
pub fn unwrap_mutex_arc<T: Owned>(arc: MutexARC<T>) -> T {
|
||||||
let MutexARC { x: x } = move arc;
|
let MutexARC { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(move x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let MutexARCInner { failed: failed, data: data, _ } = move inner;
|
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
||||||
if failed {
|
if failed {
|
||||||
fail!(~"Can't unwrap poisoned MutexARC - another task failed inside!")
|
fail!(~"Can't unwrap poisoned MutexARC - another task failed inside!")
|
||||||
}
|
}
|
||||||
move data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common code for {mutex.access,rwlock.write}{,_cond}.
|
// Common code for {mutex.access,rwlock.write}{,_cond}.
|
||||||
|
@ -284,7 +284,7 @@ struct RWARC<T> {
|
||||||
|
|
||||||
/// Create a reader/writer ARC with the supplied data.
|
/// Create a reader/writer ARC with the supplied data.
|
||||||
pub fn RWARC<T: Const Owned>(user_data: T) -> RWARC<T> {
|
pub fn RWARC<T: Const Owned>(user_data: T) -> RWARC<T> {
|
||||||
rw_arc_with_condvars(move user_data, 1)
|
rw_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a reader/writer ARC with the supplied data and a specified number
|
* Create a reader/writer ARC with the supplied data and a specified number
|
||||||
|
@ -296,8 +296,8 @@ pub fn rw_arc_with_condvars<T: Const Owned>(
|
||||||
{
|
{
|
||||||
let data =
|
let data =
|
||||||
RWARCInner { lock: rwlock_with_condvars(num_condvars),
|
RWARCInner { lock: rwlock_with_condvars(num_condvars),
|
||||||
failed: false, data: move user_data };
|
failed: false, data: user_data };
|
||||||
RWARC { x: unsafe { shared_mutable_state(move data) }, cant_nest: () }
|
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Const Owned> RWARC<T> {
|
impl<T: Const Owned> RWARC<T> {
|
||||||
|
@ -386,7 +386,7 @@ impl<T: Const Owned> &RWARC<T> {
|
||||||
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
|
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
|
||||||
check_poison(false, (*state).failed);
|
check_poison(false, (*state).failed);
|
||||||
blk(RWWriteMode((&mut (*state).data,
|
blk(RWWriteMode((&mut (*state).data,
|
||||||
move write_mode,
|
write_mode,
|
||||||
PoisonOnFail(&mut (*state).failed))))
|
PoisonOnFail(&mut (*state).failed))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,9 +396,9 @@ impl<T: Const Owned> &RWARC<T> {
|
||||||
fn downgrade(token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
|
fn downgrade(token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
|
||||||
// The rwlock should assert that the token belongs to us for us.
|
// The rwlock should assert that the token belongs to us for us.
|
||||||
let state = unsafe { get_shared_immutable_state(&self.x) };
|
let state = unsafe { get_shared_immutable_state(&self.x) };
|
||||||
let RWWriteMode((data, t, _poison)) = move token;
|
let RWWriteMode((data, t, _poison)) = token;
|
||||||
// Let readers in
|
// Let readers in
|
||||||
let new_token = (&state.lock).downgrade(move t);
|
let new_token = (&state.lock).downgrade(t);
|
||||||
// Whatever region the input reference had, it will be safe to use
|
// Whatever region the input reference had, it will be safe to use
|
||||||
// the same region for the output reference. (The only 'unsafe' part
|
// the same region for the output reference. (The only 'unsafe' part
|
||||||
// of this cast is removing the mutability.)
|
// of this cast is removing the mutability.)
|
||||||
|
@ -406,7 +406,7 @@ impl<T: Const Owned> &RWARC<T> {
|
||||||
// Downgrade ensured the token belonged to us. Just a sanity check.
|
// Downgrade ensured the token belonged to us. Just a sanity check.
|
||||||
assert ptr::ref_eq(&state.data, new_data);
|
assert ptr::ref_eq(&state.data, new_data);
|
||||||
// Produce new token
|
// Produce new token
|
||||||
RWReadMode((new_data, move new_token))
|
RWReadMode((new_data, new_token))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,13 +419,13 @@ impl<T: Const Owned> &RWARC<T> {
|
||||||
*/
|
*/
|
||||||
// FIXME(#3724) make this a by-move method on the arc
|
// FIXME(#3724) make this a by-move method on the arc
|
||||||
pub fn unwrap_rw_arc<T: Const Owned>(arc: RWARC<T>) -> T {
|
pub fn unwrap_rw_arc<T: Const Owned>(arc: RWARC<T>) -> T {
|
||||||
let RWARC { x: x, _ } = move arc;
|
let RWARC { x: x, _ } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(move x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let RWARCInner { failed: failed, data: data, _ } = move inner;
|
let RWARCInner { failed: failed, data: data, _ } = inner;
|
||||||
if failed {
|
if failed {
|
||||||
fail!(~"Can't unwrap poisoned RWARC - another task failed inside!")
|
fail!(~"Can't unwrap poisoned RWARC - another task failed inside!")
|
||||||
}
|
}
|
||||||
move data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Borrowck rightly complains about immutably aliasing the rwlock in order to
|
// Borrowck rightly complains about immutably aliasing the rwlock in order to
|
||||||
|
@ -509,7 +509,7 @@ mod tests {
|
||||||
|
|
||||||
let (p, c) = pipes::stream();
|
let (p, c) = pipes::stream();
|
||||||
|
|
||||||
do task::spawn() |move c| {
|
do task::spawn() || {
|
||||||
let p = pipes::PortSet();
|
let p = pipes::PortSet();
|
||||||
c.send(p.chan());
|
c.send(p.chan());
|
||||||
|
|
||||||
|
@ -532,8 +532,8 @@ mod tests {
|
||||||
let arc = ~MutexARC(false);
|
let arc = ~MutexARC(false);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
let (p,c) = pipes::oneshot();
|
let (p,c) = pipes::oneshot();
|
||||||
let (c,p) = (~mut Some(move c), ~mut Some(move p));
|
let (c,p) = (~mut Some(c), ~mut Some(p));
|
||||||
do task::spawn |move arc2, move p| {
|
do task::spawn || {
|
||||||
// wait until parent gets in
|
// wait until parent gets in
|
||||||
pipes::recv_one(option::swap_unwrap(p));
|
pipes::recv_one(option::swap_unwrap(p));
|
||||||
do arc2.access_cond |state, cond| {
|
do arc2.access_cond |state, cond| {
|
||||||
|
@ -555,7 +555,7 @@ mod tests {
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
let (p, c) = pipes::stream();
|
let (p, c) = pipes::stream();
|
||||||
|
|
||||||
do task::spawn_unlinked |move arc2, move p| {
|
do task::spawn_unlinked || {
|
||||||
let _ = p.recv();
|
let _ = p.recv();
|
||||||
do arc2.access_cond |one, cond| {
|
do arc2.access_cond |one, cond| {
|
||||||
cond.signal();
|
cond.signal();
|
||||||
|
@ -574,7 +574,7 @@ mod tests {
|
||||||
pub fn test_mutex_arc_poison() {
|
pub fn test_mutex_arc_poison() {
|
||||||
let arc = ~MutexARC(1);
|
let arc = ~MutexARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.access |one| {
|
do arc2.access |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -588,21 +588,21 @@ mod tests {
|
||||||
let arc = MutexARC(1);
|
let arc = MutexARC(1);
|
||||||
let arc2 = ~(&arc).clone();
|
let arc2 = ~(&arc).clone();
|
||||||
let (p, c) = pipes::stream();
|
let (p, c) = pipes::stream();
|
||||||
do task::spawn |move c, move arc2| {
|
do task::spawn || {
|
||||||
do arc2.access |one| {
|
do arc2.access |one| {
|
||||||
c.send(());
|
c.send(());
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _ = p.recv();
|
let _ = p.recv();
|
||||||
let one = unwrap_mutex_arc(move arc);
|
let one = unwrap_mutex_arc(arc);
|
||||||
assert one == 1;
|
assert one == 1;
|
||||||
}
|
}
|
||||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||||
pub fn test_rw_arc_poison_wr() {
|
pub fn test_rw_arc_poison_wr() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.write |one| {
|
do arc2.write |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -615,7 +615,7 @@ mod tests {
|
||||||
pub fn test_rw_arc_poison_ww() {
|
pub fn test_rw_arc_poison_ww() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.write |one| {
|
do arc2.write |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -628,7 +628,7 @@ mod tests {
|
||||||
pub fn test_rw_arc_poison_dw() {
|
pub fn test_rw_arc_poison_dw() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.write_downgrade |write_mode| {
|
do arc2.write_downgrade |write_mode| {
|
||||||
do (&write_mode).write |one| {
|
do (&write_mode).write |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
|
@ -643,7 +643,7 @@ mod tests {
|
||||||
pub fn test_rw_arc_no_poison_rr() {
|
pub fn test_rw_arc_no_poison_rr() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.read |one| {
|
do arc2.read |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -656,7 +656,7 @@ mod tests {
|
||||||
pub fn test_rw_arc_no_poison_rw() {
|
pub fn test_rw_arc_no_poison_rw() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.read |one| {
|
do arc2.read |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -669,9 +669,9 @@ mod tests {
|
||||||
pub fn test_rw_arc_no_poison_dr() {
|
pub fn test_rw_arc_no_poison_dr() {
|
||||||
let arc = ~RWARC(1);
|
let arc = ~RWARC(1);
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
do task::try |move arc2| {
|
do task::try || {
|
||||||
do arc2.write_downgrade |write_mode| {
|
do arc2.write_downgrade |write_mode| {
|
||||||
let read_mode = arc2.downgrade(move write_mode);
|
let read_mode = arc2.downgrade(write_mode);
|
||||||
do (&read_mode).read |one| {
|
do (&read_mode).read |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -687,7 +687,7 @@ mod tests {
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
|
|
||||||
do task::spawn |move arc2, move c| {
|
do task::spawn || {
|
||||||
do arc2.write |num| {
|
do arc2.write |num| {
|
||||||
for 10.times {
|
for 10.times {
|
||||||
let tmp = *num;
|
let tmp = *num;
|
||||||
|
@ -703,8 +703,8 @@ mod tests {
|
||||||
let mut children = ~[];
|
let mut children = ~[];
|
||||||
for 5.times {
|
for 5.times {
|
||||||
let arc3 = ~arc.clone();
|
let arc3 = ~arc.clone();
|
||||||
do task::task().future_result(|+r| children.push(move r)).spawn
|
do task::task().future_result(|+r| children.push(r)).spawn
|
||||||
|move arc3| {
|
|| {
|
||||||
do arc3.read |num| {
|
do arc3.read |num| {
|
||||||
assert *num >= 0;
|
assert *num >= 0;
|
||||||
}
|
}
|
||||||
|
@ -732,9 +732,9 @@ mod tests {
|
||||||
let mut reader_convos = ~[];
|
let mut reader_convos = ~[];
|
||||||
for 10.times {
|
for 10.times {
|
||||||
let ((rp1,rc1),(rp2,rc2)) = (pipes::stream(),pipes::stream());
|
let ((rp1,rc1),(rp2,rc2)) = (pipes::stream(),pipes::stream());
|
||||||
reader_convos.push((move rc1, move rp2));
|
reader_convos.push((rc1, rp2));
|
||||||
let arcn = ~arc.clone();
|
let arcn = ~arc.clone();
|
||||||
do task::spawn |move rp1, move rc2, move arcn| {
|
do task::spawn || {
|
||||||
rp1.recv(); // wait for downgrader to give go-ahead
|
rp1.recv(); // wait for downgrader to give go-ahead
|
||||||
do arcn.read |state| {
|
do arcn.read |state| {
|
||||||
assert *state == 31337;
|
assert *state == 31337;
|
||||||
|
@ -746,7 +746,7 @@ mod tests {
|
||||||
// Writer task
|
// Writer task
|
||||||
let arc2 = ~arc.clone();
|
let arc2 = ~arc.clone();
|
||||||
let ((wp1,wc1),(wp2,wc2)) = (pipes::stream(),pipes::stream());
|
let ((wp1,wc1),(wp2,wc2)) = (pipes::stream(),pipes::stream());
|
||||||
do task::spawn |move arc2, move wc2, move wp1| {
|
do task::spawn || {
|
||||||
wp1.recv();
|
wp1.recv();
|
||||||
do arc2.write_cond |state, cond| {
|
do arc2.write_cond |state, cond| {
|
||||||
assert *state == 0;
|
assert *state == 0;
|
||||||
|
@ -779,7 +779,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let read_mode = arc.downgrade(move write_mode);
|
let read_mode = arc.downgrade(write_mode);
|
||||||
do (&read_mode).read |state| {
|
do (&read_mode).read |state| {
|
||||||
// complete handshake with other readers
|
// complete handshake with other readers
|
||||||
for vec::each(reader_convos) |x| {
|
for vec::each(reader_convos) |x| {
|
||||||
|
|
|
@ -108,7 +108,7 @@ struct BigBitv {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn BigBitv(storage: ~[uint]) -> BigBitv {
|
fn BigBitv(storage: ~[uint]) -> BigBitv {
|
||||||
BigBitv {storage: move storage}
|
BigBitv {storage: storage}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,9 +232,9 @@ pub fn Bitv (nbits: uint, init: bool) -> Bitv {
|
||||||
if nbits % uint_bits == 0 {0} else {1};
|
if nbits % uint_bits == 0 {0} else {1};
|
||||||
let elem = if init {!0} else {0};
|
let elem = if init {!0} else {0};
|
||||||
let s = from_elem(nelems, elem);
|
let s = from_elem(nelems, elem);
|
||||||
Big(~BigBitv(move s))
|
Big(~BigBitv(s))
|
||||||
};
|
};
|
||||||
Bitv {rep: move rep, nbits: nbits}
|
Bitv {rep: rep, nbits: nbits}
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl Bitv {
|
priv impl Bitv {
|
||||||
|
@ -519,7 +519,7 @@ impl Clone for Bitv {
|
||||||
let mut st = from_elem(self.nbits / uint_bits + 1, 0);
|
let mut st = from_elem(self.nbits / uint_bits + 1, 0);
|
||||||
let len = st.len();
|
let len = st.len();
|
||||||
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
|
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
|
||||||
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: move st})}
|
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: st})}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ pub fn from_fn(len: uint, f: fn(index: uint) -> bool) -> Bitv {
|
||||||
for uint::range(0, len) |i| {
|
for uint::range(0, len) |i| {
|
||||||
bitv.set(i, f(i));
|
bitv.set(i, f(i));
|
||||||
}
|
}
|
||||||
move bitv
|
bitv
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint_bits: uint = 32u + (1u << 32u >> 27u);
|
const uint_bits: uint = 32u + (1u << 32u >> 27u);
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub struct Cell<T> {
|
||||||
|
|
||||||
/// Creates a new full cell with the given value.
|
/// Creates a new full cell with the given value.
|
||||||
pub fn Cell<T>(value: T) -> Cell<T> {
|
pub fn Cell<T>(value: T) -> Cell<T> {
|
||||||
Cell { value: Some(move value) }
|
Cell { value: Some(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn empty_cell<T>() -> Cell<T> {
|
pub pure fn empty_cell<T>() -> Cell<T> {
|
||||||
|
@ -37,7 +37,7 @@ impl<T> Cell<T> {
|
||||||
|
|
||||||
let mut value = None;
|
let mut value = None;
|
||||||
value <-> self.value;
|
value <-> self.value;
|
||||||
return option::unwrap(move value);
|
return option::unwrap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the value, failing if the cell is full.
|
/// Returns the value, failing if the cell is full.
|
||||||
|
@ -45,7 +45,7 @@ impl<T> Cell<T> {
|
||||||
if !self.is_empty() {
|
if !self.is_empty() {
|
||||||
fail!(~"attempt to put a value back into a full cell");
|
fail!(~"attempt to put a value back into a full cell");
|
||||||
}
|
}
|
||||||
self.value = Some(move value);
|
self.value = Some(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the cell is empty and false if the cell is full.
|
/// Returns true if the cell is empty and false if the cell is full.
|
||||||
|
@ -57,8 +57,8 @@ impl<T> Cell<T> {
|
||||||
fn with_ref<R>(op: fn(v: &T) -> R) -> R {
|
fn with_ref<R>(op: fn(v: &T) -> R) -> R {
|
||||||
let v = self.take();
|
let v = self.take();
|
||||||
let r = op(&v);
|
let r = op(&v);
|
||||||
self.put_back(move v);
|
self.put_back(v);
|
||||||
move r
|
r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ fn test_basic() {
|
||||||
let value = value_cell.take();
|
let value = value_cell.take();
|
||||||
assert value == ~10;
|
assert value == ~10;
|
||||||
assert value_cell.is_empty();
|
assert value_cell.is_empty();
|
||||||
value_cell.put_back(move value);
|
value_cell.put_back(value);
|
||||||
assert !value_cell.is_empty();
|
assert !value_cell.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ pub struct DuplexStream<T, U> {
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> GenericChan<T> for DuplexStream<T, U> {
|
impl<T: Owned, U: Owned> GenericChan<T> for DuplexStream<T, U> {
|
||||||
fn send(x: T) {
|
fn send(x: T) {
|
||||||
self.chan.send(move x)
|
self.chan.send(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned, U: Owned> GenericSmartChan<T> for DuplexStream<T, U> {
|
impl<T: Owned, U: Owned> GenericSmartChan<T> for DuplexStream<T, U> {
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
self.chan.try_send(move x)
|
self.chan.try_send(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +66,12 @@ pub fn DuplexStream<T: Owned, U: Owned>()
|
||||||
let (p1, c2) = pipes::stream();
|
let (p1, c2) = pipes::stream();
|
||||||
let (p2, c1) = pipes::stream();
|
let (p2, c1) = pipes::stream();
|
||||||
(DuplexStream {
|
(DuplexStream {
|
||||||
chan: move c1,
|
chan: c1,
|
||||||
port: move p1
|
port: p1
|
||||||
},
|
},
|
||||||
DuplexStream {
|
DuplexStream {
|
||||||
chan: move c2,
|
chan: c2,
|
||||||
port: move p2
|
port: p2
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub fn create<T: Copy>() -> Deque<T> {
|
||||||
*/
|
*/
|
||||||
fn grow<T: Copy>(nelts: uint, lo: uint, elts: ~[Cell<T>])
|
fn grow<T: Copy>(nelts: uint, lo: uint, elts: ~[Cell<T>])
|
||||||
-> ~[Cell<T>] {
|
-> ~[Cell<T>] {
|
||||||
let mut elts = move elts;
|
let mut elts = elts;
|
||||||
assert (nelts == vec::len(elts));
|
assert (nelts == vec::len(elts));
|
||||||
let mut rv = ~[];
|
let mut rv = ~[];
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ pub fn create<T: Copy>() -> Deque<T> {
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
move rv
|
rv
|
||||||
}
|
}
|
||||||
fn get<T: Copy>(elts: &DVec<Cell<T>>, i: uint) -> T {
|
fn get<T: Copy>(elts: &DVec<Cell<T>>, i: uint) -> T {
|
||||||
match (*elts).get_elt(i) { Some(move t) => t, _ => fail!() }
|
match (*elts).get_elt(i) { Some(t) => t, _ => fail!() }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Repr<T> {
|
struct Repr<T> {
|
||||||
|
@ -75,7 +75,7 @@ pub fn create<T: Copy>() -> Deque<T> {
|
||||||
self.lo = self.elts.len() - 1u;
|
self.lo = self.elts.len() - 1u;
|
||||||
} else { self.lo -= 1u; }
|
} else { self.lo -= 1u; }
|
||||||
if self.lo == self.hi {
|
if self.lo == self.hi {
|
||||||
self.elts.swap(|v| grow(self.nelts, oldlo, move v));
|
self.elts.swap(|v| grow(self.nelts, oldlo, v));
|
||||||
self.lo = self.elts.len() - 1u;
|
self.lo = self.elts.len() - 1u;
|
||||||
self.hi = self.nelts;
|
self.hi = self.nelts;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ pub fn create<T: Copy>() -> Deque<T> {
|
||||||
}
|
}
|
||||||
fn add_back(t: T) {
|
fn add_back(t: T) {
|
||||||
if self.lo == self.hi && self.nelts != 0u {
|
if self.lo == self.hi && self.nelts != 0u {
|
||||||
self.elts.swap(|v| grow(self.nelts, self.lo, move v));
|
self.elts.swap(|v| grow(self.nelts, self.lo, v));
|
||||||
self.lo = 0u;
|
self.lo = 0u;
|
||||||
self.hi = self.nelts;
|
self.hi = self.nelts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ pub mod reader {
|
||||||
r_doc
|
r_doc
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_doc<T>(d: Doc, f: fn() -> T) -> T{
|
fn push_doc<T>(d: Doc, f: fn() -> T) -> T {
|
||||||
let old_parent = self.parent;
|
let old_parent = self.parent;
|
||||||
let old_pos = self.pos;
|
let old_pos = self.pos;
|
||||||
self.parent = d;
|
self.parent = d;
|
||||||
|
@ -267,7 +267,7 @@ pub mod reader {
|
||||||
let r = f();
|
let r = f();
|
||||||
self.parent = old_parent;
|
self.parent = old_parent;
|
||||||
self.pos = old_pos;
|
self.pos = old_pos;
|
||||||
move r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _next_uint(exp_tag: EbmlEncoderTag) -> uint {
|
fn _next_uint(exp_tag: EbmlEncoderTag) -> uint {
|
||||||
|
|
|
@ -28,7 +28,7 @@ This example sends boxed integers across tasks using serialization.
|
||||||
~~~
|
~~~
|
||||||
let (port, chan) = serial::pipe_stream();
|
let (port, chan) = serial::pipe_stream();
|
||||||
|
|
||||||
do task::spawn |move chan| {
|
do task::spawn || {
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
chan.send(@i)
|
chan.send(@i)
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,8 @@ pub mod serial {
|
||||||
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
||||||
DeserializingUnflattener::new(
|
DeserializingUnflattener::new(
|
||||||
deserialize_buffer::<DefaultDecoder, T>);
|
deserialize_buffer::<DefaultDecoder, T>);
|
||||||
let byte_port = ReaderBytePort::new(move reader);
|
let byte_port = ReaderBytePort::new(reader);
|
||||||
FlatPort::new(move unflat, move byte_port)
|
FlatPort::new(unflat, byte_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Writer`
|
/// Create a `FlatChan` from a `Writer`
|
||||||
|
@ -124,8 +124,8 @@ pub mod serial {
|
||||||
let flat: SerializingFlattener<DefaultEncoder, T> =
|
let flat: SerializingFlattener<DefaultEncoder, T> =
|
||||||
SerializingFlattener::new(
|
SerializingFlattener::new(
|
||||||
serialize_value::<DefaultEncoder, T>);
|
serialize_value::<DefaultEncoder, T>);
|
||||||
let byte_chan = WriterByteChan::new(move writer);
|
let byte_chan = WriterByteChan::new(writer);
|
||||||
FlatChan::new(move flat, move byte_chan)
|
FlatChan::new(flat, byte_chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatPort` from a `Port<~[u8]>`
|
/// Create a `FlatPort` from a `Port<~[u8]>`
|
||||||
|
@ -135,8 +135,8 @@ pub mod serial {
|
||||||
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
let unflat: DeserializingUnflattener<DefaultDecoder, T> =
|
||||||
DeserializingUnflattener::new(
|
DeserializingUnflattener::new(
|
||||||
deserialize_buffer::<DefaultDecoder, T>);
|
deserialize_buffer::<DefaultDecoder, T>);
|
||||||
let byte_port = PipeBytePort::new(move port);
|
let byte_port = PipeBytePort::new(port);
|
||||||
FlatPort::new(move unflat, move byte_port)
|
FlatPort::new(unflat, byte_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
||||||
|
@ -146,8 +146,8 @@ pub mod serial {
|
||||||
let flat: SerializingFlattener<DefaultEncoder, T> =
|
let flat: SerializingFlattener<DefaultEncoder, T> =
|
||||||
SerializingFlattener::new(
|
SerializingFlattener::new(
|
||||||
serialize_value::<DefaultEncoder, T>);
|
serialize_value::<DefaultEncoder, T>);
|
||||||
let byte_chan = PipeByteChan::new(move chan);
|
let byte_chan = PipeByteChan::new(chan);
|
||||||
FlatChan::new(move flat, move byte_chan)
|
FlatChan::new(flat, byte_chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
||||||
|
@ -155,7 +155,7 @@ pub mod serial {
|
||||||
Decodable<DefaultDecoder>>(
|
Decodable<DefaultDecoder>>(
|
||||||
) -> (PipePort<T>, PipeChan<T>) {
|
) -> (PipePort<T>, PipeChan<T>) {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
return (pipe_port(move port), pipe_chan(move chan));
|
return (pipe_port(port), pipe_chan(chan));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +193,8 @@ pub mod pod {
|
||||||
reader: R
|
reader: R
|
||||||
) -> ReaderPort<T, R> {
|
) -> ReaderPort<T, R> {
|
||||||
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
||||||
let byte_port = ReaderBytePort::new(move reader);
|
let byte_port = ReaderBytePort::new(reader);
|
||||||
FlatPort::new(move unflat, move byte_port)
|
FlatPort::new(unflat, byte_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Writer`
|
/// Create a `FlatChan` from a `Writer`
|
||||||
|
@ -202,28 +202,28 @@ pub mod pod {
|
||||||
writer: W
|
writer: W
|
||||||
) -> WriterChan<T, W> {
|
) -> WriterChan<T, W> {
|
||||||
let flat: PodFlattener<T> = PodFlattener::new();
|
let flat: PodFlattener<T> = PodFlattener::new();
|
||||||
let byte_chan = WriterByteChan::new(move writer);
|
let byte_chan = WriterByteChan::new(writer);
|
||||||
FlatChan::new(move flat, move byte_chan)
|
FlatChan::new(flat, byte_chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatPort` from a `Port<~[u8]>`
|
/// Create a `FlatPort` from a `Port<~[u8]>`
|
||||||
pub fn pipe_port<T: Copy Owned>(port: Port<~[u8]>) -> PipePort<T> {
|
pub fn pipe_port<T: Copy Owned>(port: Port<~[u8]>) -> PipePort<T> {
|
||||||
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
let unflat: PodUnflattener<T> = PodUnflattener::new();
|
||||||
let byte_port = PipeBytePort::new(move port);
|
let byte_port = PipeBytePort::new(port);
|
||||||
FlatPort::new(move unflat, move byte_port)
|
FlatPort::new(unflat, byte_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
/// Create a `FlatChan` from a `Chan<~[u8]>`
|
||||||
pub fn pipe_chan<T: Copy Owned>(chan: Chan<~[u8]>) -> PipeChan<T> {
|
pub fn pipe_chan<T: Copy Owned>(chan: Chan<~[u8]>) -> PipeChan<T> {
|
||||||
let flat: PodFlattener<T> = PodFlattener::new();
|
let flat: PodFlattener<T> = PodFlattener::new();
|
||||||
let byte_chan = PipeByteChan::new(move chan);
|
let byte_chan = PipeByteChan::new(chan);
|
||||||
FlatChan::new(move flat, move byte_chan)
|
FlatChan::new(flat, byte_chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
/// Create a pair of `FlatChan` and `FlatPort`, backed by pipes
|
||||||
pub fn pipe_stream<T: Copy Owned>() -> (PipePort<T>, PipeChan<T>) {
|
pub fn pipe_stream<T: Copy Owned>() -> (PipePort<T>, PipeChan<T>) {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
return (pipe_port(move port), pipe_chan(move chan));
|
return (pipe_port(port), pipe_chan(chan));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -261,13 +261,13 @@ const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
||||||
pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P>: GenericPort<T> {
|
pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P>: GenericPort<T> {
|
||||||
fn recv() -> T {
|
fn recv() -> T {
|
||||||
match self.try_recv() {
|
match self.try_recv() {
|
||||||
Some(move val) => move val,
|
Some(val) => val,
|
||||||
None => fail!(~"port is closed")
|
None => fail!(~"port is closed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn try_recv() -> Option<T> {
|
fn try_recv() -> Option<T> {
|
||||||
let command = match self.byte_port.try_recv(CONTINUE.len()) {
|
let command = match self.byte_port.try_recv(CONTINUE.len()) {
|
||||||
Some(move c) => move c,
|
Some(c) => c,
|
||||||
None => {
|
None => {
|
||||||
warn!("flatpipe: broken pipe");
|
warn!("flatpipe: broken pipe");
|
||||||
return None;
|
return None;
|
||||||
|
@ -288,8 +288,8 @@ pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P>: GenericPort<T> {
|
||||||
let msg_len = msg_len as uint;
|
let msg_len = msg_len as uint;
|
||||||
|
|
||||||
match self.byte_port.try_recv(msg_len) {
|
match self.byte_port.try_recv(msg_len) {
|
||||||
Some(move bytes) => {
|
Some(bytes) => {
|
||||||
Some(self.unflattener.unflatten(move bytes))
|
Some(self.unflattener.unflatten(bytes))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
warn!("flatpipe: broken pipe");
|
warn!("flatpipe: broken pipe");
|
||||||
|
@ -306,20 +306,20 @@ pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P>: GenericPort<T> {
|
||||||
impl<T,F:Flattener<T>,C:ByteChan> GenericChan<T> for FlatChan<T, F, C> {
|
impl<T,F:Flattener<T>,C:ByteChan> GenericChan<T> for FlatChan<T, F, C> {
|
||||||
fn send(val: T) {
|
fn send(val: T) {
|
||||||
self.byte_chan.send(CONTINUE.to_vec());
|
self.byte_chan.send(CONTINUE.to_vec());
|
||||||
let bytes = self.flattener.flatten(move val);
|
let bytes = self.flattener.flatten(val);
|
||||||
let len = bytes.len() as u64;
|
let len = bytes.len() as u64;
|
||||||
do io::u64_to_be_bytes(len, size_of::<u64>()) |len_bytes| {
|
do io::u64_to_be_bytes(len, size_of::<u64>()) |len_bytes| {
|
||||||
self.byte_chan.send(len_bytes.to_vec());
|
self.byte_chan.send(len_bytes.to_vec());
|
||||||
}
|
}
|
||||||
self.byte_chan.send(move bytes);
|
self.byte_chan.send(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
||||||
static fn new(u: U, p: P) -> FlatPort<T, U, P> {
|
static fn new(u: U, p: P) -> FlatPort<T, U, P> {
|
||||||
FlatPort {
|
FlatPort {
|
||||||
unflattener: move u,
|
unflattener: u,
|
||||||
byte_port: move p
|
byte_port: p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,8 +327,8 @@ pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
||||||
pub impl<T,F:Flattener<T>,C:ByteChan> FlatChan<T, F, C> {
|
pub impl<T,F:Flattener<T>,C:ByteChan> FlatChan<T, F, C> {
|
||||||
static fn new(f: F, c: C) -> FlatChan<T, F, C> {
|
static fn new(f: F, c: C) -> FlatChan<T, F, C> {
|
||||||
FlatChan {
|
FlatChan {
|
||||||
flattener: move f,
|
flattener: f,
|
||||||
byte_chan: move c
|
byte_chan: c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ pub mod flatteners {
|
||||||
static fn new(deserialize_buffer: DeserializeBuffer<T>
|
static fn new(deserialize_buffer: DeserializeBuffer<T>
|
||||||
) -> DeserializingUnflattener<D, T> {
|
) -> DeserializingUnflattener<D, T> {
|
||||||
DeserializingUnflattener {
|
DeserializingUnflattener {
|
||||||
deserialize_buffer: move deserialize_buffer
|
deserialize_buffer: deserialize_buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ pub mod flatteners {
|
||||||
static fn new(serialize_value: SerializeValue<T>
|
static fn new(serialize_value: SerializeValue<T>
|
||||||
) -> SerializingFlattener<S, T> {
|
) -> SerializingFlattener<S, T> {
|
||||||
SerializingFlattener {
|
SerializingFlattener {
|
||||||
serialize_value: move serialize_value
|
serialize_value: serialize_value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ pub mod flatteners {
|
||||||
pub fn deserialize_buffer<D: Decoder FromReader,
|
pub fn deserialize_buffer<D: Decoder FromReader,
|
||||||
T: Decodable<D>>(buf: &[u8]) -> T {
|
T: Decodable<D>>(buf: &[u8]) -> T {
|
||||||
let buf = vec::from_slice(buf);
|
let buf = vec::from_slice(buf);
|
||||||
let buf_reader = @BufReader::new(move buf);
|
let buf_reader = @BufReader::new(buf);
|
||||||
let reader = buf_reader as @Reader;
|
let reader = buf_reader as @Reader;
|
||||||
let deser: D = FromReader::from_reader(reader);
|
let deser: D = FromReader::from_reader(reader);
|
||||||
Decodable::decode(&deser)
|
Decodable::decode(&deser)
|
||||||
|
@ -462,8 +462,8 @@ pub mod flatteners {
|
||||||
let writer = bytes_writer as @Writer;
|
let writer = bytes_writer as @Writer;
|
||||||
let ser = FromWriter::from_writer(writer);
|
let ser = FromWriter::from_writer(writer);
|
||||||
val.encode(&ser);
|
val.encode(&ser);
|
||||||
let bytes = bytes_writer.bytes.check_out(|bytes| move bytes);
|
let bytes = bytes_writer.bytes.check_out(|bytes| bytes);
|
||||||
return move bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromReader {
|
pub trait FromReader {
|
||||||
|
@ -477,8 +477,8 @@ pub mod flatteners {
|
||||||
impl FromReader for json::Decoder {
|
impl FromReader for json::Decoder {
|
||||||
static fn from_reader(r: Reader) -> json::Decoder {
|
static fn from_reader(r: Reader) -> json::Decoder {
|
||||||
match json::from_reader(r) {
|
match json::from_reader(r) {
|
||||||
Ok(move json) => {
|
Ok(json) => {
|
||||||
json::Decoder(move json)
|
json::Decoder(json)
|
||||||
}
|
}
|
||||||
Err(e) => fail!(fmt!("flatpipe: can't parse json: %?", e))
|
Err(e) => fail!(fmt!("flatpipe: can't parse json: %?", e))
|
||||||
}
|
}
|
||||||
|
@ -487,7 +487,7 @@ pub mod flatteners {
|
||||||
|
|
||||||
impl FromWriter for json::Encoder {
|
impl FromWriter for json::Encoder {
|
||||||
static fn from_writer(w: Writer) -> json::Encoder {
|
static fn from_writer(w: Writer) -> json::Encoder {
|
||||||
json::Encoder(move w)
|
json::Encoder(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,13 +495,13 @@ pub mod flatteners {
|
||||||
static fn from_reader(r: Reader) -> ebml::reader::Decoder {
|
static fn from_reader(r: Reader) -> ebml::reader::Decoder {
|
||||||
let buf = @r.read_whole_stream();
|
let buf = @r.read_whole_stream();
|
||||||
let doc = ebml::reader::Doc(buf);
|
let doc = ebml::reader::Doc(buf);
|
||||||
ebml::reader::Decoder(move doc)
|
ebml::reader::Decoder(doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWriter for ebml::writer::Encoder {
|
impl FromWriter for ebml::writer::Encoder {
|
||||||
static fn from_writer(w: Writer) -> ebml::writer::Encoder {
|
static fn from_writer(w: Writer) -> ebml::writer::Encoder {
|
||||||
ebml::writer::Encoder(move w)
|
ebml::writer::Encoder(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ pub mod bytepipes {
|
||||||
}
|
}
|
||||||
|
|
||||||
if left == 0 {
|
if left == 0 {
|
||||||
return Some(move bytes);
|
return Some(bytes);
|
||||||
} else {
|
} else {
|
||||||
warn!("flatpipe: dropped %? broken bytes", left);
|
warn!("flatpipe: dropped %? broken bytes", left);
|
||||||
return None;
|
return None;
|
||||||
|
@ -554,7 +554,7 @@ pub mod bytepipes {
|
||||||
pub impl<R: Reader> ReaderBytePort<R> {
|
pub impl<R: Reader> ReaderBytePort<R> {
|
||||||
static fn new(r: R) -> ReaderBytePort<R> {
|
static fn new(r: R) -> ReaderBytePort<R> {
|
||||||
ReaderBytePort {
|
ReaderBytePort {
|
||||||
reader: move r
|
reader: r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ pub mod bytepipes {
|
||||||
pub impl<W: Writer> WriterByteChan<W> {
|
pub impl<W: Writer> WriterByteChan<W> {
|
||||||
static fn new(w: W) -> WriterByteChan<W> {
|
static fn new(w: W) -> WriterByteChan<W> {
|
||||||
WriterByteChan {
|
WriterByteChan {
|
||||||
writer: move w
|
writer: w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -587,17 +587,17 @@ pub mod bytepipes {
|
||||||
let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
|
let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
|
||||||
assert count > bytes.len();
|
assert count > bytes.len();
|
||||||
match self.try_recv(count - bytes.len()) {
|
match self.try_recv(count - bytes.len()) {
|
||||||
Some(move rest) => {
|
Some(rest) => {
|
||||||
bytes.push_all(rest);
|
bytes.push_all(rest);
|
||||||
return Some(move bytes);
|
return Some(bytes);
|
||||||
}
|
}
|
||||||
None => return None
|
None => return None
|
||||||
}
|
}
|
||||||
} else if self.buf.is_empty() {
|
} else if self.buf.is_empty() {
|
||||||
match self.port.try_recv() {
|
match self.port.try_recv() {
|
||||||
Some(move buf) => {
|
Some(buf) => {
|
||||||
assert !buf.is_empty();
|
assert !buf.is_empty();
|
||||||
self.buf = move buf;
|
self.buf = buf;
|
||||||
return self.try_recv(count);
|
return self.try_recv(count);
|
||||||
}
|
}
|
||||||
None => return None
|
None => return None
|
||||||
|
@ -610,14 +610,14 @@ pub mod bytepipes {
|
||||||
|
|
||||||
pub impl PipeByteChan: ByteChan {
|
pub impl PipeByteChan: ByteChan {
|
||||||
fn send(&self, val: ~[u8]) {
|
fn send(&self, val: ~[u8]) {
|
||||||
self.chan.send(move val)
|
self.chan.send(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl PipeBytePort {
|
pub impl PipeBytePort {
|
||||||
static fn new(p: Port<~[u8]>) -> PipeBytePort {
|
static fn new(p: Port<~[u8]>) -> PipeBytePort {
|
||||||
PipeBytePort {
|
PipeBytePort {
|
||||||
port: move p,
|
port: p,
|
||||||
buf: ~[]
|
buf: ~[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -626,7 +626,7 @@ pub mod bytepipes {
|
||||||
pub impl PipeByteChan {
|
pub impl PipeByteChan {
|
||||||
static fn new(c: Chan<~[u8]>) -> PipeByteChan {
|
static fn new(c: Chan<~[u8]>) -> PipeByteChan {
|
||||||
PipeByteChan {
|
PipeByteChan {
|
||||||
chan: move c
|
chan: c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -661,14 +661,14 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializing_memory_stream() {
|
fn test_serializing_memory_stream() {
|
||||||
let writer = BytesWriter();
|
let writer = BytesWriter();
|
||||||
let chan = serial::writer_chan(move writer);
|
let chan = serial::writer_chan(writer);
|
||||||
|
|
||||||
chan.send(10);
|
chan.send(10);
|
||||||
|
|
||||||
let bytes = chan.byte_chan.writer.bytes.get();
|
let bytes = chan.byte_chan.writer.bytes.get();
|
||||||
|
|
||||||
let reader = BufReader::new(move bytes);
|
let reader = BufReader::new(bytes);
|
||||||
let port = serial::reader_port(move reader);
|
let port = serial::reader_port(reader);
|
||||||
|
|
||||||
let res: int = port.recv();
|
let res: int = port.recv();
|
||||||
assert res == 10i;
|
assert res == 10i;
|
||||||
|
@ -678,7 +678,7 @@ mod test {
|
||||||
fn test_serializing_pipes() {
|
fn test_serializing_pipes() {
|
||||||
let (port, chan) = serial::pipe_stream();
|
let (port, chan) = serial::pipe_stream();
|
||||||
|
|
||||||
do task::spawn |move chan| {
|
do task::spawn || {
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
chan.send(i)
|
chan.send(i)
|
||||||
}
|
}
|
||||||
|
@ -693,7 +693,7 @@ mod test {
|
||||||
fn test_serializing_boxes() {
|
fn test_serializing_boxes() {
|
||||||
let (port, chan) = serial::pipe_stream();
|
let (port, chan) = serial::pipe_stream();
|
||||||
|
|
||||||
do task::spawn |move chan| {
|
do task::spawn || {
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
chan.send(@i)
|
chan.send(@i)
|
||||||
}
|
}
|
||||||
|
@ -707,14 +707,14 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pod_memory_stream() {
|
fn test_pod_memory_stream() {
|
||||||
let writer = BytesWriter();
|
let writer = BytesWriter();
|
||||||
let chan = pod::writer_chan(move writer);
|
let chan = pod::writer_chan(writer);
|
||||||
|
|
||||||
chan.send(10);
|
chan.send(10);
|
||||||
|
|
||||||
let bytes = chan.byte_chan.writer.bytes.get();
|
let bytes = chan.byte_chan.writer.bytes.get();
|
||||||
|
|
||||||
let reader = BufReader::new(move bytes);
|
let reader = BufReader::new(bytes);
|
||||||
let port = pod::reader_port(move reader);
|
let port = pod::reader_port(reader);
|
||||||
|
|
||||||
let res: int = port.recv();
|
let res: int = port.recv();
|
||||||
assert res == 10;
|
assert res == 10;
|
||||||
|
@ -724,7 +724,7 @@ mod test {
|
||||||
fn test_pod_pipes() {
|
fn test_pod_pipes() {
|
||||||
let (port, chan) = pod::pipe_stream();
|
let (port, chan) = pod::pipe_stream();
|
||||||
|
|
||||||
do task::spawn |move chan| {
|
do task::spawn || {
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
chan.send(i)
|
chan.send(i)
|
||||||
}
|
}
|
||||||
|
@ -741,11 +741,11 @@ mod test {
|
||||||
fn test_pod_tcp_stream() {
|
fn test_pod_tcp_stream() {
|
||||||
fn reader_port(buf: TcpSocketBuf
|
fn reader_port(buf: TcpSocketBuf
|
||||||
) -> pod::ReaderPort<int, TcpSocketBuf> {
|
) -> pod::ReaderPort<int, TcpSocketBuf> {
|
||||||
pod::reader_port(move buf)
|
pod::reader_port(buf)
|
||||||
}
|
}
|
||||||
fn writer_chan(buf: TcpSocketBuf
|
fn writer_chan(buf: TcpSocketBuf
|
||||||
) -> pod::WriterChan<int, TcpSocketBuf> {
|
) -> pod::WriterChan<int, TcpSocketBuf> {
|
||||||
pod::writer_chan(move buf)
|
pod::writer_chan(buf)
|
||||||
}
|
}
|
||||||
test_some_tcp_stream(reader_port, writer_chan, 9666);
|
test_some_tcp_stream(reader_port, writer_chan, 9666);
|
||||||
}
|
}
|
||||||
|
@ -755,11 +755,11 @@ mod test {
|
||||||
fn test_serializing_tcp_stream() {
|
fn test_serializing_tcp_stream() {
|
||||||
fn reader_port(buf: TcpSocketBuf
|
fn reader_port(buf: TcpSocketBuf
|
||||||
) -> serial::ReaderPort<int, TcpSocketBuf> {
|
) -> serial::ReaderPort<int, TcpSocketBuf> {
|
||||||
serial::reader_port(move buf)
|
serial::reader_port(buf)
|
||||||
}
|
}
|
||||||
fn writer_chan(buf: TcpSocketBuf
|
fn writer_chan(buf: TcpSocketBuf
|
||||||
) -> serial::WriterChan<int, TcpSocketBuf> {
|
) -> serial::WriterChan<int, TcpSocketBuf> {
|
||||||
serial::writer_chan(move buf)
|
serial::writer_chan(buf)
|
||||||
}
|
}
|
||||||
test_some_tcp_stream(reader_port, writer_chan, 9667);
|
test_some_tcp_stream(reader_port, writer_chan, 9667);
|
||||||
}
|
}
|
||||||
|
@ -790,27 +790,25 @@ mod test {
|
||||||
|
|
||||||
let addr0 = ip::v4::parse_addr("127.0.0.1");
|
let addr0 = ip::v4::parse_addr("127.0.0.1");
|
||||||
|
|
||||||
let begin_connect_chan = Cell(move begin_connect_chan);
|
let begin_connect_chan = Cell(begin_connect_chan);
|
||||||
let accept_chan = Cell(move accept_chan);
|
let accept_chan = Cell(accept_chan);
|
||||||
|
|
||||||
// The server task
|
// The server task
|
||||||
let addr = copy addr0;
|
let addr = copy addr0;
|
||||||
do task::spawn |move begin_connect_chan,
|
do task::spawn || {
|
||||||
move accept_chan| {
|
|
||||||
let iotask = &uv::global_loop::get();
|
let iotask = &uv::global_loop::get();
|
||||||
let begin_connect_chan = begin_connect_chan.take();
|
let begin_connect_chan = begin_connect_chan.take();
|
||||||
let accept_chan = accept_chan.take();
|
let accept_chan = accept_chan.take();
|
||||||
let listen_res = do tcp::listen(
|
let listen_res = do tcp::listen(
|
||||||
copy addr, port, 128, iotask,
|
copy addr, port, 128, iotask, |_kill_ch| {
|
||||||
|move begin_connect_chan, _kill_ch| {
|
|
||||||
// Tell the sender to initiate the connection
|
// Tell the sender to initiate the connection
|
||||||
debug!("listening");
|
debug!("listening");
|
||||||
begin_connect_chan.send(())
|
begin_connect_chan.send(())
|
||||||
}) |move accept_chan, new_conn, kill_ch| {
|
}) |new_conn, kill_ch| {
|
||||||
|
|
||||||
// Incoming connection. Send it to the receiver task to accept
|
// Incoming connection. Send it to the receiver task to accept
|
||||||
let (res_port, res_chan) = pipes::stream();
|
let (res_port, res_chan) = pipes::stream();
|
||||||
accept_chan.send((move new_conn, move res_chan));
|
accept_chan.send((new_conn, res_chan));
|
||||||
// Wait until the connection is accepted
|
// Wait until the connection is accepted
|
||||||
res_port.recv();
|
res_port.recv();
|
||||||
|
|
||||||
|
@ -823,8 +821,7 @@ mod test {
|
||||||
|
|
||||||
// Client task
|
// Client task
|
||||||
let addr = copy addr0;
|
let addr = copy addr0;
|
||||||
do task::spawn |move begin_connect_port,
|
do task::spawn || {
|
||||||
move writer_chan| {
|
|
||||||
|
|
||||||
// Wait for the server to start listening
|
// Wait for the server to start listening
|
||||||
begin_connect_port.recv();
|
begin_connect_port.recv();
|
||||||
|
@ -833,11 +830,11 @@ mod test {
|
||||||
let iotask = &uv::global_loop::get();
|
let iotask = &uv::global_loop::get();
|
||||||
let connect_result = tcp::connect(copy addr, port, iotask);
|
let connect_result = tcp::connect(copy addr, port, iotask);
|
||||||
assert connect_result.is_ok();
|
assert connect_result.is_ok();
|
||||||
let sock = result::unwrap(move connect_result);
|
let sock = result::unwrap(connect_result);
|
||||||
let socket_buf: tcp::TcpSocketBuf = tcp::socket_buf(move sock);
|
let socket_buf: tcp::TcpSocketBuf = tcp::socket_buf(sock);
|
||||||
|
|
||||||
// TcpSocketBuf is a Writer!
|
// TcpSocketBuf is a Writer!
|
||||||
let chan = writer_chan(move socket_buf);
|
let chan = writer_chan(socket_buf);
|
||||||
|
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
debug!("sending %?", i);
|
debug!("sending %?", i);
|
||||||
|
@ -846,9 +843,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reciever task
|
// Reciever task
|
||||||
do task::spawn |move accept_port, move finish_chan,
|
do task::spawn || {
|
||||||
move reader_port| {
|
|
||||||
|
|
||||||
// Wait for a connection
|
// Wait for a connection
|
||||||
let (conn, res_chan) = accept_port.recv();
|
let (conn, res_chan) = accept_port.recv();
|
||||||
|
|
||||||
|
@ -856,13 +851,13 @@ mod test {
|
||||||
let accept_result = tcp::accept(conn);
|
let accept_result = tcp::accept(conn);
|
||||||
debug!("accepted");
|
debug!("accepted");
|
||||||
assert accept_result.is_ok();
|
assert accept_result.is_ok();
|
||||||
let sock = result::unwrap(move accept_result);
|
let sock = result::unwrap(accept_result);
|
||||||
res_chan.send(());
|
res_chan.send(());
|
||||||
|
|
||||||
let socket_buf: tcp::TcpSocketBuf = tcp::socket_buf(move sock);
|
let socket_buf: tcp::TcpSocketBuf = tcp::socket_buf(sock);
|
||||||
|
|
||||||
// TcpSocketBuf is a Reader!
|
// TcpSocketBuf is a Reader!
|
||||||
let port = reader_port(move socket_buf);
|
let port = reader_port(socket_buf);
|
||||||
|
|
||||||
for int::range(0, 10) |i| {
|
for int::range(0, 10) |i| {
|
||||||
let j = port.recv();
|
let j = port.recv();
|
||||||
|
@ -897,22 +892,22 @@ mod test {
|
||||||
|
|
||||||
fn reader_port_loader(bytes: ~[u8]
|
fn reader_port_loader(bytes: ~[u8]
|
||||||
) -> pod::ReaderPort<int, BufReader> {
|
) -> pod::ReaderPort<int, BufReader> {
|
||||||
let reader = BufReader::new(move bytes);
|
let reader = BufReader::new(bytes);
|
||||||
pod::reader_port(move reader)
|
pod::reader_port(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pipe_port_loader(bytes: ~[u8]
|
fn pipe_port_loader(bytes: ~[u8]
|
||||||
) -> pod::PipePort<int> {
|
) -> pod::PipePort<int> {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
if !bytes.is_empty() {
|
if !bytes.is_empty() {
|
||||||
chan.send(move bytes);
|
chan.send(bytes);
|
||||||
}
|
}
|
||||||
pod::pipe_port(move port)
|
pod::pipe_port(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none1<P: BytePort>(loader: PortLoader<P>) {
|
fn test_try_recv_none1<P: BytePort>(loader: PortLoader<P>) {
|
||||||
let bytes = ~[];
|
let bytes = ~[];
|
||||||
let port = loader(move bytes);
|
let port = loader(bytes);
|
||||||
let res: Option<int> = port.try_recv();
|
let res: Option<int> = port.try_recv();
|
||||||
assert res.is_none();
|
assert res.is_none();
|
||||||
}
|
}
|
||||||
|
@ -929,7 +924,7 @@ mod test {
|
||||||
fn test_try_recv_none2<P: BytePort>(loader: PortLoader<P>) {
|
fn test_try_recv_none2<P: BytePort>(loader: PortLoader<P>) {
|
||||||
// The control word in the protocol is interrupted
|
// The control word in the protocol is interrupted
|
||||||
let bytes = ~[0];
|
let bytes = ~[0];
|
||||||
let port = loader(move bytes);
|
let port = loader(bytes);
|
||||||
let res: Option<int> = port.try_recv();
|
let res: Option<int> = port.try_recv();
|
||||||
assert res.is_none();
|
assert res.is_none();
|
||||||
}
|
}
|
||||||
|
@ -947,7 +942,7 @@ mod test {
|
||||||
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
||||||
// The control word is followed by garbage
|
// The control word is followed by garbage
|
||||||
let bytes = CONTINUE.to_vec() + ~[0];
|
let bytes = CONTINUE.to_vec() + ~[0];
|
||||||
let port = loader(move bytes);
|
let port = loader(bytes);
|
||||||
let res: Option<int> = port.try_recv();
|
let res: Option<int> = port.try_recv();
|
||||||
assert res.is_none();
|
assert res.is_none();
|
||||||
}
|
}
|
||||||
|
@ -962,7 +957,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_try_recv_none4<P: BytePort>(+loader: PortLoader<P>) {
|
fn test_try_recv_none4<P: BytePort>(+loader: PortLoader<P>) {
|
||||||
assert do task::try |move loader| {
|
assert do task::try || {
|
||||||
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
|
||||||
// The control word is followed by a valid length,
|
// The control word is followed by a valid length,
|
||||||
// then undeserializable garbage
|
// then undeserializable garbage
|
||||||
|
@ -972,7 +967,7 @@ mod test {
|
||||||
};
|
};
|
||||||
let bytes = CONTINUE.to_vec() + len_bytes + ~[0, 0, 0, 0];
|
let bytes = CONTINUE.to_vec() + len_bytes + ~[0, 0, 0, 0];
|
||||||
|
|
||||||
let port = loader(move bytes);
|
let port = loader(bytes);
|
||||||
|
|
||||||
let _res: Option<int> = port.try_recv();
|
let _res: Option<int> = port.try_recv();
|
||||||
}.is_err();
|
}.is_err();
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
|
||||||
Node(@ref kk, @copy v, left, right) => {
|
Node(@ref kk, @copy v, left, right) => {
|
||||||
if k == *kk {
|
if k == *kk {
|
||||||
Some(v)
|
Some(v)
|
||||||
} else if k < *kk { find(left, move k) } else { find(right, move k) }
|
} else if k < *kk { find(left, k) } else { find(right, k) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,10 +71,10 @@ impl<A> Future<A> {
|
||||||
|
|
||||||
let mut state = Evaluating;
|
let mut state = Evaluating;
|
||||||
self.state <-> state;
|
self.state <-> state;
|
||||||
match move state {
|
match state {
|
||||||
Forced(_) | Evaluating => fail!(~"Logic error."),
|
Forced(_) | Evaluating => fail!(~"Logic error."),
|
||||||
Pending(move f) => {
|
Pending(f) => {
|
||||||
self.state = Forced(move f());
|
self.state = Forced(f());
|
||||||
self.get_ref()
|
self.get_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ pub fn from_value<A>(val: A) -> Future<A> {
|
||||||
* not block.
|
* not block.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Future {state: Forced(move val)}
|
Future {state: Forced(val)}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_port<A:Owned>(port: PortOne<A>) ->
|
pub fn from_port<A:Owned>(port: PortOne<A>) ->
|
||||||
|
@ -102,13 +102,13 @@ pub fn from_port<A:Owned>(port: PortOne<A>) ->
|
||||||
* waiting for the result to be received on the port.
|
* waiting for the result to be received on the port.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let port = ~mut Some(move port);
|
let port = ~mut Some(port);
|
||||||
do from_fn |move port| {
|
do from_fn || {
|
||||||
let mut port_ = None;
|
let mut port_ = None;
|
||||||
port_ <-> *port;
|
port_ <-> *port;
|
||||||
let port = option::unwrap(move port_);
|
let port = option::unwrap(port_);
|
||||||
match recv(move port) {
|
match recv(port) {
|
||||||
oneshot::send(move data) => move data
|
oneshot::send(data) => data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ pub fn from_fn<A>(f: ~fn() -> A) -> Future<A> {
|
||||||
* function. It is not spawned into another task.
|
* function. It is not spawned into another task.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Future {state: Pending(move f)}
|
Future {state: Pending(f)}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn<A:Owned>(blk: fn~() -> A) -> Future<A> {
|
pub fn spawn<A:Owned>(blk: fn~() -> A) -> Future<A> {
|
||||||
|
@ -135,13 +135,13 @@ pub fn spawn<A:Owned>(blk: fn~() -> A) -> Future<A> {
|
||||||
|
|
||||||
let (chan, port) = oneshot::init();
|
let (chan, port) = oneshot::init();
|
||||||
|
|
||||||
let chan = ~mut Some(move chan);
|
let chan = ~mut Some(chan);
|
||||||
do task::spawn |move blk, move chan| {
|
do task::spawn || {
|
||||||
let chan = option::swap_unwrap(&mut *chan);
|
let chan = option::swap_unwrap(&mut *chan);
|
||||||
send_one(move chan, blk());
|
send_one(chan, blk());
|
||||||
}
|
}
|
||||||
|
|
||||||
return from_port(move port);
|
return from_port(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
|
@ -162,8 +162,8 @@ pub mod test {
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_from_port() {
|
pub fn test_from_port() {
|
||||||
let (ch, po) = oneshot::init();
|
let (ch, po) = oneshot::init();
|
||||||
send_one(move ch, ~"whale");
|
send_one(ch, ~"whale");
|
||||||
let f = from_port(move po);
|
let f = from_port(po);
|
||||||
assert f.get() == ~"whale";
|
assert f.get() == ~"whale";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ pub mod test {
|
||||||
pub fn test_sendable_future() {
|
pub fn test_sendable_future() {
|
||||||
let expected = ~"schlorf";
|
let expected = ~"schlorf";
|
||||||
let f = do spawn |copy expected| { copy expected };
|
let f = do spawn |copy expected| { copy expected };
|
||||||
do task::spawn |move f, move expected| {
|
do task::spawn |f, expected| {
|
||||||
let actual = f.get();
|
let actual = f.get();
|
||||||
assert actual == expected;
|
assert actual == expected;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
* fn do_work(in: &str, out: Option<~str>) {
|
* fn do_work(in: &str, out: Option<~str>) {
|
||||||
* io::println(in);
|
* io::println(in);
|
||||||
* io::println(match out {
|
* io::println(match out {
|
||||||
* Some(move x) => x,
|
* Some(x) => x,
|
||||||
* None => ~"No Output"
|
* None => ~"No Output"
|
||||||
* });
|
* });
|
||||||
* }
|
* }
|
||||||
|
@ -339,7 +339,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
return Ok(Matches {opts: vec::from_slice(opts),
|
return Ok(Matches {opts: vec::from_slice(opts),
|
||||||
vals: move vals,
|
vals: vals,
|
||||||
free: free});
|
free: free});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1178,7 @@ mod tests {
|
||||||
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
|
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
|
||||||
let opts = ~[optopt(~"e"), optopt(~"encrypt")];
|
let opts = ~[optopt(~"e"), optopt(~"encrypt")];
|
||||||
let matches = &match getopts(args, opts) {
|
let matches = &match getopts(args, opts) {
|
||||||
result::Ok(move m) => m,
|
result::Ok(m) => m,
|
||||||
result::Err(_) => fail!()
|
result::Err(_) => fail!()
|
||||||
};
|
};
|
||||||
assert opts_present(matches, ~[~"e"]);
|
assert opts_present(matches, ~[~"e"]);
|
||||||
|
@ -1199,7 +1199,7 @@ mod tests {
|
||||||
let args = ~[~"-Lfoo", ~"-M."];
|
let args = ~[~"-Lfoo", ~"-M."];
|
||||||
let opts = ~[optmulti(~"L"), optmulti(~"M")];
|
let opts = ~[optmulti(~"L"), optmulti(~"M")];
|
||||||
let matches = &match getopts(args, opts) {
|
let matches = &match getopts(args, opts) {
|
||||||
result::Ok(move m) => m,
|
result::Ok(m) => m,
|
||||||
result::Err(_) => fail!()
|
result::Err(_) => fail!()
|
||||||
};
|
};
|
||||||
assert opts_present(matches, ~[~"L"]);
|
assert opts_present(matches, ~[~"L"]);
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct BufReader {
|
||||||
pub impl BufReader {
|
pub impl BufReader {
|
||||||
static pub fn new(v: ~[u8]) -> BufReader {
|
static pub fn new(v: ~[u8]) -> BufReader {
|
||||||
BufReader {
|
BufReader {
|
||||||
buf: move v,
|
buf: v,
|
||||||
pos: 0
|
pos: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ pub impl BufReader {
|
||||||
// FIXME #4429: This isn't correct if f fails
|
// FIXME #4429: This isn't correct if f fails
|
||||||
self.pos = bytes_reader.pos;
|
self.pos = bytes_reader.pos;
|
||||||
|
|
||||||
return move res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,18 +388,18 @@ pub fn Parser(rdr: io::Reader) -> Parser {
|
||||||
|
|
||||||
pub impl Parser {
|
pub impl Parser {
|
||||||
fn parse() -> Result<Json, Error> {
|
fn parse() -> Result<Json, Error> {
|
||||||
match move self.parse_value() {
|
match self.parse_value() {
|
||||||
Ok(move value) => {
|
Ok(value) => {
|
||||||
// Skip trailing whitespaces.
|
// Skip trailing whitespaces.
|
||||||
self.parse_whitespace();
|
self.parse_whitespace();
|
||||||
// Make sure there is no trailing characters.
|
// Make sure there is no trailing characters.
|
||||||
if self.eof() {
|
if self.eof() {
|
||||||
Ok(move value)
|
Ok(value)
|
||||||
} else {
|
} else {
|
||||||
self.error(~"trailing characters")
|
self.error(~"trailing characters")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(move e) => Err(e)
|
Err(e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,9 +438,9 @@ priv impl Parser {
|
||||||
'f' => self.parse_ident(~"alse", Boolean(false)),
|
'f' => self.parse_ident(~"alse", Boolean(false)),
|
||||||
'0' .. '9' | '-' => self.parse_number(),
|
'0' .. '9' | '-' => self.parse_number(),
|
||||||
'"' =>
|
'"' =>
|
||||||
match move self.parse_str() {
|
match self.parse_str() {
|
||||||
Ok(move s) => Ok(String(s)),
|
Ok(s) => Ok(String(s)),
|
||||||
Err(move e) => Err(e),
|
Err(e) => Err(e),
|
||||||
},
|
},
|
||||||
'[' => self.parse_list(),
|
'[' => self.parse_list(),
|
||||||
'{' => self.parse_object(),
|
'{' => self.parse_object(),
|
||||||
|
@ -455,7 +455,7 @@ priv impl Parser {
|
||||||
fn parse_ident(ident: &str, value: Json) -> Result<Json, Error> {
|
fn parse_ident(ident: &str, value: Json) -> Result<Json, Error> {
|
||||||
if str::all(ident, |c| c == self.next_char()) {
|
if str::all(ident, |c| c == self.next_char()) {
|
||||||
self.bump();
|
self.bump();
|
||||||
Ok(move value)
|
Ok(value)
|
||||||
} else {
|
} else {
|
||||||
self.error(~"invalid syntax")
|
self.error(~"invalid syntax")
|
||||||
}
|
}
|
||||||
|
@ -662,13 +662,13 @@ priv impl Parser {
|
||||||
|
|
||||||
if self.ch == ']' {
|
if self.ch == ']' {
|
||||||
self.bump();
|
self.bump();
|
||||||
return Ok(List(move values));
|
return Ok(List(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match move self.parse_value() {
|
match self.parse_value() {
|
||||||
Ok(move v) => values.push(move v),
|
Ok(v) => values.push(v),
|
||||||
Err(move e) => return Err(e)
|
Err(e) => return Err(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parse_whitespace();
|
self.parse_whitespace();
|
||||||
|
@ -678,7 +678,7 @@ priv impl Parser {
|
||||||
|
|
||||||
match self.ch {
|
match self.ch {
|
||||||
',' => self.bump(),
|
',' => self.bump(),
|
||||||
']' => { self.bump(); return Ok(List(move values)); }
|
']' => { self.bump(); return Ok(List(values)); }
|
||||||
_ => return self.error(~"expected `,` or `]`")
|
_ => return self.error(~"expected `,` or `]`")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -692,7 +692,7 @@ priv impl Parser {
|
||||||
|
|
||||||
if self.ch == '}' {
|
if self.ch == '}' {
|
||||||
self.bump();
|
self.bump();
|
||||||
return Ok(Object(move values));
|
return Ok(Object(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
while !self.eof() {
|
while !self.eof() {
|
||||||
|
@ -702,9 +702,9 @@ priv impl Parser {
|
||||||
return self.error(~"key must be a string");
|
return self.error(~"key must be a string");
|
||||||
}
|
}
|
||||||
|
|
||||||
let key = match move self.parse_str() {
|
let key = match self.parse_str() {
|
||||||
Ok(move key) => key,
|
Ok(key) => key,
|
||||||
Err(move e) => return Err(e)
|
Err(e) => return Err(e)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.parse_whitespace();
|
self.parse_whitespace();
|
||||||
|
@ -715,15 +715,15 @@ priv impl Parser {
|
||||||
}
|
}
|
||||||
self.bump();
|
self.bump();
|
||||||
|
|
||||||
match move self.parse_value() {
|
match self.parse_value() {
|
||||||
Ok(move value) => { values.insert(key, move value); }
|
Ok(value) => { values.insert(key, value); }
|
||||||
Err(move e) => return Err(e)
|
Err(e) => return Err(e)
|
||||||
}
|
}
|
||||||
self.parse_whitespace();
|
self.parse_whitespace();
|
||||||
|
|
||||||
match self.ch {
|
match self.ch {
|
||||||
',' => self.bump(),
|
',' => self.bump(),
|
||||||
'}' => { self.bump(); return Ok(Object(move values)); }
|
'}' => { self.bump(); return Ok(Object(values)); }
|
||||||
_ => {
|
_ => {
|
||||||
if self.eof() { break; }
|
if self.eof() { break; }
|
||||||
return self.error(~"expected `,` or `}`");
|
return self.error(~"expected `,` or `}`");
|
||||||
|
@ -753,7 +753,7 @@ pub struct Decoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Decoder(json: Json) -> Decoder {
|
pub fn Decoder(json: Json) -> Decoder {
|
||||||
Decoder { json: move json, stack: ~[] }
|
Decoder { json: json, stack: ~[] }
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl Decoder {
|
priv impl Decoder {
|
||||||
|
@ -868,7 +868,7 @@ pub impl Decoder: serialize::Decoder {
|
||||||
};
|
};
|
||||||
let res = f(len);
|
let res = f(len);
|
||||||
self.pop();
|
self.pop();
|
||||||
move res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T {
|
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T {
|
||||||
|
@ -879,7 +879,7 @@ pub impl Decoder: serialize::Decoder {
|
||||||
};
|
};
|
||||||
let res = f(len);
|
let res = f(len);
|
||||||
self.pop();
|
self.pop();
|
||||||
move res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
|
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
|
||||||
|
@ -897,14 +897,14 @@ pub impl Decoder: serialize::Decoder {
|
||||||
debug!("read_rec()");
|
debug!("read_rec()");
|
||||||
let value = f();
|
let value = f();
|
||||||
self.pop();
|
self.pop();
|
||||||
move value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_struct<T>(&self, _name: &str, _len: uint, f: fn() -> T) -> T {
|
fn read_struct<T>(&self, _name: &str, _len: uint, f: fn() -> T) -> T {
|
||||||
debug!("read_struct()");
|
debug!("read_struct()");
|
||||||
let value = f();
|
let value = f();
|
||||||
self.pop();
|
self.pop();
|
||||||
move value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T {
|
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T {
|
||||||
|
@ -934,7 +934,7 @@ pub impl Decoder: serialize::Decoder {
|
||||||
debug!("read_tup(len=%u)", len);
|
debug!("read_tup(len=%u)", len);
|
||||||
let value = f();
|
let value = f();
|
||||||
self.pop();
|
self.pop();
|
||||||
move value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
|
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
|
||||||
|
@ -1219,11 +1219,11 @@ mod tests {
|
||||||
|
|
||||||
for items.each |item| {
|
for items.each |item| {
|
||||||
match *item {
|
match *item {
|
||||||
(copy key, copy value) => { d.insert(key, move value); },
|
(copy key, copy value) => { d.insert(key, value); },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object(move d)
|
Object(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -181,7 +181,7 @@ pub mod v4 {
|
||||||
*/
|
*/
|
||||||
pub fn parse_addr(ip: &str) -> IpAddr {
|
pub fn parse_addr(ip: &str) -> IpAddr {
|
||||||
match try_parse_addr(ip) {
|
match try_parse_addr(ip) {
|
||||||
result::Ok(move addr) => move addr,
|
result::Ok(addr) => addr,
|
||||||
result::Err(ref err_data) => fail!(err_data.err_msg)
|
result::Err(ref err_data) => fail!(err_data.err_msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ pub mod v6 {
|
||||||
*/
|
*/
|
||||||
pub fn parse_addr(ip: &str) -> IpAddr {
|
pub fn parse_addr(ip: &str) -> IpAddr {
|
||||||
match try_parse_addr(ip) {
|
match try_parse_addr(ip) {
|
||||||
result::Ok(move addr) => move addr,
|
result::Ok(addr) => addr,
|
||||||
result::Err(copy err_data) => fail!(err_data.err_msg)
|
result::Err(copy err_data) => fail!(err_data.err_msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||||
result::Err(GetAddrUnknownError));
|
result::Err(GetAddrUnknownError));
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
out_vec.push(move new_ip_addr);
|
out_vec.push(new_ip_addr);
|
||||||
|
|
||||||
let next_addr = ll::get_next_addrinfo(curr_addr);
|
let next_addr = ll::get_next_addrinfo(curr_addr);
|
||||||
if next_addr == ptr::null::<addrinfo>() as *addrinfo {
|
if next_addr == ptr::null::<addrinfo>() as *addrinfo {
|
||||||
|
@ -345,7 +345,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||||
}
|
}
|
||||||
log(debug, fmt!("successful process addrinfo result, len: %?",
|
log(debug, fmt!("successful process addrinfo result, len: %?",
|
||||||
vec::len(out_vec)));
|
vec::len(out_vec)));
|
||||||
output_ch.send(result::Ok(move out_vec));
|
output_ch.send(result::Ok(out_vec));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log(debug, ~"addrinfo pointer is NULL");
|
log(debug, ~"addrinfo pointer is NULL");
|
||||||
|
@ -427,7 +427,7 @@ mod test {
|
||||||
}
|
}
|
||||||
// note really sure how to realiably test/assert
|
// note really sure how to realiably test/assert
|
||||||
// this.. mostly just wanting to see it work, atm.
|
// this.. mostly just wanting to see it work, atm.
|
||||||
let results = result::unwrap(move ga_result);
|
let results = result::unwrap(ga_result);
|
||||||
log(debug, fmt!("test_get_addr: Number of results for %s: %?",
|
log(debug, fmt!("test_get_addr: Number of results for %s: %?",
|
||||||
localhost_name, vec::len(results)));
|
localhost_name, vec::len(results)));
|
||||||
for vec::each(results) |r| {
|
for vec::each(results) |r| {
|
||||||
|
|
|
@ -177,7 +177,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
|
||||||
// we can send into the interact cb to be handled in libuv..
|
// we can send into the interact cb to be handled in libuv..
|
||||||
debug!("stream_handle_ptr outside interact %?",
|
debug!("stream_handle_ptr outside interact %?",
|
||||||
stream_handle_ptr);
|
stream_handle_ptr);
|
||||||
do iotask::interact(iotask) |move input_ip, loop_ptr| {
|
do iotask::interact(iotask) |loop_ptr| {
|
||||||
unsafe {
|
unsafe {
|
||||||
debug!("in interact cb for tcp client connect..");
|
debug!("in interact cb for tcp client connect..");
|
||||||
debug!("stream_handle_ptr in interact %?",
|
debug!("stream_handle_ptr in interact %?",
|
||||||
|
@ -629,10 +629,10 @@ pub fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
new_connect_cb: fn~(TcpNewConnection,
|
new_connect_cb: fn~(TcpNewConnection,
|
||||||
SharedChan<Option<TcpErrData>>))
|
SharedChan<Option<TcpErrData>>))
|
||||||
-> result::Result<(), TcpListenErrData> {
|
-> result::Result<(), TcpListenErrData> {
|
||||||
do listen_common(move host_ip, port, backlog, iotask,
|
do listen_common(host_ip, port, backlog, iotask,
|
||||||
move on_establish_cb)
|
on_establish_cb)
|
||||||
// on_connect_cb
|
// on_connect_cb
|
||||||
|move new_connect_cb, handle| {
|
|handle| {
|
||||||
unsafe {
|
unsafe {
|
||||||
let server_data_ptr = uv::ll::get_data_for_uv_handle(handle)
|
let server_data_ptr = uv::ll::get_data_for_uv_handle(handle)
|
||||||
as *TcpListenFcData;
|
as *TcpListenFcData;
|
||||||
|
@ -659,7 +659,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
server_stream_ptr: server_stream_ptr,
|
server_stream_ptr: server_stream_ptr,
|
||||||
stream_closed_ch: stream_closed_ch,
|
stream_closed_ch: stream_closed_ch,
|
||||||
kill_ch: kill_ch.clone(),
|
kill_ch: kill_ch.clone(),
|
||||||
on_connect_cb: move on_connect_cb,
|
on_connect_cb: on_connect_cb,
|
||||||
iotask: iotask.clone(),
|
iotask: iotask.clone(),
|
||||||
ipv6: match &host_ip {
|
ipv6: match &host_ip {
|
||||||
&ip::Ipv4(_) => { false }
|
&ip::Ipv4(_) => { false }
|
||||||
|
@ -678,7 +678,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
// tcp::connect (because the iotask::interact cb isn't
|
// tcp::connect (because the iotask::interact cb isn't
|
||||||
// nested within a core::comm::listen block)
|
// nested within a core::comm::listen block)
|
||||||
let loc_ip = copy(host_ip);
|
let loc_ip = copy(host_ip);
|
||||||
do iotask::interact(iotask) |move loc_ip, loop_ptr| {
|
do iotask::interact(iotask) |loop_ptr| {
|
||||||
unsafe {
|
unsafe {
|
||||||
match uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
|
match uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
|
||||||
0i32 => {
|
0i32 => {
|
||||||
|
@ -815,7 +815,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
*/
|
*/
|
||||||
pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
||||||
TcpSocketBuf(@TcpBufferedSocketData {
|
TcpSocketBuf(@TcpBufferedSocketData {
|
||||||
sock: move sock, mut buf: ~[], buf_off: 0
|
sock: sock, mut buf: ~[], buf_off: 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,12 +851,12 @@ impl TcpSocket {
|
||||||
let addr = uv::ll::ip6_addr("", 0);
|
let addr = uv::ll::ip6_addr("", 0);
|
||||||
uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr,
|
uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr,
|
||||||
ptr::addr_of(&addr));
|
ptr::addr_of(&addr));
|
||||||
ip::Ipv6(move addr)
|
ip::Ipv6(addr)
|
||||||
} else {
|
} else {
|
||||||
let addr = uv::ll::ip4_addr("", 0);
|
let addr = uv::ll::ip4_addr("", 0);
|
||||||
uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr,
|
uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr,
|
||||||
ptr::addr_of(&addr));
|
ptr::addr_of(&addr));
|
||||||
ip::Ipv4(move addr)
|
ip::Ipv4(addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1047,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
|
||||||
Some(result::get(&rs_result).recv())
|
Some(result::get(&rs_result).recv())
|
||||||
};
|
};
|
||||||
log(debug, ~"tcp::read after recv_timeout");
|
log(debug, ~"tcp::read after recv_timeout");
|
||||||
match move read_result {
|
match read_result {
|
||||||
None => {
|
None => {
|
||||||
log(debug, ~"tcp::read: timed out..");
|
log(debug, ~"tcp::read: timed out..");
|
||||||
let err_data = TcpErrData {
|
let err_data = TcpErrData {
|
||||||
|
@ -1057,7 +1057,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
|
||||||
read_stop_common_impl(socket_data);
|
read_stop_common_impl(socket_data);
|
||||||
result::Err(err_data)
|
result::Err(err_data)
|
||||||
}
|
}
|
||||||
Some(move data_result) => {
|
Some(data_result) => {
|
||||||
log(debug, ~"tcp::read got data");
|
log(debug, ~"tcp::read got data");
|
||||||
read_stop_common_impl(socket_data);
|
read_stop_common_impl(socket_data);
|
||||||
data_result
|
data_result
|
||||||
|
@ -1091,7 +1091,7 @@ fn read_stop_common_impl(socket_data: *TcpSocketData) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match stop_po.recv() {
|
match stop_po.recv() {
|
||||||
Some(move err_data) => Err(err_data),
|
Some(err_data) => Err(err_data),
|
||||||
None => Ok(())
|
None => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1183,7 +1183,7 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
|
||||||
// aftermath, so we don't have to sit here blocking.
|
// aftermath, so we don't have to sit here blocking.
|
||||||
match result_po.recv() {
|
match result_po.recv() {
|
||||||
TcpWriteSuccess => Ok(()),
|
TcpWriteSuccess => Ok(()),
|
||||||
TcpWriteError(move err_data) => Err(err_data)
|
TcpWriteError(err_data) => Err(err_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1613,10 +1613,10 @@ pub mod test {
|
||||||
debug!("server started, firing up client..");
|
debug!("server started, firing up client..");
|
||||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||||
let iotask = uv::global_loop::get();
|
let iotask = uv::global_loop::get();
|
||||||
let connect_result = connect(move server_ip_addr, server_port,
|
let connect_result = connect(server_ip_addr, server_port,
|
||||||
&iotask);
|
&iotask);
|
||||||
|
|
||||||
let sock = result::unwrap(move connect_result);
|
let sock = result::unwrap(connect_result);
|
||||||
|
|
||||||
debug!("testing peer address");
|
debug!("testing peer address");
|
||||||
// This is what we are actually testing!
|
// This is what we are actually testing!
|
||||||
|
@ -1784,11 +1784,11 @@ pub mod test {
|
||||||
// client
|
// client
|
||||||
debug!("server started, firing up client..");
|
debug!("server started, firing up client..");
|
||||||
let server_addr = ip::v4::parse_addr(server_ip);
|
let server_addr = ip::v4::parse_addr(server_ip);
|
||||||
let conn_result = connect(move server_addr, server_port, hl_loop);
|
let conn_result = connect(server_addr, server_port, hl_loop);
|
||||||
if result::is_err(&conn_result) {
|
if result::is_err(&conn_result) {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
let sock_buf = @socket_buf(result::unwrap(move conn_result));
|
let sock_buf = @socket_buf(result::unwrap(conn_result));
|
||||||
buf_write(sock_buf, expected_req);
|
buf_write(sock_buf, expected_req);
|
||||||
|
|
||||||
let buf_reader = sock_buf as Reader;
|
let buf_reader = sock_buf as Reader;
|
||||||
|
@ -1819,7 +1819,7 @@ pub mod test {
|
||||||
let (server_po, server_ch) = stream::<~str>();
|
let (server_po, server_ch) = stream::<~str>();
|
||||||
let server_ch = SharedChan(server_ch);
|
let server_ch = SharedChan(server_ch);
|
||||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||||
let listen_result = listen(move server_ip_addr, server_port, 128,
|
let listen_result = listen(server_ip_addr, server_port, 128,
|
||||||
iotask,
|
iotask,
|
||||||
// on_establish_cb -- called when listener is set up
|
// on_establish_cb -- called when listener is set up
|
||||||
|kill_ch| {
|
|kill_ch| {
|
||||||
|
@ -1849,15 +1849,15 @@ pub mod test {
|
||||||
else {
|
else {
|
||||||
debug!("SERVER/WORKER: send on cont ch");
|
debug!("SERVER/WORKER: send on cont ch");
|
||||||
cont_ch.send(());
|
cont_ch.send(());
|
||||||
let sock = result::unwrap(move accept_result);
|
let sock = result::unwrap(accept_result);
|
||||||
let peer_addr = sock.get_peer_addr();
|
let peer_addr = sock.get_peer_addr();
|
||||||
debug!("SERVER: successfully accepted \
|
debug!("SERVER: successfully accepted \
|
||||||
connection from %s:%u",
|
connection from %s:%u",
|
||||||
ip::format_addr(&peer_addr),
|
ip::format_addr(&peer_addr),
|
||||||
ip::get_port(&peer_addr));
|
ip::get_port(&peer_addr));
|
||||||
let received_req_bytes = read(&sock, 0u);
|
let received_req_bytes = read(&sock, 0u);
|
||||||
match move received_req_bytes {
|
match received_req_bytes {
|
||||||
result::Ok(move data) => {
|
result::Ok(data) => {
|
||||||
debug!("SERVER: got REQ str::from_bytes..");
|
debug!("SERVER: got REQ str::from_bytes..");
|
||||||
debug!("SERVER: REQ data len: %?",
|
debug!("SERVER: REQ data len: %?",
|
||||||
vec::len(data));
|
vec::len(data));
|
||||||
|
@ -1868,7 +1868,7 @@ pub mod test {
|
||||||
debug!("SERVER: after write.. die");
|
debug!("SERVER: after write.. die");
|
||||||
kill_ch.send(None);
|
kill_ch.send(None);
|
||||||
}
|
}
|
||||||
result::Err(move err_data) => {
|
result::Err(err_data) => {
|
||||||
debug!("SERVER: error recvd: %s %s",
|
debug!("SERVER: error recvd: %s %s",
|
||||||
err_data.err_name, err_data.err_msg);
|
err_data.err_name, err_data.err_msg);
|
||||||
kill_ch.send(Some(err_data));
|
kill_ch.send(Some(err_data));
|
||||||
|
@ -1904,7 +1904,7 @@ pub mod test {
|
||||||
fn run_tcp_test_server_fail(server_ip: &str, server_port: uint,
|
fn run_tcp_test_server_fail(server_ip: &str, server_port: uint,
|
||||||
iotask: &IoTask) -> TcpListenErrData {
|
iotask: &IoTask) -> TcpListenErrData {
|
||||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||||
let listen_result = listen(move server_ip_addr, server_port, 128,
|
let listen_result = listen(server_ip_addr, server_port, 128,
|
||||||
iotask,
|
iotask,
|
||||||
// on_establish_cb -- called when listener is set up
|
// on_establish_cb -- called when listener is set up
|
||||||
|kill_ch| {
|
|kill_ch| {
|
||||||
|
@ -1929,7 +1929,7 @@ pub mod test {
|
||||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||||
|
|
||||||
debug!("CLIENT: starting..");
|
debug!("CLIENT: starting..");
|
||||||
let connect_result = connect(move server_ip_addr, server_port,
|
let connect_result = connect(server_ip_addr, server_port,
|
||||||
iotask);
|
iotask);
|
||||||
if result::is_err(&connect_result) {
|
if result::is_err(&connect_result) {
|
||||||
debug!("CLIENT: failed to connect");
|
debug!("CLIENT: failed to connect");
|
||||||
|
@ -1937,7 +1937,7 @@ pub mod test {
|
||||||
Err(err_data)
|
Err(err_data)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let sock = result::unwrap(move connect_result);
|
let sock = result::unwrap(connect_result);
|
||||||
let resp_bytes = str::to_bytes(resp);
|
let resp_bytes = str::to_bytes(resp);
|
||||||
tcp_write_single(&sock, resp_bytes);
|
tcp_write_single(&sock, resp_bytes);
|
||||||
let read_result = sock.read(0u);
|
let read_result = sock.read(0u);
|
||||||
|
|
|
@ -253,7 +253,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
|
||||||
'&' | ';' => {
|
'&' | ';' => {
|
||||||
if key != ~"" && value != ~"" {
|
if key != ~"" && value != ~"" {
|
||||||
let mut values = match m.pop(&key) {
|
let mut values = match m.pop(&key) {
|
||||||
Some(move values) => values,
|
Some(values) => values,
|
||||||
None => ~[],
|
None => ~[],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
|
||||||
|
|
||||||
if key != ~"" && value != ~"" {
|
if key != ~"" && value != ~"" {
|
||||||
let mut values = match m.pop(&key) {
|
let mut values = match m.pop(&key) {
|
||||||
Some(move values) => values,
|
Some(values) => values,
|
||||||
None => ~[],
|
None => ~[],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ pub pure fn from_str(rawurl: &str) -> Result<Url, ~str> {
|
||||||
impl FromStr for Url {
|
impl FromStr for Url {
|
||||||
static pure fn from_str(s: &str) -> Option<Url> {
|
static pure fn from_str(s: &str) -> Option<Url> {
|
||||||
match from_str(s) {
|
match from_str(s) {
|
||||||
Ok(move url) => Some(url),
|
Ok(url) => Some(url),
|
||||||
Err(_) => None
|
Err(_) => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ pub mod chained {
|
||||||
entry.next = new_chains[idx];
|
entry.next = new_chains[idx];
|
||||||
new_chains[idx] = Some(entry);
|
new_chains[idx] = Some(entry);
|
||||||
}
|
}
|
||||||
self.chains = move new_chains;
|
self.chains = new_chains;
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn each_entry(blk: fn(@Entry<K,V>) -> bool) {
|
pure fn each_entry(blk: fn(@Entry<K,V>) -> bool) {
|
||||||
|
@ -321,7 +321,7 @@ pub mod chained {
|
||||||
if opt_v.is_none() {
|
if opt_v.is_none() {
|
||||||
fail!(fmt!("Key not found in table: %?", k));
|
fail!(fmt!("Key not found in table: %?", k));
|
||||||
}
|
}
|
||||||
option::unwrap(move opt_v)
|
option::unwrap(opt_v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T {
|
||||||
error!("smallintmap::get(): key not present");
|
error!("smallintmap::get(): key not present");
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
Some(move v) => return v
|
Some(v) => return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn map_slices<A: Copy Owned, B: Copy Owned>(
|
||||||
do vec::as_imm_buf(xs) |p, _len| {
|
do vec::as_imm_buf(xs) |p, _len| {
|
||||||
let f = f();
|
let f = f();
|
||||||
let base = base;
|
let base = base;
|
||||||
let f = do future_spawn() |move f| {
|
let f = do future_spawn() || {
|
||||||
unsafe {
|
unsafe {
|
||||||
let len = end - base;
|
let len = end - base;
|
||||||
let slice = (ptr::offset(p, base),
|
let slice = (ptr::offset(p, base),
|
||||||
|
@ -72,7 +72,7 @@ fn map_slices<A: Copy Owned, B: Copy Owned>(
|
||||||
f(base, slice)
|
f(base, slice)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
futures.push(move f);
|
futures.push(f);
|
||||||
};
|
};
|
||||||
base += items_per_task;
|
base += items_per_task;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,27 +139,27 @@ impl <T: Ord> PriorityQueue<T> {
|
||||||
|
|
||||||
priv fn siftup(&mut self, start: uint, mut pos: uint) {
|
priv fn siftup(&mut self, start: uint, mut pos: uint) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let new = move *addr_of(&self.data[pos]);
|
let new = *addr_of(&self.data[pos]);
|
||||||
|
|
||||||
while pos > start {
|
while pos > start {
|
||||||
let parent = (pos - 1) >> 1;
|
let parent = (pos - 1) >> 1;
|
||||||
if new > self.data[parent] {
|
if new > self.data[parent] {
|
||||||
let mut x = rusti::init();
|
let mut x = rusti::init();
|
||||||
x <-> self.data[parent];
|
x <-> self.data[parent];
|
||||||
rusti::move_val_init(&mut self.data[pos], move x);
|
rusti::move_val_init(&mut self.data[pos], x);
|
||||||
pos = parent;
|
pos = parent;
|
||||||
loop
|
loop
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
rusti::move_val_init(&mut self.data[pos], move new);
|
rusti::move_val_init(&mut self.data[pos], new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
|
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let start = pos;
|
let start = pos;
|
||||||
let new = move *addr_of(&self.data[pos]);
|
let new = *addr_of(&self.data[pos]);
|
||||||
|
|
||||||
let mut child = 2 * pos + 1;
|
let mut child = 2 * pos + 1;
|
||||||
while child < end {
|
while child < end {
|
||||||
|
@ -169,12 +169,12 @@ impl <T: Ord> PriorityQueue<T> {
|
||||||
}
|
}
|
||||||
let mut x = rusti::init();
|
let mut x = rusti::init();
|
||||||
x <-> self.data[child];
|
x <-> self.data[child];
|
||||||
rusti::move_val_init(&mut self.data[pos], move x);
|
rusti::move_val_init(&mut self.data[pos], x);
|
||||||
pos = child;
|
pos = child;
|
||||||
child = 2 * pos + 1;
|
child = 2 * pos + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rusti::move_val_init(&mut self.data[pos], move new);
|
rusti::move_val_init(&mut self.data[pos], new);
|
||||||
self.siftup(start, pos);
|
self.siftup(start, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ fn complete_key(_v: @CompletionCb) {}
|
||||||
/// Bind to the main completion callback
|
/// Bind to the main completion callback
|
||||||
pub unsafe fn complete(cb: CompletionCb) {
|
pub unsafe fn complete(cb: CompletionCb) {
|
||||||
unsafe {
|
unsafe {
|
||||||
task::local_data::local_data_set(complete_key, @(move cb));
|
task::local_data::local_data_set(complete_key, @(cb));
|
||||||
|
|
||||||
extern fn callback(line: *c_char, completions: *()) {
|
extern fn callback(line: *c_char, completions: *()) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -848,11 +848,11 @@ pub mod node {
|
||||||
offset += 1u;
|
offset += 1u;
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
cast::forget(move local_buf);
|
cast::forget(local_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cast::transmute(move buf);
|
return cast::transmute(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ pub fn sha1() -> Sha1 {
|
||||||
computed: false,
|
computed: false,
|
||||||
work_buf: @mut vec::from_elem(work_buf_len, 0u32)
|
work_buf: @mut vec::from_elem(work_buf_len, 0u32)
|
||||||
};
|
};
|
||||||
let mut sh = (move st) as Sha1;
|
let mut sh = (st) as Sha1;
|
||||||
sh.reset();
|
sh.reset();
|
||||||
return sh;
|
return sh;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub pure fn merge_sort<T: Copy>(v: &[const T], le: Le<T>) -> ~[T] {
|
||||||
}
|
}
|
||||||
rs.push_all(vec::slice(a, a_ix, a_len));
|
rs.push_all(vec::slice(a, a_ix, a_len));
|
||||||
rs.push_all(vec::slice(b, b_ix, b_len));
|
rs.push_all(vec::slice(b, b_ix, b_len));
|
||||||
move rs
|
rs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ fn binarysort<T: Copy Ord>(array: &mut [T], start: uint) {
|
||||||
let mut n = start-left;
|
let mut n = start-left;
|
||||||
|
|
||||||
copy_vec(array, left+1, array, left, n);
|
copy_vec(array, left+1, array, left, n);
|
||||||
array[left] = move pivot;
|
array[left] = pivot;
|
||||||
start += 1;
|
start += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ mod test_qsort {
|
||||||
|
|
||||||
do quick_sort(names) |x, y| { int::le(*x, *y) };
|
do quick_sort(names) |x, y| { int::le(*x, *y) };
|
||||||
|
|
||||||
let immut_names = move names;
|
let immut_names = names;
|
||||||
|
|
||||||
let pairs = vec::zip_slice(expected, immut_names);
|
let pairs = vec::zip_slice(expected, immut_names);
|
||||||
for vec::each(pairs) |p| {
|
for vec::each(pairs) |p| {
|
||||||
|
@ -1022,14 +1022,14 @@ mod big_tests {
|
||||||
let res = do vec::from_fn(num) |i| {
|
let res = do vec::from_fn(num) |i| {
|
||||||
arr[i % size]
|
arr[i % size]
|
||||||
};
|
};
|
||||||
move res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn makeRange(n: uint) -> ~[uint] {
|
fn makeRange(n: uint) -> ~[uint] {
|
||||||
let one = do vec::from_fn(n) |i| { i };
|
let one = do vec::from_fn(n) |i| { i };
|
||||||
let mut two = copy one;
|
let mut two = copy one;
|
||||||
vec::reverse(two);
|
vec::reverse(two);
|
||||||
vec::append(move two, one)
|
vec::append(two, one)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tabulate_unique(lo: uint, hi: uint) {
|
fn tabulate_unique(lo: uint, hi: uint) {
|
||||||
|
@ -1048,7 +1048,7 @@ mod big_tests {
|
||||||
let arr = do vec::from_fn(n) |_i| {
|
let arr = do vec::from_fn(n) |_i| {
|
||||||
rng.gen_float()
|
rng.gen_float()
|
||||||
};
|
};
|
||||||
let mut arr = move arr;
|
let mut arr = arr;
|
||||||
|
|
||||||
tim_sort(arr); // *sort
|
tim_sort(arr); // *sort
|
||||||
isSorted(arr);
|
isSorted(arr);
|
||||||
|
@ -1089,7 +1089,7 @@ mod big_tests {
|
||||||
let mut arr = if n > 4 {
|
let mut arr = if n > 4 {
|
||||||
let part = vec::view(arr, 0, 4);
|
let part = vec::view(arr, 0, 4);
|
||||||
multiplyVec(part, n)
|
multiplyVec(part, n)
|
||||||
} else { move arr };
|
} else { arr };
|
||||||
tim_sort(arr); // ~sort
|
tim_sort(arr); // ~sort
|
||||||
isSorted(arr);
|
isSorted(arr);
|
||||||
|
|
||||||
|
@ -1120,7 +1120,7 @@ mod big_tests {
|
||||||
let arr = do vec::from_fn(n) |_i| {
|
let arr = do vec::from_fn(n) |_i| {
|
||||||
@rng.gen_float()
|
@rng.gen_float()
|
||||||
};
|
};
|
||||||
let mut arr = move arr;
|
let mut arr = arr;
|
||||||
|
|
||||||
tim_sort(arr); // *sort
|
tim_sort(arr); // *sort
|
||||||
isSorted(arr);
|
isSorted(arr);
|
||||||
|
@ -1161,7 +1161,7 @@ mod big_tests {
|
||||||
let mut arr = if n > 4 {
|
let mut arr = if n > 4 {
|
||||||
let part = vec::view(arr, 0, 4);
|
let part = vec::view(arr, 0, 4);
|
||||||
multiplyVec(part, n)
|
multiplyVec(part, n)
|
||||||
} else { move arr };
|
} else { arr };
|
||||||
tim_sort(arr); // ~sort
|
tim_sort(arr); // ~sort
|
||||||
isSorted(arr);
|
isSorted(arr);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct Waitqueue { head: pipes::Port<SignalEnd>,
|
||||||
|
|
||||||
fn new_waitqueue() -> Waitqueue {
|
fn new_waitqueue() -> Waitqueue {
|
||||||
let (block_head, block_tail) = pipes::stream();
|
let (block_head, block_tail) = pipes::stream();
|
||||||
Waitqueue { head: move block_head, tail: move block_tail }
|
Waitqueue { head: block_head, tail: block_tail }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signals one live task from the queue.
|
// Signals one live task from the queue.
|
||||||
|
@ -86,7 +86,7 @@ enum Sem<Q> = Exclusive<SemInner<Q>>;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn new_sem<Q: Owned>(count: int, q: Q) -> Sem<Q> {
|
fn new_sem<Q: Owned>(count: int, q: Q) -> Sem<Q> {
|
||||||
Sem(exclusive(SemInner {
|
Sem(exclusive(SemInner {
|
||||||
mut count: count, waiters: new_waitqueue(), blocked: move q }))
|
mut count: count, waiters: new_waitqueue(), blocked: q }))
|
||||||
}
|
}
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn new_sem_and_signal(count: int, num_condvars: uint)
|
fn new_sem_and_signal(count: int, num_condvars: uint)
|
||||||
|
@ -109,9 +109,9 @@ impl<Q: Owned> &Sem<Q> {
|
||||||
// Create waiter nobe.
|
// Create waiter nobe.
|
||||||
let (WaitEnd, SignalEnd) = pipes::oneshot();
|
let (WaitEnd, SignalEnd) = pipes::oneshot();
|
||||||
// Tell outer scope we need to block.
|
// Tell outer scope we need to block.
|
||||||
waiter_nobe = Some(move WaitEnd);
|
waiter_nobe = Some(WaitEnd);
|
||||||
// Enqueue ourself.
|
// Enqueue ourself.
|
||||||
state.waiters.tail.send(move SignalEnd);
|
state.waiters.tail.send(SignalEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ impl<Q: Owned> &Sem<Q> {
|
||||||
/* for 1000.times { task::yield(); } */
|
/* for 1000.times { task::yield(); } */
|
||||||
// Need to wait outside the exclusive.
|
// Need to wait outside the exclusive.
|
||||||
if waiter_nobe.is_some() {
|
if waiter_nobe.is_some() {
|
||||||
let _ = pipes::recv_one(option::unwrap(move waiter_nobe));
|
let _ = pipes::recv_one(option::unwrap(waiter_nobe));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn release() {
|
fn release() {
|
||||||
|
@ -215,8 +215,8 @@ impl &Condvar {
|
||||||
fn wait_on(condvar_id: uint) {
|
fn wait_on(condvar_id: uint) {
|
||||||
// Create waiter nobe.
|
// Create waiter nobe.
|
||||||
let (WaitEnd, SignalEnd) = pipes::oneshot();
|
let (WaitEnd, SignalEnd) = pipes::oneshot();
|
||||||
let mut WaitEnd = Some(move WaitEnd);
|
let mut WaitEnd = Some(WaitEnd);
|
||||||
let mut SignalEnd = Some(move SignalEnd);
|
let mut SignalEnd = Some(SignalEnd);
|
||||||
let mut reacquire = None;
|
let mut reacquire = None;
|
||||||
let mut out_of_bounds = None;
|
let mut out_of_bounds = None;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -231,7 +231,7 @@ impl &Condvar {
|
||||||
}
|
}
|
||||||
// Enqueue ourself to be woken up by a signaller.
|
// Enqueue ourself to be woken up by a signaller.
|
||||||
let SignalEnd = option::swap_unwrap(&mut SignalEnd);
|
let SignalEnd = option::swap_unwrap(&mut SignalEnd);
|
||||||
state.blocked[condvar_id].tail.send(move SignalEnd);
|
state.blocked[condvar_id].tail.send(SignalEnd);
|
||||||
} else {
|
} else {
|
||||||
out_of_bounds = Some(vec::len(state.blocked));
|
out_of_bounds = Some(vec::len(state.blocked));
|
||||||
}
|
}
|
||||||
|
@ -737,7 +737,7 @@ mod tests {
|
||||||
pub fn test_sem_as_mutex() {
|
pub fn test_sem_as_mutex() {
|
||||||
let s = ~semaphore(1);
|
let s = ~semaphore(1);
|
||||||
let s2 = ~s.clone();
|
let s2 = ~s.clone();
|
||||||
do task::spawn |move s2| {
|
do task::spawn || {
|
||||||
do s2.access {
|
do s2.access {
|
||||||
for 5.times { task::yield(); }
|
for 5.times { task::yield(); }
|
||||||
}
|
}
|
||||||
|
@ -752,7 +752,7 @@ mod tests {
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
let s = ~semaphore(0);
|
let s = ~semaphore(0);
|
||||||
let s2 = ~s.clone();
|
let s2 = ~s.clone();
|
||||||
do task::spawn |move s2, move c| {
|
do task::spawn || {
|
||||||
s2.acquire();
|
s2.acquire();
|
||||||
c.send(());
|
c.send(());
|
||||||
}
|
}
|
||||||
|
@ -764,7 +764,7 @@ mod tests {
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
let s = ~semaphore(0);
|
let s = ~semaphore(0);
|
||||||
let s2 = ~s.clone();
|
let s2 = ~s.clone();
|
||||||
do task::spawn |move s2, move p| {
|
do task::spawn || {
|
||||||
for 5.times { task::yield(); }
|
for 5.times { task::yield(); }
|
||||||
s2.release();
|
s2.release();
|
||||||
let _ = p.recv();
|
let _ = p.recv();
|
||||||
|
@ -780,7 +780,7 @@ mod tests {
|
||||||
let s2 = ~s.clone();
|
let s2 = ~s.clone();
|
||||||
let (p1,c1) = pipes::stream();
|
let (p1,c1) = pipes::stream();
|
||||||
let (p2,c2) = pipes::stream();
|
let (p2,c2) = pipes::stream();
|
||||||
do task::spawn |move s2, move c1, move p2| {
|
do task::spawn || {
|
||||||
do s2.access {
|
do s2.access {
|
||||||
let _ = p2.recv();
|
let _ = p2.recv();
|
||||||
c1.send(());
|
c1.send(());
|
||||||
|
@ -799,10 +799,10 @@ mod tests {
|
||||||
let s = ~semaphore(1);
|
let s = ~semaphore(1);
|
||||||
let s2 = ~s.clone();
|
let s2 = ~s.clone();
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
let child_data = ~mut Some((move s2, move c));
|
let child_data = ~mut Some((s2, c));
|
||||||
do s.access {
|
do s.access {
|
||||||
let (s2,c) = option::swap_unwrap(child_data);
|
let (s2,c) = option::swap_unwrap(child_data);
|
||||||
do task::spawn |move c, move s2| {
|
do task::spawn || {
|
||||||
c.send(());
|
c.send(());
|
||||||
do s2.access { }
|
do s2.access { }
|
||||||
c.send(());
|
c.send(());
|
||||||
|
@ -825,7 +825,7 @@ mod tests {
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
let mut sharedstate = ~0;
|
let mut sharedstate = ~0;
|
||||||
let ptr = ptr::addr_of(&(*sharedstate));
|
let ptr = ptr::addr_of(&(*sharedstate));
|
||||||
do task::spawn |move m2, move c| {
|
do task::spawn || {
|
||||||
let sharedstate: &mut int =
|
let sharedstate: &mut int =
|
||||||
unsafe { cast::reinterpret_cast(&ptr) };
|
unsafe { cast::reinterpret_cast(&ptr) };
|
||||||
access_shared(sharedstate, m2, 10);
|
access_shared(sharedstate, m2, 10);
|
||||||
|
@ -854,7 +854,7 @@ mod tests {
|
||||||
// Child wakes up parent
|
// Child wakes up parent
|
||||||
do m.lock_cond |cond| {
|
do m.lock_cond |cond| {
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
do task::spawn |move m2| {
|
do task::spawn || {
|
||||||
do m2.lock_cond |cond| {
|
do m2.lock_cond |cond| {
|
||||||
let woken = cond.signal();
|
let woken = cond.signal();
|
||||||
assert woken;
|
assert woken;
|
||||||
|
@ -865,7 +865,7 @@ mod tests {
|
||||||
// Parent wakes up child
|
// Parent wakes up child
|
||||||
let (port,chan) = pipes::stream();
|
let (port,chan) = pipes::stream();
|
||||||
let m3 = ~m.clone();
|
let m3 = ~m.clone();
|
||||||
do task::spawn |move chan, move m3| {
|
do task::spawn || {
|
||||||
do m3.lock_cond |cond| {
|
do m3.lock_cond |cond| {
|
||||||
chan.send(());
|
chan.send(());
|
||||||
cond.wait();
|
cond.wait();
|
||||||
|
@ -887,8 +887,8 @@ mod tests {
|
||||||
for num_waiters.times {
|
for num_waiters.times {
|
||||||
let mi = ~m.clone();
|
let mi = ~m.clone();
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
ports.push(move port);
|
ports.push(port);
|
||||||
do task::spawn |move chan, move mi| {
|
do task::spawn || {
|
||||||
do mi.lock_cond |cond| {
|
do mi.lock_cond |cond| {
|
||||||
chan.send(());
|
chan.send(());
|
||||||
cond.wait();
|
cond.wait();
|
||||||
|
@ -918,7 +918,7 @@ mod tests {
|
||||||
pub fn test_mutex_cond_no_waiter() {
|
pub fn test_mutex_cond_no_waiter() {
|
||||||
let m = ~Mutex();
|
let m = ~Mutex();
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
do task::try |move m| {
|
do task::try || {
|
||||||
do m.lock_cond |_x| { }
|
do m.lock_cond |_x| { }
|
||||||
};
|
};
|
||||||
do m2.lock_cond |cond| {
|
do m2.lock_cond |cond| {
|
||||||
|
@ -931,7 +931,7 @@ mod tests {
|
||||||
let m = ~Mutex();
|
let m = ~Mutex();
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
|
|
||||||
let result: result::Result<(),()> = do task::try |move m2| {
|
let result: result::Result<(),()> = do task::try || {
|
||||||
do m2.lock {
|
do m2.lock {
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
@ -947,9 +947,9 @@ mod tests {
|
||||||
let m = ~Mutex();
|
let m = ~Mutex();
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
|
|
||||||
let result: result::Result<(),()> = do task::try |move m2| {
|
let result: result::Result<(),()> = do task::try || {
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
do task::spawn |move p| { // linked
|
do task::spawn || { // linked
|
||||||
let _ = p.recv(); // wait for sibling to get in the mutex
|
let _ = p.recv(); // wait for sibling to get in the mutex
|
||||||
task::yield();
|
task::yield();
|
||||||
fail!();
|
fail!();
|
||||||
|
@ -972,19 +972,19 @@ mod tests {
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
|
|
||||||
let result: result::Result<(),()> = do task::try |move c, move m2| {
|
let result: result::Result<(),()> = do task::try || {
|
||||||
let mut sibling_convos = ~[];
|
let mut sibling_convos = ~[];
|
||||||
for 2.times {
|
for 2.times {
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
let c = ~mut Some(move c);
|
let c = ~mut Some(c);
|
||||||
sibling_convos.push(move p);
|
sibling_convos.push(p);
|
||||||
let mi = ~m2.clone();
|
let mi = ~m2.clone();
|
||||||
// spawn sibling task
|
// spawn sibling task
|
||||||
do task::spawn |move mi, move c| { // linked
|
do task::spawn || { // linked
|
||||||
do mi.lock_cond |cond| {
|
do mi.lock_cond |cond| {
|
||||||
let c = option::swap_unwrap(c);
|
let c = option::swap_unwrap(c);
|
||||||
c.send(()); // tell sibling to go ahead
|
c.send(()); // tell sibling to go ahead
|
||||||
let _z = SendOnFailure(move c);
|
let _z = SendOnFailure(c);
|
||||||
cond.wait(); // block forever
|
cond.wait(); // block forever
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -993,7 +993,7 @@ mod tests {
|
||||||
let _ = p.recv(); // wait for sibling to get in the mutex
|
let _ = p.recv(); // wait for sibling to get in the mutex
|
||||||
}
|
}
|
||||||
do m2.lock { }
|
do m2.lock { }
|
||||||
c.send(move sibling_convos); // let parent wait on all children
|
c.send(sibling_convos); // let parent wait on all children
|
||||||
fail!();
|
fail!();
|
||||||
};
|
};
|
||||||
assert result.is_err();
|
assert result.is_err();
|
||||||
|
@ -1015,7 +1015,7 @@ mod tests {
|
||||||
|
|
||||||
fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure {
|
fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure {
|
||||||
SendOnFailure {
|
SendOnFailure {
|
||||||
c: move c
|
c: c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1025,7 +1025,7 @@ mod tests {
|
||||||
let m = ~Mutex();
|
let m = ~Mutex();
|
||||||
do m.lock_cond |cond| {
|
do m.lock_cond |cond| {
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
do task::spawn |move m2| {
|
do task::spawn || {
|
||||||
do m2.lock_cond |cond| {
|
do m2.lock_cond |cond| {
|
||||||
cond.signal_on(0);
|
cond.signal_on(0);
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1039,7 @@ mod tests {
|
||||||
let m = ~mutex_with_condvars(2);
|
let m = ~mutex_with_condvars(2);
|
||||||
let m2 = ~m.clone();
|
let m2 = ~m.clone();
|
||||||
let (p,c) = pipes::stream();
|
let (p,c) = pipes::stream();
|
||||||
do task::spawn |move m2, move c| {
|
do task::spawn || {
|
||||||
do m2.lock_cond |cond| {
|
do m2.lock_cond |cond| {
|
||||||
c.send(());
|
c.send(());
|
||||||
cond.wait_on(1);
|
cond.wait_on(1);
|
||||||
|
@ -1088,7 +1088,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
DowngradeRead =>
|
DowngradeRead =>
|
||||||
do x.write_downgrade |mode| {
|
do x.write_downgrade |mode| {
|
||||||
let mode = x.downgrade(move mode);
|
let mode = x.downgrade(mode);
|
||||||
(&mode).read(blk);
|
(&mode).read(blk);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1103,7 +1103,7 @@ mod tests {
|
||||||
let x2 = ~x.clone();
|
let x2 = ~x.clone();
|
||||||
let mut sharedstate = ~0;
|
let mut sharedstate = ~0;
|
||||||
let ptr = ptr::addr_of(&(*sharedstate));
|
let ptr = ptr::addr_of(&(*sharedstate));
|
||||||
do task::spawn |move c, move x2| {
|
do task::spawn || {
|
||||||
let sharedstate: &mut int =
|
let sharedstate: &mut int =
|
||||||
unsafe { cast::reinterpret_cast(&ptr) };
|
unsafe { cast::reinterpret_cast(&ptr) };
|
||||||
access_shared(sharedstate, x2, mode1, 10);
|
access_shared(sharedstate, x2, mode1, 10);
|
||||||
|
@ -1148,7 +1148,7 @@ mod tests {
|
||||||
let x2 = ~x.clone();
|
let x2 = ~x.clone();
|
||||||
let (p1,c1) = pipes::stream();
|
let (p1,c1) = pipes::stream();
|
||||||
let (p2,c2) = pipes::stream();
|
let (p2,c2) = pipes::stream();
|
||||||
do task::spawn |move c1, move x2, move p2| {
|
do task::spawn || {
|
||||||
if !make_mode2_go_first {
|
if !make_mode2_go_first {
|
||||||
let _ = p2.recv(); // parent sends to us once it locks, or ...
|
let _ = p2.recv(); // parent sends to us once it locks, or ...
|
||||||
}
|
}
|
||||||
|
@ -1185,10 +1185,10 @@ mod tests {
|
||||||
// Tests that downgrade can unlock the lock in both modes
|
// Tests that downgrade can unlock the lock in both modes
|
||||||
let x = ~RWlock();
|
let x = ~RWlock();
|
||||||
do lock_rwlock_in_mode(x, Downgrade) { }
|
do lock_rwlock_in_mode(x, Downgrade) { }
|
||||||
test_rwlock_handshake(move x, Read, Read, false);
|
test_rwlock_handshake(x, Read, Read, false);
|
||||||
let y = ~RWlock();
|
let y = ~RWlock();
|
||||||
do lock_rwlock_in_mode(y, DowngradeRead) { }
|
do lock_rwlock_in_mode(y, DowngradeRead) { }
|
||||||
test_rwlock_exclusion(move y, Write, Write);
|
test_rwlock_exclusion(y, Write, Write);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_rwlock_read_recursive() {
|
pub fn test_rwlock_read_recursive() {
|
||||||
|
@ -1203,7 +1203,7 @@ mod tests {
|
||||||
// Child wakes up parent
|
// Child wakes up parent
|
||||||
do x.write_cond |cond| {
|
do x.write_cond |cond| {
|
||||||
let x2 = ~x.clone();
|
let x2 = ~x.clone();
|
||||||
do task::spawn |move x2| {
|
do task::spawn || {
|
||||||
do x2.write_cond |cond| {
|
do x2.write_cond |cond| {
|
||||||
let woken = cond.signal();
|
let woken = cond.signal();
|
||||||
assert woken;
|
assert woken;
|
||||||
|
@ -1214,7 +1214,7 @@ mod tests {
|
||||||
// Parent wakes up child
|
// Parent wakes up child
|
||||||
let (port,chan) = pipes::stream();
|
let (port,chan) = pipes::stream();
|
||||||
let x3 = ~x.clone();
|
let x3 = ~x.clone();
|
||||||
do task::spawn |move x3, move chan| {
|
do task::spawn || {
|
||||||
do x3.write_cond |cond| {
|
do x3.write_cond |cond| {
|
||||||
chan.send(());
|
chan.send(());
|
||||||
cond.wait();
|
cond.wait();
|
||||||
|
@ -1250,8 +1250,8 @@ mod tests {
|
||||||
for num_waiters.times {
|
for num_waiters.times {
|
||||||
let xi = ~x.clone();
|
let xi = ~x.clone();
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
ports.push(move port);
|
ports.push(port);
|
||||||
do task::spawn |move chan, move xi| {
|
do task::spawn || {
|
||||||
do lock_cond(xi, dg1) |cond| {
|
do lock_cond(xi, dg1) |cond| {
|
||||||
chan.send(());
|
chan.send(());
|
||||||
cond.wait();
|
cond.wait();
|
||||||
|
@ -1286,7 +1286,7 @@ mod tests {
|
||||||
let x = ~RWlock();
|
let x = ~RWlock();
|
||||||
let x2 = ~x.clone();
|
let x2 = ~x.clone();
|
||||||
|
|
||||||
let result: result::Result<(),()> = do task::try |move x2| {
|
let result: result::Result<(),()> = do task::try || {
|
||||||
do lock_rwlock_in_mode(x2, mode1) {
|
do lock_rwlock_in_mode(x2, mode1) {
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
@ -1332,7 +1332,7 @@ mod tests {
|
||||||
let x = ~RWlock();
|
let x = ~RWlock();
|
||||||
let y = ~RWlock();
|
let y = ~RWlock();
|
||||||
do x.write_downgrade |xwrite| {
|
do x.write_downgrade |xwrite| {
|
||||||
let mut xopt = Some(move xwrite);
|
let mut xopt = Some(xwrite);
|
||||||
do y.write_downgrade |_ywrite| {
|
do y.write_downgrade |_ywrite| {
|
||||||
y.downgrade(option::swap_unwrap(&mut xopt));
|
y.downgrade(option::swap_unwrap(&mut xopt));
|
||||||
error!("oops, y.downgrade(x) should have failed!");
|
error!("oops, y.downgrade(x) should have failed!");
|
||||||
|
|
|
@ -50,11 +50,11 @@ pub impl<T> TaskPool<T> {
|
||||||
let (port, chan) = pipes::stream::<Msg<T>>();
|
let (port, chan) = pipes::stream::<Msg<T>>();
|
||||||
let init_fn = init_fn_factory();
|
let init_fn = init_fn_factory();
|
||||||
|
|
||||||
let task_body: ~fn() = |move port, move init_fn| {
|
let task_body: ~fn() = || {
|
||||||
let local_data = init_fn(i);
|
let local_data = init_fn(i);
|
||||||
loop {
|
loop {
|
||||||
match port.recv() {
|
match port.recv() {
|
||||||
Execute(move f) => f(&local_data),
|
Execute(f) => f(&local_data),
|
||||||
Quit => break
|
Quit => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,23 +64,23 @@ pub impl<T> TaskPool<T> {
|
||||||
match opt_sched_mode {
|
match opt_sched_mode {
|
||||||
None => {
|
None => {
|
||||||
// Run on this scheduler.
|
// Run on this scheduler.
|
||||||
task::spawn(move task_body);
|
task::spawn(task_body);
|
||||||
}
|
}
|
||||||
Some(sched_mode) => {
|
Some(sched_mode) => {
|
||||||
task::task().sched_mode(sched_mode).spawn(move task_body);
|
task::task().sched_mode(sched_mode).spawn(task_body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move chan
|
chan
|
||||||
};
|
};
|
||||||
|
|
||||||
return TaskPool { channels: move channels, next_index: 0 };
|
return TaskPool { channels: channels, next_index: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes the function `f` on a task in the pool. The function
|
/// Executes the function `f` on a task in the pool. The function
|
||||||
/// receives a reference to the local data returned by the `init_fn`.
|
/// receives a reference to the local data returned by the `init_fn`.
|
||||||
fn execute(&self, f: ~fn(&T)) {
|
fn execute(&self, f: ~fn(&T)) {
|
||||||
self.channels[self.next_index].send(Execute(move f));
|
self.channels[self.next_index].send(Execute(f));
|
||||||
self.next_index += 1;
|
self.next_index += 1;
|
||||||
if self.next_index == self.channels.len() { self.next_index = 0; }
|
if self.next_index == self.channels.len() { self.next_index = 0; }
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ pub impl<T> TaskPool<T> {
|
||||||
fn test_task_pool() {
|
fn test_task_pool() {
|
||||||
let f: ~fn() -> ~fn(uint) -> uint = || {
|
let f: ~fn() -> ~fn(uint) -> uint = || {
|
||||||
let g: ~fn(uint) -> uint = |i| i;
|
let g: ~fn(uint) -> uint = |i| i;
|
||||||
move g
|
g
|
||||||
};
|
};
|
||||||
let pool = TaskPool::new(4, Some(SingleThreaded), move f);
|
let pool = TaskPool::new(4, Some(SingleThreaded), f);
|
||||||
for 8.times {
|
for 8.times {
|
||||||
pool.execute(|i| io::println(fmt!("Hello from thread %u!", *i)));
|
pool.execute(|i| io::println(fmt!("Hello from thread %u!", *i)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,8 @@ pub struct TestDescAndFn {
|
||||||
pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
|
pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
|
||||||
let opts =
|
let opts =
|
||||||
match parse_opts(args) {
|
match parse_opts(args) {
|
||||||
either::Left(move o) => o,
|
either::Left(o) => o,
|
||||||
either::Right(move m) => fail!(m)
|
either::Right(m) => fail!(m)
|
||||||
};
|
};
|
||||||
if !run_tests_console(&opts, tests) { fail!(~"Some tests failed"); }
|
if !run_tests_console(&opts, tests) { fail!(~"Some tests failed"); }
|
||||||
}
|
}
|
||||||
|
@ -173,8 +173,8 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
|
||||||
getopts::optopt(~"logfile")];
|
getopts::optopt(~"logfile")];
|
||||||
let matches =
|
let matches =
|
||||||
match getopts::getopts(args_, opts) {
|
match getopts::getopts(args_, opts) {
|
||||||
Ok(move m) => m,
|
Ok(m) => m,
|
||||||
Err(move f) => return either::Right(getopts::fail_str(f))
|
Err(f) => return either::Right(getopts::fail_str(f))
|
||||||
};
|
};
|
||||||
|
|
||||||
let filter =
|
let filter =
|
||||||
|
@ -260,7 +260,7 @@ pub fn run_tests_console(opts: &TestOpts,
|
||||||
st.failed += 1;
|
st.failed += 1;
|
||||||
write_failed(st.out, st.use_color);
|
write_failed(st.out, st.use_color);
|
||||||
st.out.write_line(~"");
|
st.out.write_line(~"");
|
||||||
st.failures.push(move test);
|
st.failures.push(test);
|
||||||
}
|
}
|
||||||
TrIgnored => {
|
TrIgnored => {
|
||||||
st.ignored += 1;
|
st.ignored += 1;
|
||||||
|
@ -410,7 +410,7 @@ fn should_sort_failures_before_printing_them() {
|
||||||
mut failed: 0u,
|
mut failed: 0u,
|
||||||
mut ignored: 0u,
|
mut ignored: 0u,
|
||||||
mut benchmarked: 0u,
|
mut benchmarked: 0u,
|
||||||
mut failures: ~[move test_b, move test_a]
|
mut failures: ~[test_b, test_a]
|
||||||
};
|
};
|
||||||
|
|
||||||
print_failures(st);
|
print_failures(st);
|
||||||
|
@ -486,7 +486,7 @@ fn run_tests(opts: &TestOpts,
|
||||||
callback(TeWait(copy b.desc));
|
callback(TeWait(copy b.desc));
|
||||||
run_test(!opts.run_benchmarks, b, ch.clone());
|
run_test(!opts.run_benchmarks, b, ch.clone());
|
||||||
let (test, result) = p.recv();
|
let (test, result) = p.recv();
|
||||||
callback(TeResult(move test, result));
|
callback(TeResult(test, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ pub fn filter_tests(
|
||||||
|
|
||||||
// Remove tests that don't match the test filter
|
// Remove tests that don't match the test filter
|
||||||
filtered = if opts.filter.is_none() {
|
filtered = if opts.filter.is_none() {
|
||||||
move filtered
|
filtered
|
||||||
} else {
|
} else {
|
||||||
let filter_str =
|
let filter_str =
|
||||||
match opts.filter {
|
match opts.filter {
|
||||||
|
@ -534,7 +534,7 @@ pub fn filter_tests(
|
||||||
|
|
||||||
// Maybe pull out the ignored test and unignore them
|
// Maybe pull out the ignored test and unignore them
|
||||||
filtered = if !opts.run_ignored {
|
filtered = if !opts.run_ignored {
|
||||||
move filtered
|
filtered
|
||||||
} else {
|
} else {
|
||||||
fn filter(test: TestDescAndFn) -> Option<TestDescAndFn> {
|
fn filter(test: TestDescAndFn) -> Option<TestDescAndFn> {
|
||||||
if test.desc.ignore {
|
if test.desc.ignore {
|
||||||
|
@ -556,7 +556,7 @@ pub fn filter_tests(
|
||||||
}
|
}
|
||||||
sort::quick_sort(filtered, lteq);
|
sort::quick_sort(filtered, lteq);
|
||||||
|
|
||||||
move filtered
|
filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestFuture {
|
struct TestFuture {
|
||||||
|
@ -582,9 +582,9 @@ pub fn run_test(force_ignore: bool,
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
let mut result_future = None; // task::future_result(builder);
|
let mut result_future = None; // task::future_result(builder);
|
||||||
task::task().unlinked().future_result(|+r| {
|
task::task().unlinked().future_result(|+r| {
|
||||||
result_future = Some(move r);
|
result_future = Some(r);
|
||||||
}).spawn(testfn_cell.take());
|
}).spawn(testfn_cell.take());
|
||||||
let task_result = option::unwrap(move result_future).recv();
|
let task_result = option::unwrap(result_future).recv();
|
||||||
let test_result = calc_result(&desc,
|
let test_result = calc_result(&desc,
|
||||||
task_result == task::Success);
|
task_result == task::Success);
|
||||||
monitor_ch.send((desc, test_result));
|
monitor_ch.send((desc, test_result));
|
||||||
|
@ -965,9 +965,9 @@ mod tests {
|
||||||
},
|
},
|
||||||
testfn: DynTestFn(copy testfn),
|
testfn: DynTestFn(copy testfn),
|
||||||
};
|
};
|
||||||
tests.push(move test);
|
tests.push(test);
|
||||||
}
|
}
|
||||||
move tests
|
tests
|
||||||
};
|
};
|
||||||
let filtered = filter_tests(&opts, tests);
|
let filtered = filter_tests(&opts, tests);
|
||||||
|
|
||||||
|
@ -980,7 +980,7 @@ mod tests {
|
||||||
~"test::parse_ignored_flag",
|
~"test::parse_ignored_flag",
|
||||||
~"test::sort_tests"];
|
~"test::sort_tests"];
|
||||||
|
|
||||||
let pairs = vec::zip(expected, move filtered);
|
let pairs = vec::zip(expected, filtered);
|
||||||
|
|
||||||
for vec::each(pairs) |p| {
|
for vec::each(pairs) |p| {
|
||||||
match *p {
|
match *p {
|
||||||
|
|
|
@ -170,7 +170,7 @@ pub fn at_utc(clock: Timespec) -> Tm {
|
||||||
let mut Timespec { sec, nsec } = clock;
|
let mut Timespec { sec, nsec } = clock;
|
||||||
let mut tm = empty_tm();
|
let mut tm = empty_tm();
|
||||||
rustrt::rust_gmtime(sec, nsec, tm);
|
rustrt::rust_gmtime(sec, nsec, tm);
|
||||||
move tm
|
tm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ pub fn at(clock: Timespec) -> Tm {
|
||||||
let mut Timespec { sec, nsec } = clock;
|
let mut Timespec { sec, nsec } = clock;
|
||||||
let mut tm = empty_tm();
|
let mut tm = empty_tm();
|
||||||
rustrt::rust_localtime(sec, nsec, tm);
|
rustrt::rust_localtime(sec, nsec, tm);
|
||||||
move tm
|
tm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ pub pure fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
||||||
pub pure fn strftime(format: &str, tm: &Tm) -> ~str {
|
pub pure fn strftime(format: &str, tm: &Tm) -> ~str {
|
||||||
// unsafe only because do_strftime is annoying to make pure
|
// unsafe only because do_strftime is annoying to make pure
|
||||||
// (it does IO with a str_reader)
|
// (it does IO with a str_reader)
|
||||||
move unsafe { do_strftime(format, tm) }
|
unsafe { do_strftime(format, tm) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tm {
|
impl Tm {
|
||||||
|
@ -240,7 +240,7 @@ impl Tm {
|
||||||
|
|
||||||
/// Formats the time according to the format string.
|
/// Formats the time according to the format string.
|
||||||
pure fn strftime(&self, format: &str) -> ~str {
|
pure fn strftime(&self, format: &str) -> ~str {
|
||||||
move strftime(format, self)
|
strftime(format, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -689,7 +689,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
||||||
'%' => {
|
'%' => {
|
||||||
match parse_type(s, pos, rdr.read_char(), &mut tm) {
|
match parse_type(s, pos, rdr.read_char(), &mut tm) {
|
||||||
Ok(next) => pos = next,
|
Ok(next) => pos = next,
|
||||||
Err(move e) => { result = Err(move e); break; }
|
Err(e) => { result = Err(e); break; }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
c => {
|
c => {
|
||||||
|
@ -714,7 +714,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
||||||
tm_zone: copy tm.tm_zone,
|
tm_zone: copy tm.tm_zone,
|
||||||
tm_nsec: tm.tm_nsec,
|
tm_nsec: tm.tm_nsec,
|
||||||
})
|
})
|
||||||
} else { move result }
|
} else { result }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +882,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn get_monitor_task_gl() -> IoTask {
|
||||||
|
|
||||||
fn spawn_loop() -> IoTask {
|
fn spawn_loop() -> IoTask {
|
||||||
let builder = do task().add_wrapper |task_body| {
|
let builder = do task().add_wrapper |task_body| {
|
||||||
fn~(move task_body) {
|
fn~() {
|
||||||
// The I/O loop task also needs to be weak so it doesn't keep
|
// The I/O loop task also needs to be weak so it doesn't keep
|
||||||
// the runtime alive
|
// the runtime alive
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -116,7 +116,7 @@ fn spawn_loop() -> IoTask {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let builder = builder.unlinked();
|
let builder = builder.unlinked();
|
||||||
spawn_iotask(move builder)
|
spawn_iotask(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub fn spawn_iotask(task: task::TaskBuilder) -> IoTask {
|
||||||
*/
|
*/
|
||||||
pub unsafe fn interact(iotask: &IoTask,
|
pub unsafe fn interact(iotask: &IoTask,
|
||||||
cb: fn~(*c_void)) {
|
cb: fn~(*c_void)) {
|
||||||
send_msg(iotask, Interaction(move cb));
|
send_msg(iotask, Interaction(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,7 +150,7 @@ struct IoTaskLoopData {
|
||||||
|
|
||||||
fn send_msg(iotask: &IoTask,
|
fn send_msg(iotask: &IoTask,
|
||||||
msg: IoTaskMsg) {
|
msg: IoTaskMsg) {
|
||||||
iotask.op_chan.send(move msg);
|
iotask.op_chan.send(msg);
|
||||||
unsafe {
|
unsafe {
|
||||||
ll::async_send(iotask.async_handle);
|
ll::async_send(iotask.async_handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1252,7 +1252,6 @@ pub mod test {
|
||||||
get_data_for_uv_handle(stream as *libc::c_void)
|
get_data_for_uv_handle(stream as *libc::c_void)
|
||||||
as *request_wrapper;
|
as *request_wrapper;
|
||||||
let buf_base = get_base_from_buf(buf);
|
let buf_base = get_base_from_buf(buf);
|
||||||
let buf_len = get_len_from_buf(buf);
|
|
||||||
let bytes = vec::from_buf(buf_base, nread as uint);
|
let bytes = vec::from_buf(buf_base, nread as uint);
|
||||||
let read_chan = (*client_data).read_chan.clone();
|
let read_chan = (*client_data).read_chan.clone();
|
||||||
let msg_from_server = str::from_bytes(bytes);
|
let msg_from_server = str::from_bytes(bytes);
|
||||||
|
|
|
@ -235,7 +235,7 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||||
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||||
do io::with_str_reader(s) |rdr| {
|
do io::with_str_reader(s) |rdr| {
|
||||||
let j = result::unwrap(json::from_reader(rdr));
|
let j = result::unwrap(json::from_reader(rdr));
|
||||||
Decodable::decode(&json::Decoder(move j))
|
Decodable::decode(&json::Decoder(j))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,20 +323,20 @@ impl TPrep for @Mut<Prep> {
|
||||||
Decodable<json::Decoder>>(&self,
|
Decodable<json::Decoder>>(&self,
|
||||||
blk: ~fn(&Exec) -> T) -> Work<T> {
|
blk: ~fn(&Exec) -> T) -> Work<T> {
|
||||||
|
|
||||||
let mut bo = Some(move blk);
|
let mut bo = Some(blk);
|
||||||
|
|
||||||
do self.borrow_imm |p| {
|
do self.borrow_imm |p| {
|
||||||
let cached = do p.ctxt.db.borrow_mut |db| {
|
let cached = do p.ctxt.db.borrow_mut |db| {
|
||||||
db.prepare(p.fn_name, &p.declared_inputs)
|
db.prepare(p.fn_name, &p.declared_inputs)
|
||||||
};
|
};
|
||||||
|
|
||||||
match move cached {
|
match cached {
|
||||||
Some((ref disc_in, ref disc_out, ref res))
|
Some((ref disc_in, ref disc_out, ref res))
|
||||||
if self.all_fresh("declared input",
|
if self.all_fresh("declared input",
|
||||||
&p.declared_inputs) &&
|
&p.declared_inputs) &&
|
||||||
self.all_fresh("discovered input", disc_in) &&
|
self.all_fresh("discovered input", disc_in) &&
|
||||||
self.all_fresh("discovered output", disc_out) => {
|
self.all_fresh("discovered output", disc_out) => {
|
||||||
Work::new(*self, move Left(json_decode(*res)))
|
Work::new(*self, Left(json_decode(*res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -344,16 +344,16 @@ impl TPrep for @Mut<Prep> {
|
||||||
let mut blk = None;
|
let mut blk = None;
|
||||||
blk <-> bo;
|
blk <-> bo;
|
||||||
let blk = blk.unwrap();
|
let blk = blk.unwrap();
|
||||||
let chan = ~mut Some(move chan);
|
let chan = ~mut Some(chan);
|
||||||
do task::spawn |move blk, move chan| {
|
do task::spawn || {
|
||||||
let exe = Exec{discovered_inputs: LinearMap::new(),
|
let exe = Exec{discovered_inputs: LinearMap::new(),
|
||||||
discovered_outputs: LinearMap::new()};
|
discovered_outputs: LinearMap::new()};
|
||||||
let chan = option::swap_unwrap(&mut *chan);
|
let chan = option::swap_unwrap(&mut *chan);
|
||||||
let v = blk(&exe);
|
let v = blk(&exe);
|
||||||
send_one(move chan, (move exe, move v));
|
send_one(chan, (exe, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
Work::new(*self, move Right(move port))
|
Work::new(*self, Right(port))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ impl<T:Owned
|
||||||
Decodable<json::Decoder>>
|
Decodable<json::Decoder>>
|
||||||
Work<T> {
|
Work<T> {
|
||||||
static fn new(p: @Mut<Prep>, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
|
static fn new(p: @Mut<Prep>, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
|
||||||
move Work { prep: p, res: Some(move e) }
|
Work { prep: p, res: Some(e) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,18 +374,18 @@ fn unwrap<T:Owned
|
||||||
Encodable<json::Encoder>
|
Encodable<json::Encoder>
|
||||||
Decodable<json::Decoder>>(w: Work<T>) -> T {
|
Decodable<json::Decoder>>(w: Work<T>) -> T {
|
||||||
|
|
||||||
let mut ww = move w;
|
let mut ww = w;
|
||||||
let mut s = None;
|
let mut s = None;
|
||||||
|
|
||||||
ww.res <-> s;
|
ww.res <-> s;
|
||||||
|
|
||||||
match move s {
|
match s {
|
||||||
None => fail!(),
|
None => fail!(),
|
||||||
Some(Left(move v)) => move v,
|
Some(Left(v)) => v,
|
||||||
Some(Right(move port)) => {
|
Some(Right(port)) => {
|
||||||
|
|
||||||
let (exe, v) = match recv(move port) {
|
let (exe, v) = match recv(port) {
|
||||||
oneshot::send(move data) => move data
|
oneshot::send(data) => data
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = json_encode(&v);
|
let s = json_encode(&v);
|
||||||
|
@ -399,7 +399,7 @@ fn unwrap<T:Owned
|
||||||
s);
|
s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,9 +425,9 @@ fn test() {
|
||||||
do prep.exec |_exe| {
|
do prep.exec |_exe| {
|
||||||
let out = Path("foo.o");
|
let out = Path("foo.o");
|
||||||
run::run_program("gcc", [~"foo.c", ~"-o", out.to_str()]);
|
run::run_program("gcc", [~"foo.c", ~"-o", out.to_str()]);
|
||||||
move out.to_str()
|
out.to_str()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let s = unwrap(move w);
|
let s = unwrap(w);
|
||||||
io::println(s);
|
io::println(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue