Skip to content

std: Remove some @-boxes #11082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions src/libstd/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,56 +353,56 @@ mod tests {

#[test]
fn test_tls_multitask() {
static my_key: Key<@~str> = &Key;
set(my_key, @~"parent data");
static my_key: Key<~str> = &Key;
set(my_key, ~"parent data");
do task::spawn {
// TLS shouldn't carry over.
assert!(get(my_key, |k| k.map(|k| *k)).is_none());
set(my_key, @~"child data");
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) ==
assert!(get(my_key, |k| k.map(|k| (*k).clone())).is_none());
set(my_key, ~"child data");
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() ==
~"child data");
// should be cleaned up for us
}
// Must work multiple times
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
}

#[test]
fn test_tls_overwrite() {
static my_key: Key<@~str> = &Key;
set(my_key, @~"first data");
set(my_key, @~"next data"); // Shouldn't leak.
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"next data");
static my_key: Key<~str> = &Key;
set(my_key, ~"first data");
set(my_key, ~"next data"); // Shouldn't leak.
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"next data");
}

#[test]
fn test_tls_pop() {
static my_key: Key<@~str> = &Key;
set(my_key, @~"weasel");
assert!(*(pop(my_key).unwrap()) == ~"weasel");
static my_key: Key<~str> = &Key;
set(my_key, ~"weasel");
assert!(pop(my_key).unwrap() == ~"weasel");
// Pop must remove the data from the map.
assert!(pop(my_key).is_none());
}

#[test]
fn test_tls_modify() {
static my_key: Key<@~str> = &Key;
static my_key: Key<~str> = &Key;
modify(my_key, |data| {
match data {
Some(@ref val) => fail!("unwelcome value: {}", *val),
None => Some(@~"first data")
Some(ref val) => fail!("unwelcome value: {}", *val),
None => Some(~"first data")
}
});
modify(my_key, |data| {
match data {
Some(@~"first data") => Some(@~"next data"),
Some(@ref val) => fail!("wrong value: {}", *val),
Some(~"first data") => Some(~"next data"),
Some(ref val) => fail!("wrong value: {}", *val),
None => fail!("missing value")
}
});
assert!(*(pop(my_key).unwrap()) == ~"next data");
assert!(pop(my_key).unwrap() == ~"next data");
}

#[test]
Expand All @@ -413,67 +413,67 @@ mod tests {
// to get recorded as something within a rust stack segment. Then a
// subsequent upcall (esp. for logging, think vsnprintf) would run on
// a stack smaller than 1 MB.
static my_key: Key<@~str> = &Key;
static my_key: Key<~str> = &Key;
do task::spawn {
set(my_key, @~"hax");
set(my_key, ~"hax");
}
}

#[test]
fn test_tls_multiple_types() {
static str_key: Key<@~str> = &Key;
static box_key: Key<@@()> = &Key;
static int_key: Key<@int> = &Key;
static str_key: Key<~str> = &Key;
static box_key: Key<@()> = &Key;
static int_key: Key<int> = &Key;
do task::spawn {
set(str_key, @~"string data");
set(box_key, @@());
set(int_key, @42);
set(str_key, ~"string data");
set(box_key, @());
set(int_key, 42);
}
}

#[test]
fn test_tls_overwrite_multiple_types() {
static str_key: Key<@~str> = &Key;
static box_key: Key<@@()> = &Key;
static int_key: Key<@int> = &Key;
static str_key: Key<~str> = &Key;
static box_key: Key<@()> = &Key;
static int_key: Key<int> = &Key;
do task::spawn {
set(str_key, @~"string data");
set(str_key, @~"string data 2");
set(box_key, @@());
set(box_key, @@());
set(int_key, @42);
set(str_key, ~"string data");
set(str_key, ~"string data 2");
set(box_key, @());
set(box_key, @());
set(int_key, 42);
// This could cause a segfault if overwriting-destruction is done
// with the crazy polymorphic transmute rather than the provided
// finaliser.
set(int_key, @31337);
set(int_key, 31337);
}
}

#[test]
#[should_fail]
fn test_tls_cleanup_on_failure() {
static str_key: Key<@~str> = &Key;
static box_key: Key<@@()> = &Key;
static int_key: Key<@int> = &Key;
set(str_key, @~"parent data");
set(box_key, @@());
static str_key: Key<~str> = &Key;
static box_key: Key<@()> = &Key;
static int_key: Key<int> = &Key;
set(str_key, ~"parent data");
set(box_key, @());
do task::spawn {
// spawn_linked
set(str_key, @~"string data");
set(box_key, @@());
set(int_key, @42);
set(str_key, ~"string data");
set(box_key, @());
set(int_key, 42);
fail!();
}
// Not quite nondeterministic.
set(int_key, @31337);
set(int_key, 31337);
fail!();
}

#[test]
fn test_static_pointer() {
static key: Key<@&'static int> = &Key;
static key: Key<&'static int> = &Key;
static VALUE: int = 0;
let v: @&'static int = @&VALUE;
let v: &'static int = &VALUE;
set(key, v);
}

Expand Down
18 changes: 12 additions & 6 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,28 +445,34 @@ mod tests {

#[test]
fn test_get_resource() {
use rc::Rc;
use cell::RefCell;

struct R {
i: @mut int,
i: Rc<RefCell<int>>,
}

#[unsafe_destructor]
impl ::ops::Drop for R {
fn drop(&mut self) { *(self.i) += 1; }
fn drop(&mut self) {
let ii = self.i.borrow();
ii.set(ii.get() + 1);
}
}

fn R(i: @mut int) -> R {
fn R(i: Rc<RefCell<int>>) -> R {
R {
i: i
}
}

let i = @mut 0;
let i = Rc::from_send(RefCell::new(0));
{
let x = R(i);
let x = R(i.clone());
let opt = Some(x);
let _y = opt.unwrap();
}
assert_eq!(*i, 1);
assert_eq!(i.borrow().get(), 1);
}

#[test]
Expand Down
49 changes: 28 additions & 21 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3064,7 +3064,7 @@ mod tests {

#[test]
fn test_truncate() {
let mut v = ~[@6,@5,@4];
let mut v = ~[~6,~5,~4];
v.truncate(1);
assert_eq!(v.len(), 1);
assert_eq!(*(v[0]), 6);
Expand All @@ -3073,7 +3073,7 @@ mod tests {

#[test]
fn test_clear() {
let mut v = ~[@6,@5,@4];
let mut v = ~[~6,~5,~4];
v.clear();
assert_eq!(v.len(), 0);
// If the unsafe block didn't drop things properly, we blow up here.
Expand Down Expand Up @@ -3112,14 +3112,14 @@ mod tests {

#[test]
fn test_dedup_shared() {
let mut v0 = ~[@1, @1, @2, @3];
let mut v0 = ~[~1, ~1, ~2, ~3];
v0.dedup();
let mut v1 = ~[@1, @2, @2, @3];
let mut v1 = ~[~1, ~2, ~2, ~3];
v1.dedup();
let mut v2 = ~[@1, @2, @3, @3];
let mut v2 = ~[~1, ~2, ~3, ~3];
v2.dedup();
/*
* If the @pointers were leaked or otherwise misused, valgrind and/or
* If the pointers were leaked or otherwise misused, valgrind and/or
* rustrt should raise errors.
*/
}
Expand Down Expand Up @@ -3446,18 +3446,19 @@ mod tests {
fn test_from_fn_fail() {
from_fn(100, |v| {
if v == 50 { fail!() }
(~0, @0)
~0
});
}

#[test]
#[should_fail]
fn test_from_elem_fail() {
use cast;
use rc::Rc;

struct S {
f: int,
boxes: (~int, @int)
boxes: (~int, Rc<int>)
}

impl Clone for S {
Expand All @@ -3469,66 +3470,71 @@ mod tests {
}
}

let s = S { f: 0, boxes: (~0, @0) };
let s = S { f: 0, boxes: (~0, Rc::new(0)) };
let _ = from_elem(100, s);
}

#[test]
#[should_fail]
fn test_build_fail() {
use rc::Rc;
build(None, |push| {
push((~0, @0));
push((~0, @0));
push((~0, @0));
push((~0, @0));
push((~0, Rc::new(0)));
push((~0, Rc::new(0)));
push((~0, Rc::new(0)));
push((~0, Rc::new(0)));
fail!();
});
}

#[test]
#[should_fail]
fn test_grow_fn_fail() {
use rc::Rc;
let mut v = ~[];
v.grow_fn(100, |i| {
if i == 50 {
fail!()
}
(~0, @0)
(~0, Rc::new(0))
})
}

#[test]
#[should_fail]
fn test_map_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
use rc::Rc;
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
let mut i = 0;
v.map(|_elt| {
if i == 2 {
fail!()
}
i += 1;
~[(~0, @0)]
~[(~0, Rc::new(0))]
});
}

#[test]
#[should_fail]
fn test_flat_map_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
use rc::Rc;
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
let mut i = 0;
flat_map(v, |_elt| {
if i == 2 {
fail!()
}
i += 1;
~[(~0, @0)]
~[(~0, Rc::new(0))]
});
}

#[test]
#[should_fail]
fn test_permute_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
use rc::Rc;
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
let mut i = 0;
for _ in v.permutations() {
if i == 2 {
Expand Down Expand Up @@ -3866,9 +3872,10 @@ mod tests {
#[test]
#[should_fail]
fn test_overflow_does_not_cause_segfault_managed() {
let mut v = ~[@1];
use rc::Rc;
let mut v = ~[Rc::new(1)];
v.reserve(-1);
v.push(@2);
v.push(Rc::new(2));
}

#[test]
Expand Down