Skip to content

Commit bf92940

Browse files
committed
More test cases for classes with dtors
Tests that classes with dtors and multiple fields work correctly. Closes #2708
1 parent 487cbf8 commit bf92940

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/test/run-pass/issue-2708.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Font {
2+
let fontbuf: uint;
3+
let cairo_font: uint;
4+
let font_dtor: uint;
5+
6+
new() {
7+
self.fontbuf = 0;
8+
self.cairo_font = 0;
9+
self.font_dtor = 0;
10+
}
11+
12+
drop { }
13+
}
14+
15+
fn main() {
16+
let _f = @Font();
17+
}

src/test/run-pass/resource-cycle3.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// same as resource-cycle2, but be sure to give r multiple fields...
2+
3+
// Don't leak the unique pointers
4+
5+
type u = {
6+
a: int,
7+
b: int,
8+
c: *int
9+
};
10+
11+
class r {
12+
let v: u;
13+
let w: int;
14+
let x: *int;
15+
new(v: u, w: int, _x: *int) unsafe { self.v = v; self.w = w;
16+
self.x = unsafe::reinterpret_cast(0);
17+
/* self.x = x; */ }
18+
drop unsafe {
19+
let _v2: ~int = unsafe::reinterpret_cast(self.v.c);
20+
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
21+
}
22+
}
23+
24+
enum t = {
25+
mut next: option<@t>,
26+
r: r
27+
};
28+
29+
fn main() unsafe {
30+
let i1 = ~0xA;
31+
let i1p = unsafe::reinterpret_cast(i1);
32+
unsafe::forget(i1);
33+
let i2 = ~0xA;
34+
let i2p = unsafe::reinterpret_cast(i2);
35+
unsafe::forget(i2);
36+
37+
let u1 = {a: 0xB, b: 0xC, c: i1p};
38+
let u2 = {a: 0xB, b: 0xC, c: i2p};
39+
40+
let x1 = @t({
41+
mut next: none,
42+
r: r(u1, 42, i1p)
43+
});
44+
let x2 = @t({
45+
mut next: none,
46+
r: r(u2, 42, i2p)
47+
});
48+
x1.next = some(x2);
49+
x2.next = some(x1);
50+
}

0 commit comments

Comments
 (0)