blob: d31dc6b7634e4cf277e25354455095cedc5d561e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// expect: 0 2 2 2 0/
// destructors 6.15.3: two unreachable values with drops that reach each other are both finalized in one collection (each is in a cycle, so nothing outside it drops first), each exactly once, then freed
include rt;
int n;
word g;
struct node { node* other; int v; void drop() { n++; } }
unchecked fn make() {
node* a = rt.new(node); node* b = rt.new(node);
a.v = 1; b.v = 2; a.other = b; b.other = a;
g = a;
return 0;
}
fn main() {
make();
rt.gc(); rt.put_n(n); rt.put_c(32);
g = 0;
rt.gc(); rt.put_n(n); rt.put_c(32);
rt.gc(); rt.put_n(n); rt.put_c(32);
rt.gc(); rt.gc(); rt.put_n(n); rt.put_c(32);
rt.put_n(rt.dcount); rt.put_c(10); // both entries are gone with their blocks
return 0;
}
// zc0: skip
|