libcore: Get rid of move
.
This commit is contained in:
parent
78f3e0da70
commit
5912b1448c
30 changed files with 358 additions and 362 deletions
|
@ -229,12 +229,12 @@ pub mod raw {
|
||||||
(**repr).unboxed.fill += sys::size_of::<T>();
|
(**repr).unboxed.fill += sys::size_of::<T>();
|
||||||
let p = addr_of(&((**repr).unboxed.data));
|
let p = addr_of(&((**repr).unboxed.data));
|
||||||
let p = ptr::offset(p, fill) as *mut T;
|
let p = ptr::offset(p, fill) as *mut T;
|
||||||
rusti::move_val_init(&mut(*p), move initval);
|
rusti::move_val_init(&mut(*p), initval);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
|
pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
|
||||||
reserve_at_least(&mut *v, v.len() + 1u);
|
reserve_at_least(&mut *v, v.len() + 1u);
|
||||||
push_fast(v, move initval);
|
push_fast(v, initval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
|
||||||
* reinterpret_cast on pointer types.
|
* reinterpret_cast on pointer types.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn forget<T>(thing: T) { rusti::forget(move thing); }
|
pub unsafe fn forget<T>(thing: T) { rusti::forget(thing); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force-increment the reference count on a shared box. If used
|
* Force-increment the reference count on a shared box. If used
|
||||||
|
@ -37,7 +37,7 @@ pub unsafe fn forget<T>(thing: T) { rusti::forget(move thing); }
|
||||||
* and/or reinterpret_cast when such calls would otherwise scramble a box's
|
* and/or reinterpret_cast when such calls would otherwise scramble a box's
|
||||||
* reference count
|
* reference count
|
||||||
*/
|
*/
|
||||||
pub unsafe fn bump_box_refcount<T>(t: @T) { forget(move t); }
|
pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a value of one type into a value of another type.
|
* Transform a value of one type into a value of another type.
|
||||||
|
@ -50,23 +50,23 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(move t); }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
||||||
let newthing: G = reinterpret_cast(&thing);
|
let newthing: G = reinterpret_cast(&thing);
|
||||||
forget(move thing);
|
forget(thing);
|
||||||
move newthing
|
newthing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce an immutable reference to be mutable.
|
/// Coerce an immutable reference to be mutable.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn transmute_mut<T>(ptr: &a/T) -> &a/mut T { transmute(move ptr) }
|
pub unsafe fn transmute_mut<T>(ptr: &a/T) -> &a/mut T { transmute(ptr) }
|
||||||
|
|
||||||
/// Coerce a mutable reference to be immutable.
|
/// Coerce a mutable reference to be immutable.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn transmute_immut<T>(ptr: &a/mut T) -> &a/T {
|
pub unsafe fn transmute_immut<T>(ptr: &a/mut T) -> &a/T {
|
||||||
transmute(move ptr)
|
transmute(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce a borrowed pointer to have an arbitrary associated region.
|
/// Coerce a borrowed pointer to have an arbitrary associated region.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn transmute_region<T>(ptr: &a/T) -> &b/T { transmute(move ptr) }
|
pub unsafe fn transmute_region<T>(ptr: &a/T) -> &b/T { transmute(ptr) }
|
||||||
|
|
||||||
/// Coerce an immutable reference to be mutable.
|
/// Coerce an immutable reference to be mutable.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -83,7 +83,7 @@ pub unsafe fn transmute_immut_unsafe<T>(ptr: *const T) -> *T {
|
||||||
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
|
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn transmute_mut_region<T>(ptr: &a/mut T) -> &b/mut T {
|
pub unsafe fn transmute_mut_region<T>(ptr: &a/mut T) -> &b/mut T {
|
||||||
transmute(move ptr)
|
transmute(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transforms lifetime of the second pointer to match the first.
|
/// Transforms lifetime of the second pointer to match the first.
|
||||||
|
@ -132,9 +132,9 @@ pub mod tests {
|
||||||
use managed::raw::BoxRepr;
|
use managed::raw::BoxRepr;
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = @100u8;
|
let x = @100u8;
|
||||||
let x: *BoxRepr = transmute(move x);
|
let x: *BoxRepr = transmute(x);
|
||||||
assert (*x).data == 100;
|
assert (*x).data == 100;
|
||||||
let _x: @int = transmute(move x);
|
let _x: @int = transmute(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,7 @@ impl<T: Copy> DList<T> {
|
||||||
v[index] = *data;
|
v[index] = *data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,18 +67,18 @@ pub pure fn DVec<A>() -> DVec<A> {
|
||||||
|
|
||||||
/// Creates a new dvec with a single element
|
/// Creates a new dvec with a single element
|
||||||
pub pure fn from_elem<A>(e: A) -> DVec<A> {
|
pub pure fn from_elem<A>(e: A) -> DVec<A> {
|
||||||
DVec {mut data: ~[move e]}
|
DVec {mut data: ~[e]}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new dvec with the contents of a vector
|
/// Creates a new dvec with the contents of a vector
|
||||||
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
|
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
|
||||||
DVec {mut data: move v}
|
DVec {mut data: v}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes the vector and returns its contents
|
/// Consumes the vector and returns its contents
|
||||||
pub pure fn unwrap<A>(d: DVec<A>) -> ~[A] {
|
pub pure fn unwrap<A>(d: DVec<A>) -> ~[A] {
|
||||||
let DVec {data: v} = move d;
|
let DVec {data: v} = d;
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
priv impl<A> DVec<A> {
|
priv impl<A> DVec<A> {
|
||||||
|
@ -99,14 +99,14 @@ priv impl<A> DVec<A> {
|
||||||
data <-> self.data;
|
data <-> self.data;
|
||||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
let data_ptr: *() = cast::reinterpret_cast(&data);
|
||||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
||||||
return f(move data);
|
return f(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn give_back(data: ~[A]) {
|
fn give_back(data: ~[A]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.data = move data;
|
self.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ impl<A> DVec<A> {
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn swap(f: &fn(v: ~[A]) -> ~[A]) {
|
fn swap(f: &fn(v: ~[A]) -> ~[A]) {
|
||||||
self.check_out(|v| self.give_back(f(move v)))
|
self.check_out(|v| self.give_back(f(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,7 +141,7 @@ impl<A> DVec<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn swap_mut(f: &fn(v: ~[mut A]) -> ~[mut A]) {
|
fn swap_mut(f: &fn(v: ~[mut A]) -> ~[mut A]) {
|
||||||
do self.swap |v| {
|
do self.swap |v| {
|
||||||
vec::cast_from_mut(f(vec::cast_to_mut(move v)))
|
vec::cast_from_mut(f(vec::cast_to_mut(v)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,16 +156,16 @@ impl<A> DVec<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn set(w: ~[A]) {
|
fn set(w: ~[A]) {
|
||||||
self.check_not_borrowed();
|
self.check_not_borrowed();
|
||||||
self.data = move w;
|
self.data = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove and return the last element
|
/// Remove and return the last element
|
||||||
fn pop() -> A {
|
fn pop() -> A {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
let result = v.pop();
|
let result = v.pop();
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +176,8 @@ impl<A> DVec<A> {
|
||||||
data <-> self.data;
|
data <-> self.data;
|
||||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
let data_ptr: *() = cast::reinterpret_cast(&data);
|
||||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
||||||
self.data = move ~[move t];
|
self.data = ~[t];
|
||||||
self.data.push_all_move(move data);
|
self.data.push_all_move(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,25 +185,25 @@ impl<A> DVec<A> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn push(t: A) {
|
fn push(t: A) {
|
||||||
self.check_not_borrowed();
|
self.check_not_borrowed();
|
||||||
self.data.push(move t);
|
self.data.push(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove and return the first element
|
/// Remove and return the first element
|
||||||
fn shift() -> A {
|
fn shift() -> A {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
let result = v.shift();
|
let result = v.shift();
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reverse the elements in the list, in place
|
/// Reverse the elements in the list, in place
|
||||||
fn reverse() {
|
fn reverse() {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
vec::reverse(v);
|
vec::reverse(v);
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,18 +211,18 @@ impl<A> DVec<A> {
|
||||||
fn borrow<R>(op: fn(x: &[A]) -> R) -> R {
|
fn borrow<R>(op: fn(x: &[A]) -> R) -> R {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let result = op(v);
|
let result = op(v);
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gives access to the vector as a slice with mutable contents
|
/// Gives access to the vector as a slice with mutable contents
|
||||||
fn borrow_mut<R>(op: fn(x: &[mut A]) -> R) -> R {
|
fn borrow_mut<R>(op: fn(x: &[mut A]) -> R) -> R {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
let result = op(v);
|
let result = op(v);
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ impl<A: Copy> DVec<A> {
|
||||||
/// Appends elements from `from_idx` to `to_idx` (exclusive)
|
/// Appends elements from `from_idx` to `to_idx` (exclusive)
|
||||||
fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) {
|
fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) {
|
||||||
do self.swap |v| {
|
do self.swap |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
let new_len = vec::len(v) + to_idx - from_idx;
|
let new_len = vec::len(v) + to_idx - from_idx;
|
||||||
vec::reserve(&mut v, new_len);
|
vec::reserve(&mut v, new_len);
|
||||||
let mut i = from_idx;
|
let mut i = from_idx;
|
||||||
|
@ -248,7 +248,7 @@ impl<A: Copy> DVec<A> {
|
||||||
v.push(ts[i]);
|
v.push(ts[i]);
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ impl<A: Copy> DVec<A> {
|
||||||
none { v }
|
none { v }
|
||||||
Some(h) {
|
Some(h) {
|
||||||
let len = v.len() + h;
|
let len = v.len() + h;
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
vec::reserve(v, len);
|
vec::reserve(v, len);
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
@ -286,8 +286,8 @@ impl<A: Copy> DVec<A> {
|
||||||
unsafe {
|
unsafe {
|
||||||
do self.check_out |v| {
|
do self.check_out |v| {
|
||||||
let w = copy v;
|
let w = copy v;
|
||||||
self.give_back(move v);
|
self.give_back(v);
|
||||||
move w
|
w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,9 +312,9 @@ impl<A: Copy> DVec<A> {
|
||||||
*/
|
*/
|
||||||
fn grow_set_elt(idx: uint, initval: &A, val: A) {
|
fn grow_set_elt(idx: uint, initval: &A, val: A) {
|
||||||
do self.swap |v| {
|
do self.swap |v| {
|
||||||
let mut v = move v;
|
let mut v = v;
|
||||||
v.grow_set(idx, initval, val);
|
v.grow_set(idx, initval, val);
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ impl<A: Copy> DVec<A> {
|
||||||
for vec::rev_each(v) |e| {
|
for vec::rev_each(v) |e| {
|
||||||
if !f(e) { break; }
|
if !f(e) { break; }
|
||||||
}
|
}
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ impl<A: Copy> DVec<A> {
|
||||||
for vec::rev_eachi(v) |i, e| {
|
for vec::rev_eachi(v) |i, e| {
|
||||||
if !f(i, e) { break; }
|
if !f(i, e) { break; }
|
||||||
}
|
}
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
|
||||||
Right(r) => rights.push(r)
|
Right(r) => rights.push(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (move lefts, move rights);
|
return (lefts, rights);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -131,8 +131,8 @@ pub pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
|
||||||
pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
||||||
//! Retrieves the value in the left branch. Fails if the either is Right.
|
//! Retrieves the value in the left branch. Fails if the either is Right.
|
||||||
|
|
||||||
match move eith {
|
match eith {
|
||||||
Left(move x) => move x,
|
Left(x) => x,
|
||||||
Right(_) => fail!(~"either::unwrap_left Right")
|
Right(_) => fail!(~"either::unwrap_left Right")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,8 @@ pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
|
||||||
pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
||||||
//! Retrieves the value in the right branch. Fails if the either is Left.
|
//! Retrieves the value in the right branch. Fails if the either is Left.
|
||||||
|
|
||||||
match move eith {
|
match eith {
|
||||||
Right(move x) => move x,
|
Right(x) => x,
|
||||||
Left(_) => fail!(~"either::unwrap_right Left")
|
Left(_) => fail!(~"either::unwrap_right Left")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,7 +510,7 @@ pub mod rt {
|
||||||
unsafe { str::unshift_char(&mut s, ' ') };
|
unsafe { str::unshift_char(&mut s, ' ') };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unsafe { pad(cv, move s, PadSigned) };
|
return unsafe { pad(cv, s, PadSigned) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
|
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
|
||||||
let prec = get_int_precision(cv);
|
let prec = get_int_precision(cv);
|
||||||
|
@ -522,7 +522,7 @@ pub mod rt {
|
||||||
TyBits => uint_to_str_prec(u, 2, prec),
|
TyBits => uint_to_str_prec(u, 2, prec),
|
||||||
TyOctal => uint_to_str_prec(u, 8, prec)
|
TyOctal => uint_to_str_prec(u, 8, prec)
|
||||||
};
|
};
|
||||||
return unsafe { pad(cv, move rs, PadUnsigned) };
|
return unsafe { pad(cv, rs, PadUnsigned) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
|
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
|
||||||
let s = if b { ~"true" } else { ~"false" };
|
let s = if b { ~"true" } else { ~"false" };
|
||||||
|
@ -532,7 +532,7 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
|
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
|
||||||
let mut s = str::from_char(c);
|
let mut s = str::from_char(c);
|
||||||
return unsafe { pad(cv, move s, PadNozero) };
|
return unsafe { pad(cv, s, PadNozero) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
|
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
|
||||||
// For strings, precision is the maximum characters
|
// For strings, precision is the maximum characters
|
||||||
|
@ -545,7 +545,7 @@ pub mod rt {
|
||||||
s.to_owned()
|
s.to_owned()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return unsafe { pad(cv, move unpadded, PadNozero) };
|
return unsafe { pad(cv, unpadded, PadNozero) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
|
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
|
||||||
let (to_str, digits) = match cv.precision {
|
let (to_str, digits) = match cv.precision {
|
||||||
|
@ -560,7 +560,7 @@ pub mod rt {
|
||||||
s = ~" " + s;
|
s = ~" " + s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unsafe { pad(cv, move s, PadFloat) };
|
return unsafe { pad(cv, s, PadFloat) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
|
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
|
||||||
let s = sys::log_str(v);
|
let s = sys::log_str(v);
|
||||||
|
@ -589,7 +589,7 @@ pub mod rt {
|
||||||
let diff = prec - len;
|
let diff = prec - len;
|
||||||
let pad = str::from_chars(vec::from_elem(diff, '0'));
|
let pad = str::from_chars(vec::from_elem(diff, '0'));
|
||||||
pad + s
|
pad + s
|
||||||
} else { move s }
|
} else { s }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub pure fn get_int_precision(cv: Conv) -> uint {
|
pub pure fn get_int_precision(cv: Conv) -> uint {
|
||||||
|
@ -603,13 +603,13 @@ pub mod rt {
|
||||||
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
|
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
|
||||||
|
|
||||||
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
|
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
|
||||||
let mut s = move s; // sadtimes
|
let mut s = s; // sadtimes
|
||||||
let uwidth : uint = match cv.width {
|
let uwidth : uint = match cv.width {
|
||||||
CountImplied => return (move s),
|
CountImplied => return (s),
|
||||||
CountIs(width) => { width as uint }
|
CountIs(width) => { width as uint }
|
||||||
};
|
};
|
||||||
let strlen = str::char_len(s);
|
let strlen = str::char_len(s);
|
||||||
if uwidth <= strlen { return (move s); }
|
if uwidth <= strlen { return (s); }
|
||||||
let mut padchar = ' ';
|
let mut padchar = ' ';
|
||||||
let diff = uwidth - strlen;
|
let diff = uwidth - strlen;
|
||||||
if have_flag(cv.flags, flag_left_justify) {
|
if have_flag(cv.flags, flag_left_justify) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
|
||||||
let out = vec::raw::from_buf_raw(res as *u8,
|
let out = vec::raw::from_buf_raw(res as *u8,
|
||||||
outsz as uint);
|
outsz as uint);
|
||||||
libc::free(res);
|
libc::free(res);
|
||||||
move out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] {
|
||||||
let out = vec::raw::from_buf_raw(res as *u8,
|
let out = vec::raw::from_buf_raw(res as *u8,
|
||||||
outsz as uint);
|
outsz as uint);
|
||||||
libc::free(res);
|
libc::free(res);
|
||||||
move out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ fn SipState(key0: u64, key1: u64) -> SipState {
|
||||||
mut ntail : 0u,
|
mut ntail : 0u,
|
||||||
};
|
};
|
||||||
(&state).reset();
|
(&state).reset();
|
||||||
move state
|
state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ impl Streaming for &SipState {
|
||||||
for vec::each(r) |b| {
|
for vec::each(r) |b| {
|
||||||
s += uint::to_str_radix(*b as uint, 16u);
|
s += uint::to_str_radix(*b as uint, 16u);
|
||||||
}
|
}
|
||||||
move s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -447,7 +447,7 @@ pub fn test_siphash() {
|
||||||
for vec::each(*r) |b| {
|
for vec::each(*r) |b| {
|
||||||
s += uint::to_str_radix(*b as uint, 16u);
|
s += uint::to_str_radix(*b as uint, 16u);
|
||||||
}
|
}
|
||||||
move s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
while t < 64 {
|
while t < 64 {
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl<T: Reader> ReaderUtil for T {
|
||||||
let count = self.read(bytes, len);
|
let count = self.read(bytes, len);
|
||||||
|
|
||||||
unsafe { vec::raw::set_len(&mut bytes, count); }
|
unsafe { vec::raw::set_len(&mut bytes, count); }
|
||||||
move bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_line(&self) -> ~str {
|
fn read_line(&self) -> ~str {
|
||||||
|
@ -249,7 +249,7 @@ impl<T: Reader> ReaderUtil for T {
|
||||||
bytes = vec::slice(bytes, offset, bytes.len());
|
bytes = vec::slice(bytes, offset, bytes.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move chars
|
chars
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_char(&self) -> char {
|
fn read_char(&self) -> char {
|
||||||
|
@ -273,7 +273,7 @@ impl<T: Reader> ReaderUtil for T {
|
||||||
fn read_whole_stream(&self) -> ~[u8] {
|
fn read_whole_stream(&self) -> ~[u8] {
|
||||||
let mut bytes: ~[u8] = ~[];
|
let mut bytes: ~[u8] = ~[];
|
||||||
while !self.eof() { bytes.push_all(self.read_bytes(2048u)); }
|
while !self.eof() { bytes.push_all(self.read_bytes(2048u)); }
|
||||||
move bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn each_byte(&self, it: fn(int) -> bool) {
|
fn each_byte(&self, it: fn(int) -> bool) {
|
||||||
|
@ -999,7 +999,7 @@ pub struct BytesWriter {
|
||||||
impl Writer for BytesWriter {
|
impl Writer for BytesWriter {
|
||||||
fn write(&self, v: &[const u8]) {
|
fn write(&self, v: &[const u8]) {
|
||||||
do self.bytes.swap |bytes| {
|
do self.bytes.swap |bytes| {
|
||||||
let mut bytes = move bytes;
|
let mut bytes = bytes;
|
||||||
let v_len = v.len();
|
let v_len = v.len();
|
||||||
let bytes_len = bytes.len();
|
let bytes_len = bytes.len();
|
||||||
|
|
||||||
|
@ -1014,7 +1014,7 @@ impl Writer for BytesWriter {
|
||||||
|
|
||||||
self.pos += v_len;
|
self.pos += v_len;
|
||||||
|
|
||||||
move bytes
|
bytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||||
|
@ -1035,7 +1035,7 @@ pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
|
||||||
let wr = @BytesWriter();
|
let wr = @BytesWriter();
|
||||||
f(wr as Writer);
|
f(wr as Writer);
|
||||||
// FIXME (#3758): This should not be needed.
|
// FIXME (#3758): This should not be needed.
|
||||||
unsafe { wr.bytes.check_out(|bytes| move bytes) }
|
unsafe { wr.bytes.check_out(|bytes| bytes) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
||||||
|
@ -1048,7 +1048,7 @@ pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
||||||
}
|
}
|
||||||
assert str::is_utf8(v);
|
assert str::is_utf8(v);
|
||||||
|
|
||||||
unsafe { move ::cast::transmute(move v) }
|
unsafe { ::cast::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
@ -1126,7 +1126,7 @@ pub mod fsync {
|
||||||
|
|
||||||
pub fn Res<t: Copy>(arg: Arg<t>) -> Res<t>{
|
pub fn Res<t: Copy>(arg: Arg<t>) -> Res<t>{
|
||||||
Res {
|
Res {
|
||||||
arg: move arg
|
arg: arg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl<A> iter::ExtendedIter<A> for IMPL_T<A> {
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
|
pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
|
||||||
iter::foldl(self, move b0, blk)
|
iter::foldl(self, b0, blk)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
|
pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
|
||||||
|
|
|
@ -25,7 +25,7 @@ mod inst {
|
||||||
unsafe {
|
unsafe {
|
||||||
do self.swap |v| {
|
do self.swap |v| {
|
||||||
v.each(f);
|
v.each(f);
|
||||||
move v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,11 +154,11 @@ pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
|
||||||
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
|
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
|
||||||
blk: fn(&B, &A) -> B)
|
blk: fn(&B, &A) -> B)
|
||||||
-> B {
|
-> B {
|
||||||
let mut b = move b0;
|
let mut b = b0;
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
b = blk(&b, a);
|
b = blk(&b, a);
|
||||||
}
|
}
|
||||||
move b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -215,12 +215,12 @@ pub pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
&Some(ref a_) if *a_ < *b => {
|
&Some(ref a_) if *a_ < *b => {
|
||||||
*(move a)
|
*(a)
|
||||||
}
|
}
|
||||||
_ => Some(*b)
|
_ => Some(*b)
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
Some(move val) => val,
|
Some(val) => val,
|
||||||
None => fail!(~"min called on empty iterator")
|
None => fail!(~"min called on empty iterator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,12 +230,12 @@ pub pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
&Some(ref a_) if *a_ > *b => {
|
&Some(ref a_) if *a_ > *b => {
|
||||||
*(move a)
|
*(a)
|
||||||
}
|
}
|
||||||
_ => Some(*b)
|
_ => Some(*b)
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
Some(move val) => val,
|
Some(val) => val,
|
||||||
None => fail!(~"max called on empty iterator")
|
None => fail!(~"max called on empty iterator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,15 +32,15 @@ struct Data<T> {
|
||||||
pub type Mut<T> = Data<T>;
|
pub type Mut<T> = Data<T>;
|
||||||
|
|
||||||
pub fn Mut<T>(t: T) -> Mut<T> {
|
pub fn Mut<T>(t: T) -> Mut<T> {
|
||||||
Data {value: move t, mode: ReadOnly}
|
Data {value: t, mode: ReadOnly}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unwrap<T>(m: Mut<T>) -> T {
|
pub fn unwrap<T>(m: Mut<T>) -> T {
|
||||||
// Borrowck should prevent us from calling unwrap while the value
|
// Borrowck should prevent us from calling unwrap while the value
|
||||||
// is in use, as that would be a move from a borrowed value.
|
// is in use, as that would be a move from a borrowed value.
|
||||||
assert (m.mode as uint) == (ReadOnly as uint);
|
assert (m.mode as uint) == (ReadOnly as uint);
|
||||||
let Data {value: move value, mode: _} = move m;
|
let Data {value: value, mode: _} = m;
|
||||||
move value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Data<T> {
|
impl<T> Data<T> {
|
||||||
|
|
|
@ -33,8 +33,8 @@ match msg {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the contained string, destroying the Option
|
// Remove the contained string, destroying the Option
|
||||||
let unwrapped_msg = match move msg {
|
let unwrapped_msg = match msg {
|
||||||
Some(move m) => m,
|
Some(m) => m,
|
||||||
None => ~"default message"
|
None => ~"default message"
|
||||||
};
|
};
|
||||||
~~~
|
~~~
|
||||||
|
@ -126,8 +126,8 @@ pub pure fn chain<T, U>(opt: Option<T>,
|
||||||
* function that returns an option.
|
* function that returns an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
match move opt {
|
match opt {
|
||||||
Some(move t) => f(move t),
|
Some(t) => f(t),
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,9 +148,9 @@ pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
|
||||||
/*!
|
/*!
|
||||||
* Returns the leftmost Some() value, or None if both are None.
|
* Returns the leftmost Some() value, or None if both are None.
|
||||||
*/
|
*/
|
||||||
match move opta {
|
match opta {
|
||||||
Some(move opta) => Some(move opta),
|
Some(opta) => Some(opta),
|
||||||
_ => move optb
|
_ => optb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,9 +158,9 @@ pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
|
||||||
pub pure fn while_some<T>(x: Option<T>, blk: fn(v: T) -> Option<T>) {
|
pub pure fn while_some<T>(x: Option<T>, blk: fn(v: T) -> Option<T>) {
|
||||||
//! Applies a function zero or more times until the result is none.
|
//! Applies a function zero or more times until the result is none.
|
||||||
|
|
||||||
let mut opt = move x;
|
let mut opt = x;
|
||||||
while opt.is_some() {
|
while opt.is_some() {
|
||||||
opt = blk(unwrap(move opt));
|
opt = blk(unwrap(opt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
|
||||||
f: fn(&r/T) -> U) -> U {
|
f: fn(&r/T) -> U) -> U {
|
||||||
//! Applies a function to the contained value or returns a default
|
//! Applies a function to the contained value or returns a default
|
||||||
|
|
||||||
match *opt { None => move def, Some(ref t) => f(t) }
|
match *opt { None => def, Some(ref t) => f(t) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -224,8 +224,8 @@ pub pure fn unwrap<T>(opt: Option<T>) -> T {
|
||||||
Instead, prefer to use pattern matching and handle the `None`
|
Instead, prefer to use pattern matching and handle the `None`
|
||||||
case explicitly.
|
case explicitly.
|
||||||
*/
|
*/
|
||||||
match move opt {
|
match opt {
|
||||||
Some(move x) => move x,
|
Some(x) => x,
|
||||||
None => fail!(~"option::unwrap none")
|
None => fail!(~"option::unwrap none")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,8 +247,8 @@ pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
||||||
//! As unwrap, but with a specified failure message.
|
//! As unwrap, but with a specified failure message.
|
||||||
match move opt {
|
match opt {
|
||||||
Some(move val) => val,
|
Some(val) => val,
|
||||||
None => fail!(reason.to_owned()),
|
None => fail!(reason.to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ impl<T> Option<T> {
|
||||||
/// Applies a function to the contained value or returns a default
|
/// Applies a function to the contained value or returns a default
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn map_default<U>(&self, def: U, f: fn(&self/T) -> U) -> U {
|
pure fn map_default<U>(&self, def: U, f: fn(&self/T) -> U) -> U {
|
||||||
map_default(self, move def, f)
|
map_default(self, def, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// As `map_default`, but consumes the option and gives `f`
|
/// As `map_default`, but consumes the option and gives `f`
|
||||||
|
@ -402,8 +402,8 @@ impl<T: Copy Zero> Option<T> {
|
||||||
fn test_unwrap_ptr() {
|
fn test_unwrap_ptr() {
|
||||||
let x = ~0;
|
let x = ~0;
|
||||||
let addr_x = ptr::addr_of(&(*x));
|
let addr_x = ptr::addr_of(&(*x));
|
||||||
let opt = Some(move x);
|
let opt = Some(x);
|
||||||
let y = unwrap(move opt);
|
let y = unwrap(opt);
|
||||||
let addr_y = ptr::addr_of(&(*y));
|
let addr_y = ptr::addr_of(&(*y));
|
||||||
assert addr_x == addr_y;
|
assert addr_x == addr_y;
|
||||||
}
|
}
|
||||||
|
@ -412,8 +412,8 @@ fn test_unwrap_ptr() {
|
||||||
fn test_unwrap_str() {
|
fn test_unwrap_str() {
|
||||||
let x = ~"test";
|
let x = ~"test";
|
||||||
let addr_x = str::as_buf(x, |buf, _len| buf);
|
let addr_x = str::as_buf(x, |buf, _len| buf);
|
||||||
let opt = Some(move x);
|
let opt = Some(x);
|
||||||
let y = unwrap(move opt);
|
let y = unwrap(opt);
|
||||||
let addr_y = str::as_buf(y, |buf, _len| buf);
|
let addr_y = str::as_buf(y, |buf, _len| buf);
|
||||||
assert addr_x == addr_y;
|
assert addr_x == addr_y;
|
||||||
}
|
}
|
||||||
|
@ -434,8 +434,8 @@ fn test_unwrap_resource() {
|
||||||
let i = @mut 0;
|
let i = @mut 0;
|
||||||
{
|
{
|
||||||
let x = R(i);
|
let x = R(i);
|
||||||
let opt = Some(move x);
|
let opt = Some(x);
|
||||||
let _y = unwrap(move opt);
|
let _y = unwrap(opt);
|
||||||
}
|
}
|
||||||
assert *i == 1;
|
assert *i == 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ pub fn env() -> ~[(~str,~str)] {
|
||||||
assert vec::len(vs) == 2u;
|
assert vec::len(vs) == 2u;
|
||||||
pairs.push((copy vs[0], copy vs[1]));
|
pairs.push((copy vs[0], copy vs[1]));
|
||||||
}
|
}
|
||||||
move pairs
|
pairs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ pub fn tmpdir() -> Path {
|
||||||
|
|
||||||
fn getenv_nonempty(v: &str) -> Option<Path> {
|
fn getenv_nonempty(v: &str) -> Option<Path> {
|
||||||
match getenv(v) {
|
match getenv(v) {
|
||||||
Some(move x) =>
|
Some(x) =>
|
||||||
if str::is_empty(x) {
|
if str::is_empty(x) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -915,7 +915,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
|
||||||
for uint::range(0, argc as uint) |i| {
|
for uint::range(0, argc as uint) |i| {
|
||||||
vec::push(&mut args, str::raw::from_c_str(*argv.offset(i)));
|
vec::push(&mut args, str::raw::from_c_str(*argv.offset(i)));
|
||||||
}
|
}
|
||||||
move args
|
args
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1137,7 +1137,7 @@ mod tests {
|
||||||
let rng: rand::Rng = rand::Rng();
|
let rng: rand::Rng = rand::Rng();
|
||||||
let n = ~"TEST" + rng.gen_str(10u);
|
let n = ~"TEST" + rng.gen_str(10u);
|
||||||
assert getenv(n).is_none();
|
assert getenv(n).is_none();
|
||||||
move n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1171,7 +1171,7 @@ mod tests {
|
||||||
let n = make_rand_name();
|
let n = make_rand_name();
|
||||||
setenv(n, s);
|
setenv(n, s);
|
||||||
log(debug, copy s);
|
log(debug, copy s);
|
||||||
assert getenv(n) == option::Some(move s);
|
assert getenv(n) == option::Some(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1197,7 +1197,7 @@ mod tests {
|
||||||
// MingW seems to set some funky environment variables like
|
// MingW seems to set some funky environment variables like
|
||||||
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
|
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
|
||||||
// from env() but not visible from getenv().
|
// from env() but not visible from getenv().
|
||||||
assert v2.is_none() || v2 == option::Some(move v);
|
assert v2.is_none() || v2 == option::Some(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1210,7 +1210,7 @@ mod tests {
|
||||||
assert !vec::contains(e, &(copy n, ~"VALUE"));
|
assert !vec::contains(e, &(copy n, ~"VALUE"));
|
||||||
|
|
||||||
e = env();
|
e = env();
|
||||||
assert vec::contains(e, &(move n, ~"VALUE"));
|
assert vec::contains(e, &(n, ~"VALUE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -245,7 +245,7 @@ impl Path {
|
||||||
let mut st = stat::arch::default_stat();
|
let mut st = stat::arch::default_stat();
|
||||||
let r = libc::stat(buf, &mut st);
|
let r = libc::stat(buf, &mut st);
|
||||||
|
|
||||||
if r == 0 { Some(move st) } else { None }
|
if r == 0 { Some(st) } else { None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ impl Path {
|
||||||
let mut st = stat::arch::default_stat();
|
let mut st = stat::arch::default_stat();
|
||||||
let r = libc::lstat(buf, &mut st);
|
let r = libc::lstat(buf, &mut st);
|
||||||
|
|
||||||
if r == 0 { Some(move st) } else { None }
|
if r == 0 { Some(st) } else { None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ impl GenericPath for PosixPath {
|
||||||
let mut components = str::split_nonempty(s, |c| c == '/');
|
let mut components = str::split_nonempty(s, |c| c == '/');
|
||||||
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
|
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
|
||||||
return PosixPath { is_absolute: is_absolute,
|
return PosixPath { is_absolute: is_absolute,
|
||||||
components: move components }
|
components: components }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dirname() -> ~str {
|
pure fn dirname() -> ~str {
|
||||||
|
@ -390,7 +390,7 @@ impl GenericPath for PosixPath {
|
||||||
if s.len() == 0 {
|
if s.len() == 0 {
|
||||||
~"."
|
~"."
|
||||||
} else {
|
} else {
|
||||||
move s
|
s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ impl GenericPath for PosixPath {
|
||||||
let dpath = PosixPath(d);
|
let dpath = PosixPath(d);
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
Some(ref f) => dpath.push(*f),
|
Some(ref f) => dpath.push(*f),
|
||||||
None => move dpath
|
None => dpath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ impl GenericPath for PosixPath {
|
||||||
Some(ref f) => ~[copy *f]
|
Some(ref f) => ~[copy *f]
|
||||||
};
|
};
|
||||||
return PosixPath { is_absolute: false,
|
return PosixPath { is_absolute: false,
|
||||||
components: move cs }
|
components: cs }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_rel(other: &PosixPath) -> PosixPath {
|
pure fn push_rel(other: &PosixPath) -> PosixPath {
|
||||||
|
@ -491,17 +491,17 @@ impl GenericPath for PosixPath {
|
||||||
let mut ss = str::split_nonempty(
|
let mut ss = str::split_nonempty(
|
||||||
*e,
|
*e,
|
||||||
|c| windows::is_sep(c as u8));
|
|c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(move ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
}
|
}
|
||||||
PosixPath { is_absolute: self.is_absolute,
|
PosixPath { is_absolute: self.is_absolute,
|
||||||
components: move v }
|
components: v }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push(s: &str) -> PosixPath {
|
pure fn push(s: &str) -> PosixPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(move ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
PosixPath { components: move v, ..copy self }
|
PosixPath { components: v, ..copy self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn pop() -> PosixPath {
|
pure fn pop() -> PosixPath {
|
||||||
|
@ -511,7 +511,7 @@ impl GenericPath for PosixPath {
|
||||||
}
|
}
|
||||||
return PosixPath {
|
return PosixPath {
|
||||||
is_absolute: self.is_absolute,
|
is_absolute: self.is_absolute,
|
||||||
components: move cs
|
components: cs
|
||||||
}
|
}
|
||||||
//..self }
|
//..self }
|
||||||
}
|
}
|
||||||
|
@ -577,10 +577,10 @@ impl GenericPath for WindowsPath {
|
||||||
let mut components =
|
let mut components =
|
||||||
str::split_nonempty(rest, |c| windows::is_sep(c as u8));
|
str::split_nonempty(rest, |c| windows::is_sep(c as u8));
|
||||||
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
|
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
|
||||||
return WindowsPath { host: move host,
|
return WindowsPath { host: host,
|
||||||
device: move device,
|
device: device,
|
||||||
is_absolute: is_absolute,
|
is_absolute: is_absolute,
|
||||||
components: move components }
|
components: components }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn dirname() -> ~str {
|
pure fn dirname() -> ~str {
|
||||||
|
@ -589,7 +589,7 @@ impl GenericPath for WindowsPath {
|
||||||
if s.len() == 0 {
|
if s.len() == 0 {
|
||||||
~"."
|
~"."
|
||||||
} else {
|
} else {
|
||||||
move s
|
s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ impl GenericPath for WindowsPath {
|
||||||
let dpath = WindowsPath(d);
|
let dpath = WindowsPath(d);
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
Some(ref f) => dpath.push(*f),
|
Some(ref f) => dpath.push(*f),
|
||||||
None => move dpath
|
None => dpath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ impl GenericPath for WindowsPath {
|
||||||
return WindowsPath { host: None,
|
return WindowsPath { host: None,
|
||||||
device: None,
|
device: None,
|
||||||
is_absolute: false,
|
is_absolute: false,
|
||||||
components: move cs }
|
components: cs }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push_rel(other: &WindowsPath) -> WindowsPath {
|
pure fn push_rel(other: &WindowsPath) -> WindowsPath {
|
||||||
|
@ -691,22 +691,22 @@ impl GenericPath for WindowsPath {
|
||||||
let mut ss = str::split_nonempty(
|
let mut ss = str::split_nonempty(
|
||||||
*e,
|
*e,
|
||||||
|c| windows::is_sep(c as u8));
|
|c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(move ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
}
|
}
|
||||||
// tedious, but as-is, we can't use ..self
|
// tedious, but as-is, we can't use ..self
|
||||||
return WindowsPath {
|
return WindowsPath {
|
||||||
host: copy self.host,
|
host: copy self.host,
|
||||||
device: copy self.device,
|
device: copy self.device,
|
||||||
is_absolute: self.is_absolute,
|
is_absolute: self.is_absolute,
|
||||||
components: move v
|
components: v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn push(s: &str) -> WindowsPath {
|
pure fn push(s: &str) -> WindowsPath {
|
||||||
let mut v = copy self.components;
|
let mut v = copy self.components;
|
||||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||||
unsafe { v.push_all_move(move ss); }
|
unsafe { v.push_all_move(ss); }
|
||||||
return WindowsPath { components: move v, ..copy self }
|
return WindowsPath { components: v, ..copy self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn pop() -> WindowsPath {
|
pure fn pop() -> WindowsPath {
|
||||||
|
@ -718,7 +718,7 @@ impl GenericPath for WindowsPath {
|
||||||
host: copy self.host,
|
host: copy self.host,
|
||||||
device: copy self.device,
|
device: copy self.device,
|
||||||
is_absolute: self.is_absolute,
|
is_absolute: self.is_absolute,
|
||||||
components: move cs
|
components: cs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,7 +748,7 @@ pub pure fn normalize(components: &[~str]) -> ~[~str] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move cs
|
cs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Various windows helpers, and tests for the impl.
|
// Various windows helpers, and tests for the impl.
|
||||||
|
@ -771,7 +771,7 @@ pub mod windows {
|
||||||
if s[i] == '\\' as u8 {
|
if s[i] == '\\' as u8 {
|
||||||
let pre = s.slice(2, i);
|
let pre = s.slice(2, i);
|
||||||
let rest = s.slice(i, s.len());
|
let rest = s.slice(i, s.len());
|
||||||
return Some((move pre, move rest));
|
return Some((pre, rest));
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
@ -789,7 +789,7 @@ pub mod windows {
|
||||||
} else {
|
} else {
|
||||||
s.slice(2, s.len())
|
s.slice(2, s.len())
|
||||||
};
|
};
|
||||||
return Some((s.slice(0,1), move rest));
|
return Some((s.slice(0,1), rest));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ use vec;
|
||||||
const SPIN_COUNT: uint = 0;
|
const SPIN_COUNT: uint = 0;
|
||||||
|
|
||||||
macro_rules! move_it (
|
macro_rules! move_it (
|
||||||
{ $x:expr } => ( unsafe { let y = move *ptr::addr_of(&($x)); move y } )
|
{ $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
|
||||||
)
|
)
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -233,7 +233,7 @@ fn unibuffer<T>() -> ~Buffer<Packet<T>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
b.data.header.buffer = reinterpret_cast(&b);
|
b.data.header.buffer = reinterpret_cast(&b);
|
||||||
}
|
}
|
||||||
move b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -241,7 +241,7 @@ pub fn packet<T>() -> *Packet<T> {
|
||||||
let b = unibuffer();
|
let b = unibuffer();
|
||||||
let p = ptr::addr_of(&(b.data));
|
let p = ptr::addr_of(&(b.data));
|
||||||
// We'll take over memory management from here.
|
// We'll take over memory management from here.
|
||||||
unsafe { forget(move b) }
|
unsafe { forget(b) }
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ pub fn entangle_buffer<T: Owned, Tstart: Owned>(
|
||||||
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
||||||
{
|
{
|
||||||
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
|
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
|
||||||
unsafe { forget(move buffer) }
|
unsafe { forget(buffer) }
|
||||||
(SendPacketBuffered(p), RecvPacketBuffered(p))
|
(SendPacketBuffered(p), RecvPacketBuffered(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task {
|
||||||
// It might be worth making both acquire and release versions of
|
// It might be worth making both acquire and release versions of
|
||||||
// this.
|
// this.
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(rusti::atomic_xchg(transmute(move dst), src as int))
|
transmute(rusti::atomic_xchg(transmute(dst), src as int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,14 +335,14 @@ fn wait_event(this: *rust_task) -> *libc::c_void {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn swap_state_acq(dst: &mut State, src: State) -> State {
|
fn swap_state_acq(dst: &mut State, src: State) -> State {
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(rusti::atomic_xchg_acq(transmute(move dst), src as int))
|
transmute(rusti::atomic_xchg_acq(transmute(dst), src as int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn swap_state_rel(dst: &mut State, src: State) -> State {
|
fn swap_state_rel(dst: &mut State, src: State) -> State {
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(rusti::atomic_xchg_rel(transmute(move dst), src as int))
|
transmute(rusti::atomic_xchg_rel(transmute(dst), src as int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ struct BufferResource<T> {
|
||||||
// go go gadget drop glue
|
// go go gadget drop glue
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
forget(move b)
|
forget(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
|
||||||
|
|
||||||
BufferResource {
|
BufferResource {
|
||||||
// tjc: ????
|
// tjc: ????
|
||||||
buffer: move b
|
buffer: b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
|
||||||
let p = unsafe { &*p_ };
|
let p = unsafe { &*p_ };
|
||||||
assert ptr::addr_of(&(p.header)) == header;
|
assert ptr::addr_of(&(p.header)) == header;
|
||||||
assert p.payload.is_none();
|
assert p.payload.is_none();
|
||||||
p.payload = move Some(move payload);
|
p.payload = Some(payload);
|
||||||
let old_state = swap_state_rel(&mut p.header.state, Full);
|
let old_state = swap_state_rel(&mut p.header.state, Full);
|
||||||
match old_state {
|
match old_state {
|
||||||
Empty => {
|
Empty => {
|
||||||
|
@ -434,7 +434,7 @@ Fails if the sender closes the connection.
|
||||||
*/
|
*/
|
||||||
pub fn recv<T: Owned, Tbuffer: Owned>(
|
pub fn recv<T: Owned, Tbuffer: Owned>(
|
||||||
p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
p: RecvPacketBuffered<T, Tbuffer>) -> T {
|
||||||
try_recv(move p).expect("connection closed")
|
try_recv(p).expect("connection closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attempts to receive a message from a pipe.
|
/** Attempts to receive a message from a pipe.
|
||||||
|
@ -474,7 +474,7 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
||||||
let mut payload = None;
|
let mut payload = None;
|
||||||
payload <-> p.payload;
|
payload <-> p.payload;
|
||||||
p.header.state = Empty;
|
p.header.state = Empty;
|
||||||
return Some(option::unwrap(move payload))
|
return Some(option::unwrap(payload))
|
||||||
},
|
},
|
||||||
Terminated => return None,
|
Terminated => return None,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -532,7 +532,7 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.header.state = Empty;
|
p.header.state = Empty;
|
||||||
return Some(option::unwrap(move payload))
|
return Some(option::unwrap(payload))
|
||||||
}
|
}
|
||||||
Terminated => {
|
Terminated => {
|
||||||
// This assert detects when we've accidentally unsafely
|
// This assert detects when we've accidentally unsafely
|
||||||
|
@ -723,8 +723,8 @@ pub fn select2<A: Owned, Ab: Owned, B: Owned, Bb: Owned>(
|
||||||
let i = wait_many([a.header(), b.header()]);
|
let i = wait_many([a.header(), b.header()]);
|
||||||
|
|
||||||
match i {
|
match i {
|
||||||
0 => Left((try_recv(move a), move b)),
|
0 => Left((try_recv(a), b)),
|
||||||
1 => Right((move a, try_recv(move b))),
|
1 => Right((a, try_recv(b))),
|
||||||
_ => fail!(~"select2 return an invalid packet")
|
_ => fail!(~"select2 return an invalid packet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -761,10 +761,10 @@ pub fn select<T: Owned, Tb: Owned>(endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||||
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
||||||
{
|
{
|
||||||
let ready = wait_many(endpoints.map(|p| p.header()));
|
let ready = wait_many(endpoints.map(|p| p.header()));
|
||||||
let mut remaining = move endpoints;
|
let mut remaining = endpoints;
|
||||||
let port = remaining.swap_remove(ready);
|
let port = remaining.swap_remove(ready);
|
||||||
let result = try_recv(move port);
|
let result = try_recv(port);
|
||||||
(ready, move result, move remaining)
|
(ready, result, remaining)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The sending end of a pipe. It can be used to send exactly one
|
/** The sending end of a pipe. It can be used to send exactly one
|
||||||
|
@ -791,7 +791,7 @@ impl<T:Owned,Tbuffer:Owned> ::ops::Drop for SendPacketBuffered<T,Tbuffer> {
|
||||||
if self.p != None {
|
if self.p != None {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
p <-> self.p;
|
p <-> self.p;
|
||||||
sender_terminate(option::unwrap(move p))
|
sender_terminate(option::unwrap(p))
|
||||||
}
|
}
|
||||||
//unsafe { error!("send_drop: %?",
|
//unsafe { error!("send_drop: %?",
|
||||||
// if self.buffer == none {
|
// if self.buffer == none {
|
||||||
|
@ -816,7 +816,7 @@ impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||||
fn unwrap() -> *Packet<T> {
|
fn unwrap() -> *Packet<T> {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
p <-> self.p;
|
p <-> self.p;
|
||||||
option::unwrap(move p)
|
option::unwrap(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn header() -> *PacketHeader {
|
pure fn header() -> *PacketHeader {
|
||||||
|
@ -835,7 +835,7 @@ impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||||
//error!("send reuse_buffer");
|
//error!("send reuse_buffer");
|
||||||
let mut tmp = None;
|
let mut tmp = None;
|
||||||
tmp <-> self.buffer;
|
tmp <-> self.buffer;
|
||||||
option::unwrap(move tmp)
|
option::unwrap(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,7 +860,7 @@ impl<T:Owned, Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
|
||||||
if self.p != None {
|
if self.p != None {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
p <-> self.p;
|
p <-> self.p;
|
||||||
receiver_terminate(option::unwrap(move p))
|
receiver_terminate(option::unwrap(p))
|
||||||
}
|
}
|
||||||
//unsafe { error!("recv_drop: %?",
|
//unsafe { error!("recv_drop: %?",
|
||||||
// if self.buffer == none {
|
// if self.buffer == none {
|
||||||
|
@ -873,14 +873,14 @@ impl<T: Owned, Tbuffer: Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||||
fn unwrap() -> *Packet<T> {
|
fn unwrap() -> *Packet<T> {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
p <-> self.p;
|
p <-> self.p;
|
||||||
option::unwrap(move p)
|
option::unwrap(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reuse_buffer() -> BufferResource<Tbuffer> {
|
fn reuse_buffer() -> BufferResource<Tbuffer> {
|
||||||
//error!("recv reuse_buffer");
|
//error!("recv reuse_buffer");
|
||||||
let mut tmp = None;
|
let mut tmp = None;
|
||||||
tmp <-> self.buffer;
|
tmp <-> self.buffer;
|
||||||
option::unwrap(move tmp)
|
option::unwrap(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -933,14 +933,14 @@ pub fn spawn_service<T: Owned, Tb: Owned>(
|
||||||
|
|
||||||
// This is some nasty gymnastics required to safely move the pipe
|
// This is some nasty gymnastics required to safely move the pipe
|
||||||
// into a new task.
|
// into a new task.
|
||||||
let server = ~mut Some(move server);
|
let server = ~mut Some(server);
|
||||||
do task::spawn |move service, move server| {
|
do task::spawn || {
|
||||||
let mut server_ = None;
|
let mut server_ = None;
|
||||||
server_ <-> *server;
|
server_ <-> *server;
|
||||||
service(option::unwrap(move server_))
|
service(option::unwrap(server_))
|
||||||
}
|
}
|
||||||
|
|
||||||
move client
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Like `spawn_service_recv`, but for protocols that start in the
|
/** Like `spawn_service_recv`, but for protocols that start in the
|
||||||
|
@ -957,14 +957,14 @@ pub fn spawn_service_recv<T: Owned, Tb: Owned>(
|
||||||
|
|
||||||
// This is some nasty gymnastics required to safely move the pipe
|
// This is some nasty gymnastics required to safely move the pipe
|
||||||
// into a new task.
|
// into a new task.
|
||||||
let server = ~mut Some(move server);
|
let server = ~mut Some(server);
|
||||||
do task::spawn |move service, move server| {
|
do task::spawn || {
|
||||||
let mut server_ = None;
|
let mut server_ = None;
|
||||||
server_ <-> *server;
|
server_ <-> *server;
|
||||||
service(option::unwrap(move server_))
|
service(option::unwrap(server_))
|
||||||
}
|
}
|
||||||
|
|
||||||
move client
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Streams - Make pipes a little easier in general.
|
// Streams - Make pipes a little easier in general.
|
||||||
|
@ -1041,7 +1041,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
self.endp = Some(
|
self.endp = Some(
|
||||||
streamp::client::data(unwrap(move endp), move x))
|
streamp::client::data(unwrap(endp), x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1050,9 +1050,9 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
match move streamp::client::try_data(unwrap(move endp), move x) {
|
match streamp::client::try_data(unwrap(endp), x) {
|
||||||
Some(move next) => {
|
Some(next) => {
|
||||||
self.endp = Some(move next);
|
self.endp = Some(next);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
None => false
|
None => false
|
||||||
|
@ -1064,18 +1064,18 @@ impl<T: Owned> GenericPort<T> for Port<T> {
|
||||||
fn recv() -> T {
|
fn recv() -> T {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
let streamp::data(x, endp) = pipes::recv(unwrap(move endp));
|
let streamp::data(x, endp) = pipes::recv(unwrap(endp));
|
||||||
self.endp = Some(move endp);
|
self.endp = Some(endp);
|
||||||
move x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_recv() -> Option<T> {
|
fn try_recv() -> Option<T> {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
match move pipes::try_recv(unwrap(move endp)) {
|
match pipes::try_recv(unwrap(endp)) {
|
||||||
Some(streamp::data(move x, move endp)) => {
|
Some(streamp::data(x, endp)) => {
|
||||||
self.endp = Some(move endp);
|
self.endp = Some(endp);
|
||||||
Some(move x)
|
Some(x)
|
||||||
}
|
}
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
|
@ -1122,13 +1122,13 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
|
||||||
impl<T: Owned> PortSet<T> {
|
impl<T: Owned> PortSet<T> {
|
||||||
|
|
||||||
fn add(port: pipes::Port<T>) {
|
fn add(port: pipes::Port<T>) {
|
||||||
self.ports.push(move port)
|
self.ports.push(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chan() -> Chan<T> {
|
fn chan() -> Chan<T> {
|
||||||
let (po, ch) = stream();
|
let (po, ch) = stream();
|
||||||
self.add(move po);
|
self.add(po);
|
||||||
move ch
|
ch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1142,9 +1142,9 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
|
||||||
ports <-> self.ports;
|
ports <-> self.ports;
|
||||||
while result.is_none() && ports.len() > 0 {
|
while result.is_none() && ports.len() > 0 {
|
||||||
let i = wait_many(ports);
|
let i = wait_many(ports);
|
||||||
match move ports[i].try_recv() {
|
match ports[i].try_recv() {
|
||||||
Some(move m) => {
|
Some(m) => {
|
||||||
result = Some(move m);
|
result = Some(m);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Remove this port.
|
// Remove this port.
|
||||||
|
@ -1153,7 +1153,7 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ports <-> self.ports;
|
ports <-> self.ports;
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recv() -> T {
|
fn recv() -> T {
|
||||||
|
@ -1178,29 +1178,29 @@ pub type SharedChan<T> = private::Exclusive<Chan<T>>;
|
||||||
|
|
||||||
impl<T: Owned> GenericChan<T> for SharedChan<T> {
|
impl<T: Owned> GenericChan<T> for SharedChan<T> {
|
||||||
fn send(x: T) {
|
fn send(x: T) {
|
||||||
let mut xx = Some(move x);
|
let mut xx = Some(x);
|
||||||
do self.with_imm |chan| {
|
do self.with_imm |chan| {
|
||||||
let mut x = None;
|
let mut x = None;
|
||||||
x <-> xx;
|
x <-> xx;
|
||||||
chan.send(option::unwrap(move x))
|
chan.send(option::unwrap(x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
|
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
|
||||||
fn try_send(x: T) -> bool {
|
fn try_send(x: T) -> bool {
|
||||||
let mut xx = Some(move x);
|
let mut xx = Some(x);
|
||||||
do self.with_imm |chan| {
|
do self.with_imm |chan| {
|
||||||
let mut x = None;
|
let mut x = None;
|
||||||
x <-> xx;
|
x <-> xx;
|
||||||
chan.try_send(option::unwrap(move x))
|
chan.try_send(option::unwrap(x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a `chan` into a `shared_chan`.
|
/// Converts a `chan` into a `shared_chan`.
|
||||||
pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
|
pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
|
||||||
private::exclusive(move c)
|
private::exclusive(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from one of two endpoints.
|
/// Receive a message from one of two endpoints.
|
||||||
|
@ -1267,24 +1267,24 @@ impl<T: Owned> ChanOne<T> {
|
||||||
* closed.
|
* closed.
|
||||||
*/
|
*/
|
||||||
pub fn recv_one<T: Owned>(port: PortOne<T>) -> T {
|
pub fn recv_one<T: Owned>(port: PortOne<T>) -> T {
|
||||||
let oneshot::send(message) = recv(move port);
|
let oneshot::send(message) = recv(port);
|
||||||
move message
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from a oneshot pipe unless the connection was closed.
|
/// Receive a message from a oneshot pipe unless the connection was closed.
|
||||||
pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
|
pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
|
||||||
let message = try_recv(move port);
|
let message = try_recv(port);
|
||||||
|
|
||||||
if message.is_none() { None }
|
if message.is_none() { None }
|
||||||
else {
|
else {
|
||||||
let oneshot::send(message) = option::unwrap(move message);
|
let oneshot::send(message) = option::unwrap(message);
|
||||||
Some(move message)
|
Some(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
||||||
pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
|
pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
|
||||||
oneshot::client::send(move chan, move data);
|
oneshot::client::send(chan, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1293,7 +1293,7 @@ pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
|
||||||
*/
|
*/
|
||||||
pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
|
pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
|
||||||
-> bool {
|
-> bool {
|
||||||
oneshot::client::try_send(move chan, move data).is_some()
|
oneshot::client::try_send(chan, data).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod rt {
|
pub mod rt {
|
||||||
|
@ -1301,7 +1301,7 @@ pub mod rt {
|
||||||
|
|
||||||
// These are used to hide the option constructors from the
|
// These are used to hide the option constructors from the
|
||||||
// compiler because their names are changing
|
// compiler because their names are changing
|
||||||
pub fn make_some<T>(val: T) -> Option<T> { Some(move val) }
|
pub fn make_some<T>(val: T) -> Option<T> { Some(val) }
|
||||||
pub fn make_none<T>() -> Option<T> { None }
|
pub fn make_none<T>() -> Option<T> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1318,7 +1318,7 @@ pub mod test {
|
||||||
|
|
||||||
c1.send(~"abc");
|
c1.send(~"abc");
|
||||||
|
|
||||||
match (move p1, move p2).select() {
|
match (p1, p2).select() {
|
||||||
Right(_) => fail!(),
|
Right(_) => fail!(),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
@ -1330,9 +1330,9 @@ pub mod test {
|
||||||
pub fn test_oneshot() {
|
pub fn test_oneshot() {
|
||||||
let (c, p) = oneshot::init();
|
let (c, p) = oneshot::init();
|
||||||
|
|
||||||
oneshot::client::send(move c, ());
|
oneshot::client::send(c, ());
|
||||||
|
|
||||||
recv_one(move p)
|
recv_one(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1341,7 +1341,7 @@ pub mod test {
|
||||||
|
|
||||||
{
|
{
|
||||||
// Destroy the channel
|
// Destroy the channel
|
||||||
let _chan = move chan;
|
let _chan = chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert !port.peek();
|
assert !port.peek();
|
||||||
|
|
|
@ -145,11 +145,11 @@ struct ArcDestruct<T> {
|
||||||
cast::reinterpret_cast(&data.unwrapper);
|
cast::reinterpret_cast(&data.unwrapper);
|
||||||
let (message, response) = option::swap_unwrap(p);
|
let (message, response) = option::swap_unwrap(p);
|
||||||
// Send 'ready' and wait for a response.
|
// Send 'ready' and wait for a response.
|
||||||
pipes::send_one(move message, ());
|
pipes::send_one(message, ());
|
||||||
// Unkillable wait. Message guaranteed to come.
|
// Unkillable wait. Message guaranteed to come.
|
||||||
if pipes::recv_one(move response) {
|
if pipes::recv_one(response) {
|
||||||
// Other task got the data.
|
// Other task got the data.
|
||||||
cast::forget(move data);
|
cast::forget(data);
|
||||||
} else {
|
} else {
|
||||||
// Other task was killed. drop glue takes over.
|
// Other task was killed. drop glue takes over.
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ struct ArcDestruct<T> {
|
||||||
// drop glue takes over.
|
// drop glue takes over.
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cast::forget(move data);
|
cast::forget(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,13 +182,13 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
||||||
// tried to wake us whether they should hand-off the data to
|
// tried to wake us whether they should hand-off the data to
|
||||||
// us.
|
// us.
|
||||||
if task::failing() {
|
if task::failing() {
|
||||||
pipes::send_one(move response, false);
|
pipes::send_one(response, false);
|
||||||
// Either this swap_unwrap or the one below (at "Got
|
// Either this swap_unwrap or the one below (at "Got
|
||||||
// here") ought to run.
|
// here") ought to run.
|
||||||
cast::forget(option::swap_unwrap(&mut self.ptr));
|
cast::forget(option::swap_unwrap(&mut self.ptr));
|
||||||
} else {
|
} else {
|
||||||
assert self.ptr.is_none();
|
assert self.ptr.is_none();
|
||||||
pipes::send_one(move response, true);
|
pipes::send_one(response, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,8 +198,8 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&rc.data);
|
let ptr: ~ArcData<T> = cast::reinterpret_cast(&rc.data);
|
||||||
let (p1,c1) = pipes::oneshot(); // ()
|
let (p1,c1) = pipes::oneshot(); // ()
|
||||||
let (p2,c2) = pipes::oneshot(); // bool
|
let (p2,c2) = pipes::oneshot(); // bool
|
||||||
let server: UnwrapProto = ~mut Some((move c1,move p2));
|
let server: UnwrapProto = ~mut Some((c1,p2));
|
||||||
let serverp: int = cast::transmute(move server);
|
let serverp: int = cast::transmute(server);
|
||||||
// Try to put our server end in the unwrapper slot.
|
// Try to put our server end in the unwrapper slot.
|
||||||
if compare_and_swap(&mut ptr.unwrapper, 0, serverp) {
|
if compare_and_swap(&mut ptr.unwrapper, 0, serverp) {
|
||||||
// Got in. Step 0: Tell destructor not to run. We are now it.
|
// Got in. Step 0: Tell destructor not to run. We are now it.
|
||||||
|
@ -210,15 +210,15 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
||||||
if new_count == 0 {
|
if new_count == 0 {
|
||||||
// We were the last owner. Can unwrap immediately.
|
// We were the last owner. Can unwrap immediately.
|
||||||
// Also we have to free the server endpoints.
|
// Also we have to free the server endpoints.
|
||||||
let _server: UnwrapProto = cast::transmute(move serverp);
|
let _server: UnwrapProto = cast::transmute(serverp);
|
||||||
option::swap_unwrap(&mut ptr.data)
|
option::swap_unwrap(&mut ptr.data)
|
||||||
// drop glue takes over.
|
// drop glue takes over.
|
||||||
} else {
|
} else {
|
||||||
// The *next* person who sees the refcount hit 0 will wake us.
|
// The *next* person who sees the refcount hit 0 will wake us.
|
||||||
let end_result =
|
let end_result =
|
||||||
DeathThroes { ptr: Some(move ptr),
|
DeathThroes { ptr: Some(ptr),
|
||||||
response: Some(move c2) };
|
response: Some(c2) };
|
||||||
let mut p1 = Some(move p1); // argh
|
let mut p1 = Some(p1); // argh
|
||||||
do task::rekillable {
|
do task::rekillable {
|
||||||
pipes::recv_one(option::swap_unwrap(&mut p1));
|
pipes::recv_one(option::swap_unwrap(&mut p1));
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,9 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Somebody else was trying to unwrap. Avoid guaranteed deadlock.
|
// Somebody else was trying to unwrap. Avoid guaranteed deadlock.
|
||||||
cast::forget(move ptr);
|
cast::forget(ptr);
|
||||||
// Also we have to free the (rejected) server endpoints.
|
// Also we have to free the (rejected) server endpoints.
|
||||||
let _server: UnwrapProto = cast::transmute(move serverp);
|
let _server: UnwrapProto = cast::transmute(serverp);
|
||||||
fail!(~"Another task is already unwrapping this ARC!");
|
fail!(~"Another task is already unwrapping this ARC!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,9 +248,9 @@ pub type SharedMutableState<T> = ArcDestruct<T>;
|
||||||
|
|
||||||
pub unsafe fn shared_mutable_state<T: Owned>(data: T) ->
|
pub unsafe fn shared_mutable_state<T: Owned>(data: T) ->
|
||||||
SharedMutableState<T> {
|
SharedMutableState<T> {
|
||||||
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) };
|
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = cast::transmute(move data);
|
let ptr = cast::transmute(data);
|
||||||
ArcDestruct(ptr)
|
ArcDestruct(ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ pub unsafe fn get_shared_mutable_state<T: Owned>(
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||||
assert ptr.count > 0;
|
assert ptr.count > 0;
|
||||||
let r = cast::transmute(option::get_ref(&ptr.data));
|
let r = cast::transmute(option::get_ref(&ptr.data));
|
||||||
cast::forget(move ptr);
|
cast::forget(ptr);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ pub unsafe fn get_shared_immutable_state<T: Owned>(
|
||||||
assert ptr.count > 0;
|
assert ptr.count > 0;
|
||||||
// Cast us back into the correct region
|
// Cast us back into the correct region
|
||||||
let r = cast::transmute_region(option::get_ref(&ptr.data));
|
let r = cast::transmute_region(option::get_ref(&ptr.data));
|
||||||
cast::forget(move ptr);
|
cast::forget(ptr);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ pub unsafe fn clone_shared_mutable_state<T: Owned>(rc: &SharedMutableState<T>)
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||||
let new_count = rusti::atomic_xadd(&mut ptr.count, 1) + 1;
|
let new_count = rusti::atomic_xadd(&mut ptr.count, 1) + 1;
|
||||||
assert new_count >= 2;
|
assert new_count >= 2;
|
||||||
cast::forget(move ptr);
|
cast::forget(ptr);
|
||||||
}
|
}
|
||||||
ArcDestruct((*rc).data)
|
ArcDestruct((*rc).data)
|
||||||
}
|
}
|
||||||
|
@ -355,9 +355,9 @@ pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
|
||||||
|
|
||||||
pub fn exclusive<T:Owned >(user_data: T) -> Exclusive<T> {
|
pub fn exclusive<T:Owned >(user_data: T) -> Exclusive<T> {
|
||||||
let data = ExData {
|
let data = ExData {
|
||||||
lock: LittleLock(), mut failed: false, mut data: move user_data
|
lock: LittleLock(), mut failed: false, mut data: user_data
|
||||||
};
|
};
|
||||||
Exclusive { x: unsafe { shared_mutable_state(move data) } }
|
Exclusive { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> Clone for Exclusive<T> {
|
impl<T: Owned> Clone for Exclusive<T> {
|
||||||
|
@ -386,7 +386,7 @@ impl<T: Owned> Exclusive<T> {
|
||||||
(*rec).failed = true;
|
(*rec).failed = true;
|
||||||
let result = f(&mut (*rec).data);
|
let result = f(&mut (*rec).data);
|
||||||
(*rec).failed = false;
|
(*rec).failed = false;
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,10 +401,10 @@ impl<T: Owned> Exclusive<T> {
|
||||||
|
|
||||||
// FIXME(#3724) make this a by-move method on the exclusive
|
// FIXME(#3724) make this a by-move method on the exclusive
|
||||||
pub fn unwrap_exclusive<T: Owned>(arc: Exclusive<T>) -> T {
|
pub fn unwrap_exclusive<T: Owned>(arc: Exclusive<T>) -> T {
|
||||||
let Exclusive { x: x } = move arc;
|
let Exclusive { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(move x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let ExData { data: data, _ } = move inner;
|
let ExData { data: data, _ } = inner;
|
||||||
move data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -430,9 +430,9 @@ pub mod tests {
|
||||||
for uint::range(0, num_tasks) |_i| {
|
for uint::range(0, num_tasks) |_i| {
|
||||||
let total = total.clone();
|
let total = total.clone();
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
futures.push(move port);
|
futures.push(port);
|
||||||
|
|
||||||
do task::spawn |move total, move chan| {
|
do task::spawn || {
|
||||||
for uint::range(0, count) |_i| {
|
for uint::range(0, count) |_i| {
|
||||||
do total.with |count| {
|
do total.with |count| {
|
||||||
**count += 1;
|
**count += 1;
|
||||||
|
@ -455,7 +455,7 @@ pub mod tests {
|
||||||
// accesses will also fail.
|
// accesses will also fail.
|
||||||
let x = exclusive(1);
|
let x = exclusive(1);
|
||||||
let x2 = x.clone();
|
let x2 = x.clone();
|
||||||
do task::try |move x2| {
|
do task::try || {
|
||||||
do x2.with |one| {
|
do x2.with |one| {
|
||||||
assert *one == 2;
|
assert *one == 2;
|
||||||
}
|
}
|
||||||
|
@ -468,31 +468,31 @@ pub mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
pub fn exclusive_unwrap_basic() {
|
pub fn exclusive_unwrap_basic() {
|
||||||
let x = exclusive(~~"hello");
|
let x = exclusive(~~"hello");
|
||||||
assert unwrap_exclusive(move x) == ~~"hello";
|
assert unwrap_exclusive(x) == ~~"hello";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn exclusive_unwrap_contended() {
|
pub fn exclusive_unwrap_contended() {
|
||||||
let x = exclusive(~~"hello");
|
let x = exclusive(~~"hello");
|
||||||
let x2 = ~mut Some(x.clone());
|
let x2 = ~mut Some(x.clone());
|
||||||
do task::spawn |move x2| {
|
do task::spawn || {
|
||||||
let x2 = option::swap_unwrap(x2);
|
let x2 = option::swap_unwrap(x2);
|
||||||
do x2.with |_hello| { }
|
do x2.with |_hello| { }
|
||||||
task::yield();
|
task::yield();
|
||||||
}
|
}
|
||||||
assert unwrap_exclusive(move x) == ~~"hello";
|
assert unwrap_exclusive(x) == ~~"hello";
|
||||||
|
|
||||||
// Now try the same thing, but with the child task blocking.
|
// Now try the same thing, but with the child task blocking.
|
||||||
let x = exclusive(~~"hello");
|
let x = exclusive(~~"hello");
|
||||||
let x2 = ~mut Some(x.clone());
|
let x2 = ~mut Some(x.clone());
|
||||||
let mut res = None;
|
let mut res = None;
|
||||||
do task::task().future_result(|+r| res = Some(move r)).spawn
|
do task::task().future_result(|+r| res = Some(r)).spawn
|
||||||
|move x2| {
|
|| {
|
||||||
let x2 = option::swap_unwrap(x2);
|
let x2 = option::swap_unwrap(x2);
|
||||||
assert unwrap_exclusive(move x2) == ~~"hello";
|
assert unwrap_exclusive(x2) == ~~"hello";
|
||||||
}
|
}
|
||||||
// Have to get rid of our reference before blocking.
|
// Have to get rid of our reference before blocking.
|
||||||
{ let _x = move x; } // FIXME(#3161) util::ignore doesn't work here
|
{ let _x = x; } // FIXME(#3161) util::ignore doesn't work here
|
||||||
let res = option::swap_unwrap(&mut res);
|
let res = option::swap_unwrap(&mut res);
|
||||||
res.recv();
|
res.recv();
|
||||||
}
|
}
|
||||||
|
@ -502,12 +502,12 @@ pub mod tests {
|
||||||
let x = exclusive(~~"hello");
|
let x = exclusive(~~"hello");
|
||||||
let x2 = ~mut Some(x.clone());
|
let x2 = ~mut Some(x.clone());
|
||||||
let mut res = None;
|
let mut res = None;
|
||||||
do task::task().future_result(|+r| res = Some(move r)).spawn
|
do task::task().future_result(|+r| res = Some(r)).spawn
|
||||||
|move x2| {
|
|| {
|
||||||
let x2 = option::swap_unwrap(x2);
|
let x2 = option::swap_unwrap(x2);
|
||||||
assert unwrap_exclusive(move x2) == ~~"hello";
|
assert unwrap_exclusive(x2) == ~~"hello";
|
||||||
}
|
}
|
||||||
assert unwrap_exclusive(move x) == ~~"hello";
|
assert unwrap_exclusive(x) == ~~"hello";
|
||||||
let res = option::swap_unwrap(&mut res);
|
let res = option::swap_unwrap(&mut res);
|
||||||
res.recv();
|
res.recv();
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ pub mod tests {
|
||||||
for 10.times { task::yield(); } // try to let the unwrapper go
|
for 10.times { task::yield(); } // try to let the unwrapper go
|
||||||
fail!(); // punt it awake from its deadlock
|
fail!(); // punt it awake from its deadlock
|
||||||
}
|
}
|
||||||
let _z = unwrap_exclusive(move x);
|
let _z = unwrap_exclusive(x);
|
||||||
do x2.with |_hello| { }
|
do x2.with |_hello| { }
|
||||||
};
|
};
|
||||||
assert result.is_err();
|
assert result.is_err();
|
||||||
|
|
|
@ -273,7 +273,7 @@ impl Rng {
|
||||||
s = s + str::from_char(self.gen_char_from(charset));
|
s = s + str::from_char(self.gen_char_from(charset));
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
move s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a random byte string of the specified length
|
/// Return a random byte string of the specified length
|
||||||
|
@ -339,14 +339,14 @@ impl Rng {
|
||||||
r.push(item.item);
|
r.push(item.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shuffle a vec
|
/// Shuffle a vec
|
||||||
fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
|
fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
|
||||||
let mut m = vec::from_slice(values);
|
let mut m = vec::from_slice(values);
|
||||||
self.shuffle_mut(m);
|
self.shuffle_mut(m);
|
||||||
move m
|
m
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shuffle a mutable vec in place
|
/// Shuffle a mutable vec in place
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub struct MovePtrAdaptor<V> {
|
||||||
inner: V
|
inner: V
|
||||||
}
|
}
|
||||||
pub fn MovePtrAdaptor<V: TyVisitor MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
pub fn MovePtrAdaptor<V: TyVisitor MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
||||||
MovePtrAdaptor { inner: move v }
|
MovePtrAdaptor { inner: v }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
|
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
|
||||||
|
|
|
@ -200,8 +200,8 @@ impl ReprVisitor {
|
||||||
fn visit_ptr_inner(ptr: *c_void, inner: *TyDesc) -> bool {
|
fn visit_ptr_inner(ptr: *c_void, inner: *TyDesc) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut u = ReprVisitor(ptr, self.writer);
|
let mut u = ReprVisitor(ptr, self.writer);
|
||||||
let v = reflect::MovePtrAdaptor(move u);
|
let v = reflect::MovePtrAdaptor(u);
|
||||||
visit_tydesc(inner, (move v) as @TyVisitor);
|
visit_tydesc(inner, (v) as @TyVisitor);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,8 +569,8 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
|
||||||
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
|
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
|
||||||
let tydesc = intrinsic::get_tydesc::<T>();
|
let tydesc = intrinsic::get_tydesc::<T>();
|
||||||
let mut u = ReprVisitor(ptr, writer);
|
let mut u = ReprVisitor(ptr, writer);
|
||||||
let v = reflect::MovePtrAdaptor(move u);
|
let v = reflect::MovePtrAdaptor(u);
|
||||||
visit_tydesc(tydesc, (move v) as @TyVisitor)
|
visit_tydesc(tydesc, (v) as @TyVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,9 +125,9 @@ pub pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
|
pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
|
||||||
-> Result<U, V>) -> Result<U, V> {
|
-> Result<U, V>) -> Result<U, V> {
|
||||||
match move res {
|
match res {
|
||||||
Ok(move t) => op(move t),
|
Ok(t) => op(t),
|
||||||
Err(move e) => Err(move e)
|
Err(e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,9 +144,9 @@ pub pure fn chain_err<T, U, V>(
|
||||||
res: Result<T, V>,
|
res: Result<T, V>,
|
||||||
op: fn(t: V) -> Result<T, U>)
|
op: fn(t: V) -> Result<T, U>)
|
||||||
-> Result<T, U> {
|
-> Result<T, U> {
|
||||||
match move res {
|
match res {
|
||||||
Ok(move t) => Ok(move t),
|
Ok(t) => Ok(t),
|
||||||
Err(move v) => op(move v)
|
Err(v) => op(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ pub fn map_vec<T,U:Copy,V:Copy>(
|
||||||
Err(copy u) => return Err(u)
|
Err(copy u) => return Err(u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(move vs);
|
return Ok(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -349,7 +349,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
|
||||||
}
|
}
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
return Ok(move vs);
|
return Ok(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,8 +377,8 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
||||||
/// Unwraps a result, assuming it is an `ok(T)`
|
/// Unwraps a result, assuming it is an `ok(T)`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
|
pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
|
||||||
match move res {
|
match res {
|
||||||
Ok(move t) => move t,
|
Ok(t) => t,
|
||||||
Err(_) => fail!(~"unwrap called on an err result")
|
Err(_) => fail!(~"unwrap called on an err result")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,8 +386,8 @@ pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
|
||||||
/// Unwraps a result, assuming it is an `err(U)`
|
/// Unwraps a result, assuming it is an `err(U)`
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn unwrap_err<T, U>(res: Result<T, U>) -> U {
|
pub pure fn unwrap_err<T, U>(res: Result<T, U>) -> U {
|
||||||
match move res {
|
match res {
|
||||||
Err(move u) => move u,
|
Err(u) => u,
|
||||||
Ok(_) => fail!(~"unwrap called on an ok result")
|
Ok(_) => fail!(~"unwrap called on an ok result")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
|
||||||
|
|
||||||
fn ProgRes(r: ProgRepr) -> ProgRes {
|
fn ProgRes(r: ProgRepr) -> ProgRes {
|
||||||
ProgRes {
|
ProgRes {
|
||||||
r: move r
|
r: r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,11 +344,11 @@ pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
|
||||||
let ch_clone = ch.clone();
|
let ch_clone = ch.clone();
|
||||||
do task::spawn_sched(task::SingleThreaded) {
|
do task::spawn_sched(task::SingleThreaded) {
|
||||||
let errput = readclose(pipe_err.in);
|
let errput = readclose(pipe_err.in);
|
||||||
ch.send((2, move errput));
|
ch.send((2, errput));
|
||||||
};
|
};
|
||||||
do task::spawn_sched(task::SingleThreaded) {
|
do task::spawn_sched(task::SingleThreaded) {
|
||||||
let output = readclose(pipe_out.in);
|
let output = readclose(pipe_out.in);
|
||||||
ch_clone.send((1, move output));
|
ch_clone.send((1, output));
|
||||||
};
|
};
|
||||||
let status = run::waitpid(pid);
|
let status = run::waitpid(pid);
|
||||||
let mut errs = ~"";
|
let mut errs = ~"";
|
||||||
|
@ -358,10 +358,10 @@ pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
|
||||||
let stream = p.recv();
|
let stream = p.recv();
|
||||||
match stream {
|
match stream {
|
||||||
(1, copy s) => {
|
(1, copy s) => {
|
||||||
outs = move s;
|
outs = s;
|
||||||
}
|
}
|
||||||
(2, copy s) => {
|
(2, copy s) => {
|
||||||
errs = move s;
|
errs = s;
|
||||||
}
|
}
|
||||||
(n, _) => {
|
(n, _) => {
|
||||||
fail!(fmt!("program_output received an unexpected file \
|
fail!(fmt!("program_output received an unexpected file \
|
||||||
|
@ -371,8 +371,8 @@ pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
|
||||||
count -= 1;
|
count -= 1;
|
||||||
};
|
};
|
||||||
return ProgramOutput {status: status,
|
return ProgramOutput {status: status,
|
||||||
out: move outs,
|
out: outs,
|
||||||
err: move errs};
|
err: errs};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ pub mod tests {
|
||||||
|
|
||||||
assert f(20) == 30;
|
assert f(20) == 30;
|
||||||
|
|
||||||
let original_closure: Closure = cast::transmute(move f);
|
let original_closure: Closure = cast::transmute(f);
|
||||||
|
|
||||||
let actual_function_pointer = original_closure.code;
|
let actual_function_pointer = original_closure.code;
|
||||||
let environment = original_closure.env;
|
let environment = original_closure.env;
|
||||||
|
@ -226,7 +226,7 @@ pub mod tests {
|
||||||
env: environment
|
env: environment
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_f: fn(int) -> int = cast::transmute(move new_closure);
|
let new_f: fn(int) -> int = cast::transmute(new_closure);
|
||||||
assert new_f(20) == 30;
|
assert new_f(20) == 30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
||||||
cast::bump_box_refcount(map);
|
cast::bump_box_refcount(map);
|
||||||
map
|
map
|
||||||
} else {
|
} else {
|
||||||
let map = cast::transmute(move map_ptr);
|
let map = cast::transmute(map_ptr);
|
||||||
cast::bump_box_refcount(map);
|
cast::bump_box_refcount(map);
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ unsafe fn local_get_helper<T: Durable>(
|
||||||
// overwriting the local_data_box we need to give an extra reference.
|
// overwriting the local_data_box we need to give an extra reference.
|
||||||
// We must also give an extra reference when not removing.
|
// We must also give an extra reference when not removing.
|
||||||
let (index, data_ptr) = *result;
|
let (index, data_ptr) = *result;
|
||||||
let data: @T = cast::transmute(move data_ptr);
|
let data: @T = cast::transmute(data_ptr);
|
||||||
cast::bump_box_refcount(data);
|
cast::bump_box_refcount(data);
|
||||||
if do_pop {
|
if do_pop {
|
||||||
(*map).set_elt(index, None);
|
(*map).set_elt(index, None);
|
||||||
|
@ -182,6 +182,6 @@ pub unsafe fn local_modify<T: Durable>(
|
||||||
// Could be more efficient by doing the lookup work, but this is easy.
|
// Could be more efficient by doing the lookup work, but this is easy.
|
||||||
let newdata = modify_fn(local_pop(task, key));
|
let newdata = modify_fn(local_pop(task, key));
|
||||||
if newdata.is_some() {
|
if newdata.is_some() {
|
||||||
local_set(task, key, option::unwrap(move newdata));
|
local_set(task, key, option::unwrap(newdata));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ pub struct TaskBuilder {
|
||||||
pub fn task() -> TaskBuilder {
|
pub fn task() -> TaskBuilder {
|
||||||
TaskBuilder {
|
TaskBuilder {
|
||||||
opts: default_task_opts(),
|
opts: default_task_opts(),
|
||||||
gen_body: |body| move body, // Identity function
|
gen_body: |body| body, // Identity function
|
||||||
can_not_copy: None,
|
can_not_copy: None,
|
||||||
mut consumed: false,
|
mut consumed: false,
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ impl TaskBuilder {
|
||||||
// Construct the future and give it to the caller.
|
// Construct the future and give it to the caller.
|
||||||
let (notify_pipe_po, notify_pipe_ch) = stream::<TaskResult>();
|
let (notify_pipe_po, notify_pipe_ch) = stream::<TaskResult>();
|
||||||
|
|
||||||
blk(move notify_pipe_po);
|
blk(notify_pipe_po);
|
||||||
|
|
||||||
// Reconfigure self to use a notify channel.
|
// Reconfigure self to use a notify channel.
|
||||||
TaskBuilder {
|
TaskBuilder {
|
||||||
|
@ -336,7 +336,7 @@ impl TaskBuilder {
|
||||||
opts: TaskOpts {
|
opts: TaskOpts {
|
||||||
linked: self.opts.linked,
|
linked: self.opts.linked,
|
||||||
supervised: self.opts.supervised,
|
supervised: self.opts.supervised,
|
||||||
notify_chan: move notify_chan,
|
notify_chan: notify_chan,
|
||||||
sched: SchedOpts { mode: mode, foreign_stack_size: None}
|
sched: SchedOpts { mode: mode, foreign_stack_size: None}
|
||||||
},
|
},
|
||||||
can_not_copy: None,
|
can_not_copy: None,
|
||||||
|
@ -366,11 +366,7 @@ impl TaskBuilder {
|
||||||
notify_chan: notify_chan,
|
notify_chan: notify_chan,
|
||||||
sched: self.opts.sched
|
sched: self.opts.sched
|
||||||
},
|
},
|
||||||
// tjc: I think this is the line that gets miscompiled
|
gen_body: |body| { wrapper(prev_gen_body(body)) },
|
||||||
// w/ last-use off, if we leave out the move prev_gen_body?
|
|
||||||
// that makes no sense, though...
|
|
||||||
gen_body: |move prev_gen_body,
|
|
||||||
body| { wrapper(prev_gen_body(move body)) },
|
|
||||||
can_not_copy: None,
|
can_not_copy: None,
|
||||||
.. self.consume()
|
.. self.consume()
|
||||||
}
|
}
|
||||||
|
@ -397,12 +393,12 @@ impl TaskBuilder {
|
||||||
notify_chan: notify_chan,
|
notify_chan: notify_chan,
|
||||||
sched: x.opts.sched
|
sched: x.opts.sched
|
||||||
};
|
};
|
||||||
spawn::spawn_raw(move opts, (x.gen_body)(move f));
|
spawn::spawn_raw(opts, (x.gen_body)(f));
|
||||||
}
|
}
|
||||||
/// Runs a task, while transfering ownership of one argument to the child.
|
/// Runs a task, while transfering ownership of one argument to the child.
|
||||||
fn spawn_with<A: Owned>(arg: A, f: fn~(v: A)) {
|
fn spawn_with<A: Owned>(arg: A, f: fn~(v: A)) {
|
||||||
let arg = ~mut Some(move arg);
|
let arg = ~mut Some(arg);
|
||||||
do self.spawn |move arg, move f| {
|
do self.spawn || {
|
||||||
f(option::swap_unwrap(arg))
|
f(option::swap_unwrap(arg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,12 +421,12 @@ impl TaskBuilder {
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
|
|
||||||
let fr_task_builder = self.future_result(|+r| {
|
let fr_task_builder = self.future_result(|+r| {
|
||||||
result = Some(move r);
|
result = Some(r);
|
||||||
});
|
});
|
||||||
do fr_task_builder.spawn |move f, move ch| {
|
do fr_task_builder.spawn || {
|
||||||
ch.send(f());
|
ch.send(f());
|
||||||
}
|
}
|
||||||
match option::unwrap(move result).recv() {
|
match option::unwrap(result).recv() {
|
||||||
Success => result::Ok(po.recv()),
|
Success => result::Ok(po.recv()),
|
||||||
Failure => result::Err(())
|
Failure => result::Err(())
|
||||||
}
|
}
|
||||||
|
@ -471,7 +467,7 @@ pub fn spawn(f: fn~()) {
|
||||||
* This function is equivalent to `task().spawn(f)`.
|
* This function is equivalent to `task().spawn(f)`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().spawn(move f)
|
task().spawn(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_unlinked(f: fn~()) {
|
pub fn spawn_unlinked(f: fn~()) {
|
||||||
|
@ -480,7 +476,7 @@ pub fn spawn_unlinked(f: fn~()) {
|
||||||
* task or the child task fails, the other will not be killed.
|
* task or the child task fails, the other will not be killed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().unlinked().spawn(move f)
|
task().unlinked().spawn(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_supervised(f: fn~()) {
|
pub fn spawn_supervised(f: fn~()) {
|
||||||
|
@ -489,7 +485,7 @@ pub fn spawn_supervised(f: fn~()) {
|
||||||
* task or the child task fails, the other will not be killed.
|
* task or the child task fails, the other will not be killed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().supervised().spawn(move f)
|
task().supervised().spawn(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
|
pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
|
||||||
|
@ -503,7 +499,7 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
|
||||||
* This function is equivalent to `task().spawn_with(arg, f)`.
|
* This function is equivalent to `task().spawn_with(arg, f)`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().spawn_with(move arg, move f)
|
task().spawn_with(arg, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
|
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
|
||||||
|
@ -519,7 +515,7 @@ pub fn spawn_sched(mode: SchedMode, f: fn~()) {
|
||||||
* greater than zero.
|
* greater than zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().sched_mode(mode).spawn(move f)
|
task().sched_mode(mode).spawn(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
|
pub fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
|
||||||
|
@ -530,7 +526,7 @@ pub fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
|
||||||
* This is equivalent to task().supervised().try.
|
* This is equivalent to task().supervised().try.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task().supervised().try(move f)
|
task().supervised().try(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -719,12 +715,12 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
|
||||||
let mut opts = default_task_opts();
|
let mut opts = default_task_opts();
|
||||||
opts.linked = true;
|
opts.linked = true;
|
||||||
opts.supervised = true;
|
opts.supervised = true;
|
||||||
move opts
|
opts
|
||||||
};
|
};
|
||||||
|
|
||||||
let b0 = task();
|
let b0 = task();
|
||||||
let b1 = TaskBuilder {
|
let b1 = TaskBuilder {
|
||||||
opts: move opts,
|
opts: opts,
|
||||||
can_not_copy: None,
|
can_not_copy: None,
|
||||||
.. b0
|
.. b0
|
||||||
};
|
};
|
||||||
|
@ -739,12 +735,12 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
|
||||||
let mut opts = default_task_opts();
|
let mut opts = default_task_opts();
|
||||||
opts.linked = true;
|
opts.linked = true;
|
||||||
opts.supervised = true;
|
opts.supervised = true;
|
||||||
move opts
|
opts
|
||||||
};
|
};
|
||||||
|
|
||||||
let b0 = task();
|
let b0 = task();
|
||||||
let b1 = TaskBuilder {
|
let b1 = TaskBuilder {
|
||||||
opts: move opts,
|
opts: opts,
|
||||||
can_not_copy: None,
|
can_not_copy: None,
|
||||||
.. b0
|
.. b0
|
||||||
};
|
};
|
||||||
|
@ -843,7 +839,7 @@ fn test_add_wrapper() {
|
||||||
let ch = Wrapper { f: Some(ch) };
|
let ch = Wrapper { f: Some(ch) };
|
||||||
let b1 = do b0.add_wrapper |body| {
|
let b1 = do b0.add_wrapper |body| {
|
||||||
let ch = Wrapper { f: Some(ch.f.swap_unwrap()) };
|
let ch = Wrapper { f: Some(ch.f.swap_unwrap()) };
|
||||||
fn~(move body) {
|
fn~() {
|
||||||
let ch = ch.f.swap_unwrap();
|
let ch = ch.f.swap_unwrap();
|
||||||
body();
|
body();
|
||||||
ch.send(());
|
ch.send(());
|
||||||
|
@ -857,15 +853,15 @@ fn test_add_wrapper() {
|
||||||
#[ignore(cfg(windows))]
|
#[ignore(cfg(windows))]
|
||||||
fn test_future_result() {
|
fn test_future_result() {
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
do task().future_result(|+r| { result = Some(move r); }).spawn { }
|
do task().future_result(|+r| { result = Some(r); }).spawn { }
|
||||||
assert option::unwrap(move result).recv() == Success;
|
assert option::unwrap(result).recv() == Success;
|
||||||
|
|
||||||
result = None;
|
result = None;
|
||||||
do task().future_result(|+r|
|
do task().future_result(|+r|
|
||||||
{ result = Some(move r); }).unlinked().spawn {
|
{ result = Some(r); }).unlinked().spawn {
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
assert option::unwrap(move result).recv() == Failure;
|
assert option::unwrap(result).recv() == Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||||
|
@ -1024,7 +1020,7 @@ fn avoid_copying_the_body(spawnfn: fn(v: fn~())) {
|
||||||
let x = ~1;
|
let x = ~1;
|
||||||
let x_in_parent = ptr::addr_of(&(*x)) as uint;
|
let x_in_parent = ptr::addr_of(&(*x)) as uint;
|
||||||
|
|
||||||
do spawnfn |move x| {
|
do spawnfn || {
|
||||||
let x_in_child = ptr::addr_of(&(*x)) as uint;
|
let x_in_child = ptr::addr_of(&(*x)) as uint;
|
||||||
ch.send(x_in_child);
|
ch.send(x_in_child);
|
||||||
}
|
}
|
||||||
|
@ -1041,7 +1037,7 @@ fn test_avoid_copying_the_body_spawn() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_avoid_copying_the_body_task_spawn() {
|
fn test_avoid_copying_the_body_task_spawn() {
|
||||||
do avoid_copying_the_body |f| {
|
do avoid_copying_the_body |f| {
|
||||||
do task().spawn |move f| {
|
do task().spawn || {
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1050,7 +1046,7 @@ fn test_avoid_copying_the_body_task_spawn() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_avoid_copying_the_body_try() {
|
fn test_avoid_copying_the_body_try() {
|
||||||
do avoid_copying_the_body |f| {
|
do avoid_copying_the_body |f| {
|
||||||
do try |move f| {
|
do try || {
|
||||||
f()
|
f()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1055,7 @@ fn test_avoid_copying_the_body_try() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_avoid_copying_the_body_unlinked() {
|
fn test_avoid_copying_the_body_unlinked() {
|
||||||
do avoid_copying_the_body |f| {
|
do avoid_copying_the_body |f| {
|
||||||
do spawn_unlinked |move f| {
|
do spawn_unlinked || {
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1096,12 +1092,12 @@ fn test_unkillable() {
|
||||||
unsafe {
|
unsafe {
|
||||||
do unkillable {
|
do unkillable {
|
||||||
let p = ~0;
|
let p = ~0;
|
||||||
let pp: *uint = cast::transmute(move p);
|
let pp: *uint = cast::transmute(p);
|
||||||
|
|
||||||
// If we are killed here then the box will leak
|
// If we are killed here then the box will leak
|
||||||
po.recv();
|
po.recv();
|
||||||
|
|
||||||
let _p: ~int = cast::transmute(move pp);
|
let _p: ~int = cast::transmute(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1112,7 @@ fn test_unkillable_nested() {
|
||||||
let (po, ch) = pipes::stream();
|
let (po, ch) = pipes::stream();
|
||||||
|
|
||||||
// We want to do this after failing
|
// We want to do this after failing
|
||||||
do spawn_unlinked |move ch| {
|
do spawn_unlinked || {
|
||||||
for iter::repeat(10) { yield() }
|
for iter::repeat(10) { yield() }
|
||||||
ch.send(());
|
ch.send(());
|
||||||
}
|
}
|
||||||
|
@ -1132,12 +1128,12 @@ fn test_unkillable_nested() {
|
||||||
do unkillable {
|
do unkillable {
|
||||||
do unkillable {} // Here's the difference from the previous test.
|
do unkillable {} // Here's the difference from the previous test.
|
||||||
let p = ~0;
|
let p = ~0;
|
||||||
let pp: *uint = cast::transmute(move p);
|
let pp: *uint = cast::transmute(p);
|
||||||
|
|
||||||
// If we are killed here then the box will leak
|
// If we are killed here then the box will leak
|
||||||
po.recv();
|
po.recv();
|
||||||
|
|
||||||
let _p: ~int = cast::transmute(move pp);
|
let _p: ~int = cast::transmute(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,7 +1177,7 @@ fn test_child_doesnt_ref_parent() {
|
||||||
fn test_sched_thread_per_core() {
|
fn test_sched_thread_per_core() {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
|
|
||||||
do spawn_sched(ThreadPerCore) |move chan| {
|
do spawn_sched(ThreadPerCore) || {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cores = rt::rust_num_threads();
|
let cores = rt::rust_num_threads();
|
||||||
let reported_threads = rt::rust_sched_threads();
|
let reported_threads = rt::rust_sched_threads();
|
||||||
|
@ -1197,7 +1193,7 @@ fn test_sched_thread_per_core() {
|
||||||
fn test_spawn_thread_on_demand() {
|
fn test_spawn_thread_on_demand() {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
|
|
||||||
do spawn_sched(ManualThreads(2)) |move chan| {
|
do spawn_sched(ManualThreads(2)) || {
|
||||||
unsafe {
|
unsafe {
|
||||||
let max_threads = rt::rust_sched_threads();
|
let max_threads = rt::rust_sched_threads();
|
||||||
assert(max_threads as int == 2);
|
assert(max_threads as int == 2);
|
||||||
|
@ -1206,7 +1202,7 @@ fn test_spawn_thread_on_demand() {
|
||||||
|
|
||||||
let (port2, chan2) = pipes::stream();
|
let (port2, chan2) = pipes::stream();
|
||||||
|
|
||||||
do spawn_sched(CurrentScheduler) |move chan2| {
|
do spawn_sched(CurrentScheduler) || {
|
||||||
chan2.send(());
|
chan2.send(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ use uint;
|
||||||
use util;
|
use util;
|
||||||
|
|
||||||
macro_rules! move_it (
|
macro_rules! move_it (
|
||||||
{ $x:expr } => ( unsafe { let y = move *ptr::addr_of(&($x)); move y } )
|
{ $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskSet = LinearSet<*rust_task>;
|
type TaskSet = LinearSet<*rust_task>;
|
||||||
|
@ -195,10 +195,10 @@ fn each_ancestor(list: &mut AncestorList,
|
||||||
if coalesce_this.is_some() {
|
if coalesce_this.is_some() {
|
||||||
// Needed coalesce. Our next ancestor becomes our old
|
// Needed coalesce. Our next ancestor becomes our old
|
||||||
// ancestor's next ancestor. ("next = old_next->next;")
|
// ancestor's next ancestor. ("next = old_next->next;")
|
||||||
*list = move option::unwrap(move coalesce_this);
|
*list = option::unwrap(coalesce_this);
|
||||||
} else {
|
} else {
|
||||||
// No coalesce; restore from tmp. ("next = old_next;")
|
// No coalesce; restore from tmp. ("next = old_next;")
|
||||||
*list = move tmp_list;
|
*list = tmp_list;
|
||||||
}
|
}
|
||||||
return early_break;
|
return early_break;
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ fn each_ancestor(list: &mut AncestorList,
|
||||||
// Swap the list out here; the caller replaces us with it.
|
// Swap the list out here; the caller replaces us with it.
|
||||||
let rest = util::replace(&mut nobe.ancestors,
|
let rest = util::replace(&mut nobe.ancestors,
|
||||||
AncestorList(None));
|
AncestorList(None));
|
||||||
(Some(move rest), need_unwind)
|
(Some(rest), need_unwind)
|
||||||
} else {
|
} else {
|
||||||
(None, need_unwind)
|
(None, need_unwind)
|
||||||
}
|
}
|
||||||
|
@ -292,8 +292,8 @@ fn each_ancestor(list: &mut AncestorList,
|
||||||
// If this trips, more likely the problem is 'blk' failed inside.
|
// If this trips, more likely the problem is 'blk' failed inside.
|
||||||
let tmp_arc = option::swap_unwrap(&mut *parent_group);
|
let tmp_arc = option::swap_unwrap(&mut *parent_group);
|
||||||
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
|
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
|
||||||
*parent_group = move Some(move tmp_arc);
|
*parent_group = Some(tmp_arc);
|
||||||
move result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,15 +337,15 @@ struct TCB {
|
||||||
fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
|
fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
|
||||||
is_main: bool, notifier: Option<AutoNotify>) -> TCB {
|
is_main: bool, notifier: Option<AutoNotify>) -> TCB {
|
||||||
|
|
||||||
let notifier = move notifier;
|
let notifier = notifier;
|
||||||
notifier.iter(|x| { x.failed = false; });
|
notifier.iter(|x| { x.failed = false; });
|
||||||
|
|
||||||
TCB {
|
TCB {
|
||||||
me: me,
|
me: me,
|
||||||
tasks: move tasks,
|
tasks: tasks,
|
||||||
ancestors: move ancestors,
|
ancestors: ancestors,
|
||||||
is_main: is_main,
|
is_main: is_main,
|
||||||
notifier: move notifier
|
notifier: notifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ struct AutoNotify {
|
||||||
|
|
||||||
fn AutoNotify(chan: Chan<TaskResult>) -> AutoNotify {
|
fn AutoNotify(chan: Chan<TaskResult>) -> AutoNotify {
|
||||||
AutoNotify {
|
AutoNotify {
|
||||||
notify_chan: move chan,
|
notify_chan: chan,
|
||||||
failed: true // Un-set above when taskgroup successfully made.
|
failed: true // Un-set above when taskgroup successfully made.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,10 +370,10 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
|
||||||
let newstate = util::replace(&mut *state, None);
|
let newstate = util::replace(&mut *state, None);
|
||||||
// If 'None', the group was failing. Can't enlist.
|
// If 'None', the group was failing. Can't enlist.
|
||||||
if newstate.is_some() {
|
if newstate.is_some() {
|
||||||
let group = option::unwrap(move newstate);
|
let group = option::unwrap(newstate);
|
||||||
taskset_insert(if is_member { &mut group.members }
|
taskset_insert(if is_member { &mut group.members }
|
||||||
else { &mut group.descendants }, me);
|
else { &mut group.descendants }, me);
|
||||||
*state = Some(move group);
|
*state = Some(group);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -386,10 +386,10 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task,
|
||||||
let newstate = util::replace(&mut *state, None);
|
let newstate = util::replace(&mut *state, None);
|
||||||
// If 'None', already failing and we've already gotten a kill signal.
|
// If 'None', already failing and we've already gotten a kill signal.
|
||||||
if newstate.is_some() {
|
if newstate.is_some() {
|
||||||
let group = option::unwrap(move newstate);
|
let group = option::unwrap(newstate);
|
||||||
taskset_remove(if is_member { &mut group.members }
|
taskset_remove(if is_member { &mut group.members }
|
||||||
else { &mut group.descendants }, me);
|
else { &mut group.descendants }, me);
|
||||||
*state = Some(move group);
|
*state = Some(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
|
||||||
// That's ok; only one task needs to do the dirty work. (Might also
|
// That's ok; only one task needs to do the dirty work. (Might also
|
||||||
// see 'None' if Somebody already failed and we got a kill signal.)
|
// see 'None' if Somebody already failed and we got a kill signal.)
|
||||||
if newstate.is_some() {
|
if newstate.is_some() {
|
||||||
let group = option::unwrap(move newstate);
|
let group = option::unwrap(newstate);
|
||||||
for taskset_each(&group.members) |sibling| {
|
for taskset_each(&group.members) |sibling| {
|
||||||
// Skip self - killing ourself won't do much good.
|
// Skip self - killing ourself won't do much good.
|
||||||
if sibling != me {
|
if sibling != me {
|
||||||
|
@ -457,7 +457,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||||
}));
|
}));
|
||||||
// Main task/group has no ancestors, no notifier, etc.
|
// Main task/group has no ancestors, no notifier, etc.
|
||||||
let group =
|
let group =
|
||||||
@TCB(spawner, move tasks, AncestorList(None), true, None);
|
@TCB(spawner, tasks, AncestorList(None), true, None);
|
||||||
local_set(spawner, taskgroup_key!(), group);
|
local_set(spawner, taskgroup_key!(), group);
|
||||||
group
|
group
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||||
// Child's ancestors are spawner's ancestors.
|
// Child's ancestors are spawner's ancestors.
|
||||||
let a = share_ancestors(&mut spawner_group.ancestors);
|
let a = share_ancestors(&mut spawner_group.ancestors);
|
||||||
// Propagate main-ness.
|
// Propagate main-ness.
|
||||||
(move g, move a, spawner_group.is_main)
|
(g, a, spawner_group.is_main)
|
||||||
} else {
|
} else {
|
||||||
// Child is in a separate group from spawner.
|
// Child is in a separate group from spawner.
|
||||||
let g = private::exclusive(Some(TaskGroupData {
|
let g = private::exclusive(Some(TaskGroupData {
|
||||||
|
@ -504,7 +504,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||||
// Child has no ancestors.
|
// Child has no ancestors.
|
||||||
AncestorList(None)
|
AncestorList(None)
|
||||||
};
|
};
|
||||||
(move g, move a, false)
|
(g, a, false)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,10 +515,10 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||||
// None { ancestor_list(None) }
|
// None { ancestor_list(None) }
|
||||||
let tmp = util::replace(&mut **ancestors, None);
|
let tmp = util::replace(&mut **ancestors, None);
|
||||||
if tmp.is_some() {
|
if tmp.is_some() {
|
||||||
let ancestor_arc = option::unwrap(move tmp);
|
let ancestor_arc = option::unwrap(tmp);
|
||||||
let result = ancestor_arc.clone();
|
let result = ancestor_arc.clone();
|
||||||
**ancestors = move Some(move ancestor_arc);
|
**ancestors = Some(ancestor_arc);
|
||||||
AncestorList(Some(move result))
|
AncestorList(Some(result))
|
||||||
} else {
|
} else {
|
||||||
AncestorList(None)
|
AncestorList(None)
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
|
||||||
gen_child_taskgroup(opts.linked, opts.supervised);
|
gen_child_taskgroup(opts.linked, opts.supervised);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let child_data = ~mut Some((move child_tg, move ancestors, move f));
|
let child_data = ~mut Some((child_tg, ancestors, f));
|
||||||
// Being killed with the unsafe task/closure pointers would leak them.
|
// Being killed with the unsafe task/closure pointers would leak them.
|
||||||
do unkillable {
|
do unkillable {
|
||||||
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
||||||
|
@ -548,8 +548,8 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
|
||||||
Some(option::swap_unwrap(&mut opts.notify_chan))
|
Some(option::swap_unwrap(&mut opts.notify_chan))
|
||||||
};
|
};
|
||||||
|
|
||||||
let child_wrapper = make_child_wrapper(new_task, move child_tg,
|
let child_wrapper = make_child_wrapper(new_task, child_tg,
|
||||||
move ancestors, is_main, move notify_chan, move f);
|
ancestors, is_main, notify_chan, f);
|
||||||
|
|
||||||
let closure = cast::transmute(&child_wrapper);
|
let closure = cast::transmute(&child_wrapper);
|
||||||
|
|
||||||
|
@ -557,7 +557,7 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
|
||||||
// closure. (Reordering them wouldn't help - then getting killed
|
// closure. (Reordering them wouldn't help - then getting killed
|
||||||
// between them would leak.)
|
// between them would leak.)
|
||||||
rt::start_task(new_task, closure);
|
rt::start_task(new_task, closure);
|
||||||
cast::forget(move child_wrapper);
|
cast::forget(child_wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,8 +571,8 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
|
||||||
ancestors: AncestorList, is_main: bool,
|
ancestors: AncestorList, is_main: bool,
|
||||||
notify_chan: Option<Chan<TaskResult>>,
|
notify_chan: Option<Chan<TaskResult>>,
|
||||||
f: fn~()) -> fn~() {
|
f: fn~()) -> fn~() {
|
||||||
let child_data = ~mut Some((move child_arc, move ancestors));
|
let child_data = ~mut Some((child_arc, ancestors));
|
||||||
return fn~(move notify_chan, move child_data, move f) {
|
return fn~() {
|
||||||
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
||||||
let mut (child_arc, ancestors) = option::swap_unwrap(child_data);
|
let mut (child_arc, ancestors) = option::swap_unwrap(child_data);
|
||||||
// Child task runs this code.
|
// Child task runs this code.
|
||||||
|
@ -584,14 +584,14 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
|
||||||
let notifier = match notify_chan {
|
let notifier = match notify_chan {
|
||||||
Some(ref notify_chan_value) => {
|
Some(ref notify_chan_value) => {
|
||||||
let moved_ncv = move_it!(*notify_chan_value);
|
let moved_ncv = move_it!(*notify_chan_value);
|
||||||
Some(AutoNotify(move moved_ncv))
|
Some(AutoNotify(moved_ncv))
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
};
|
};
|
||||||
|
|
||||||
if enlist_many(child, &child_arc, &mut ancestors) {
|
if enlist_many(child, &child_arc, &mut ancestors) {
|
||||||
let group = @TCB(child, move child_arc, move ancestors,
|
let group = @TCB(child, child_arc, ancestors,
|
||||||
is_main, move notifier);
|
is_main, notifier);
|
||||||
unsafe {
|
unsafe {
|
||||||
local_set(child, taskgroup_key!(), group);
|
local_set(child, taskgroup_key!(), group);
|
||||||
}
|
}
|
||||||
|
@ -694,7 +694,7 @@ fn test_spawn_raw_unsupervise() {
|
||||||
notify_chan: None,
|
notify_chan: None,
|
||||||
.. default_task_opts()
|
.. default_task_opts()
|
||||||
};
|
};
|
||||||
do spawn_raw(move opts) {
|
do spawn_raw(opts) {
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,7 @@ fn test_spawn_raw_notify_success() {
|
||||||
notify_chan: Some(notify_ch),
|
notify_chan: Some(notify_ch),
|
||||||
.. default_task_opts()
|
.. default_task_opts()
|
||||||
};
|
};
|
||||||
do spawn_raw(move opts) {
|
do spawn_raw(opts) {
|
||||||
}
|
}
|
||||||
assert notify_po.recv() == Success;
|
assert notify_po.recv() == Success;
|
||||||
}
|
}
|
||||||
|
@ -724,7 +724,7 @@ fn test_spawn_raw_notify_failure() {
|
||||||
notify_chan: Some(notify_ch),
|
notify_chan: Some(notify_ch),
|
||||||
.. default_task_opts()
|
.. default_task_opts()
|
||||||
};
|
};
|
||||||
do spawn_raw(move opts) {
|
do spawn_raw(opts) {
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
assert notify_po.recv() == Failure;
|
assert notify_po.recv() == Failure;
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl<A: ToStr> ToStr for ~[A] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str::push_char(&mut acc, ']');
|
str::push_char(&mut acc, ']');
|
||||||
move acc
|
acc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use prelude::*;
|
||||||
|
|
||||||
/// The identity function.
|
/// The identity function.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn id<T>(x: T) -> T { move x }
|
pub pure fn id<T>(x: T) -> T { x }
|
||||||
|
|
||||||
/// Ignores a value.
|
/// Ignores a value.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -37,10 +37,10 @@ pub fn with<T: Copy, R>(
|
||||||
// we wouldn't need to copy...
|
// we wouldn't need to copy...
|
||||||
|
|
||||||
let old_value = *ptr;
|
let old_value = *ptr;
|
||||||
*ptr = move new_value;
|
*ptr = new_value;
|
||||||
let result = op();
|
let result = op();
|
||||||
*ptr = move old_value;
|
*ptr = old_value;
|
||||||
return move result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,9 +58,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn replace<T>(dest: &mut T, src: T) -> T {
|
pub fn replace<T>(dest: &mut T, src: T) -> T {
|
||||||
let mut tmp = move src;
|
let mut tmp = src;
|
||||||
swap(dest, &mut tmp);
|
swap(dest, &mut tmp);
|
||||||
move tmp
|
tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A non-copyable dummy type.
|
/// A non-copyable dummy type.
|
||||||
|
@ -109,7 +109,7 @@ mod tests {
|
||||||
let x = ~[(5, false)];
|
let x = ~[(5, false)];
|
||||||
//FIXME #3387 assert x.eq(id(copy x));
|
//FIXME #3387 assert x.eq(id(copy x));
|
||||||
let y = copy x;
|
let y = copy x;
|
||||||
assert x.eq(&id(move y));
|
assert x.eq(&id(y));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_swap() {
|
pub fn test_swap() {
|
||||||
|
|
|
@ -614,7 +614,7 @@ unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
|
||||||
(**repr).unboxed.fill += sys::nonzero_size_of::<T>();
|
(**repr).unboxed.fill += sys::nonzero_size_of::<T>();
|
||||||
let p = addr_of(&((**repr).unboxed.data));
|
let p = addr_of(&((**repr).unboxed.data));
|
||||||
let p = ptr::offset(p, fill) as *mut T;
|
let p = ptr::offset(p, fill) as *mut T;
|
||||||
rusti::move_val_init(&mut(*p), move initval);
|
rusti::move_val_init(&mut(*p), initval);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue