Port more test cases to use classes instead of resources

This commit is contained in:
Tim Chevalier 2012-06-01 14:48:02 -07:00
parent bc5cb4deb3
commit 10c141a232
7 changed files with 47 additions and 23 deletions

View file

@ -1,9 +1,14 @@
// Ensures that putting resources inside structual types keeps
// working.
// Ensures that class dtors run if the object is inside an enum
// variant
type closable = @mut bool;
resource close_res(i: closable) { *i = false; }
class close_res {
let i: closable;
new(i: closable) { self.i = i; }
drop { *(self.i) = false; }
}
enum option<T> { none, some(T), }

View file

@ -1,8 +1,10 @@
import task::*;
import comm::*;
resource test(_f: int) {
// Do nothing
class test {
let f: int;
new(f: int) { self.f = f; }
drop {}
}
fn main() {

View file

@ -1,21 +1,22 @@
// xfail-test
// A port of task-killjoin to use a resource to manage
// A port of task-killjoin to use a class with a dtor to manage
// the join.
use std;
import task;
fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
resource notify(data: (comm::chan<bool>,
@mut bool)) {
let (c, v) = data;
#error["notify: task=%d v=%x unwinding=%b b=%b",
class notify {
let ch: comm::chan<bool>; let v: @mut bool;
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
drop {
#error["notify: task=%d v=%x unwinding=%b b=%b",
task::get_task(),
ptr::addr_of(*v) as uint,
task::currently_unwinding(),
*v];
comm::send(c, *v);
ptr::addr_of(*(self.v)) as uint,
task::failing(),
*(self.v)];
comm::send(self.ch, *(self.v));
}
}
fn wrapper(pair: (comm::chan<bool>, fn())) {
let (c, f) = pair;
@ -23,7 +24,7 @@ fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
#error["wrapper: task=%d allocated v=%x",
task::get_task(),
ptr::addr_of(*b) as uint];
let _r = notify((c, b));
let _r = notify(c, b);
f();
*b = true;
}

View file

@ -2,7 +2,11 @@ fn p_foo<T>(pinned: T) { }
fn s_foo<T: copy>(shared: T) { }
fn u_foo<T: send>(unique: T) { }
resource r(i: int) { }
class r {
let i: int;
new(i:int) { self.i = i; }
drop {}
}
fn main() {
p_foo(r(10));

View file

@ -1,5 +1,7 @@
resource r(i: @mut int) {
*i = *i + 1;
class r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
fn main() {

View file

@ -3,12 +3,18 @@ use std;
import task;
import comm;
resource complainer(c: comm::chan<bool>) {
comm::send(c, true);
class complainer {
let c: comm::chan<bool>;
new(c: comm::chan<bool>) {
#error("Hello!");
self.c = c; }
drop { #error("About to send!");
comm::send(self.c, true);
#error("Sent!"); }
}
fn f(c: comm::chan<bool>) {
let c <- complainer(c);
let _c <- complainer(c);
fail;
}
@ -18,5 +24,6 @@ fn main() {
let builder = task::builder();
task::unsupervise(builder);
task::run(builder) {|| f(c); }
#error("hiiiiiiiii");
assert comm::recv(p);
}

View file

@ -3,7 +3,10 @@ use std;
import task;
import comm;
resource complainer(c: @int) {
class complainer {
let c: @int;
new(c: @int) { self.c = c; }
drop {}
}
fn f() {