Skip to content

Commit 29840ad

Browse files
committed
remove the concept of managed-unique from libstd
Closes #11545
1 parent 197fe67 commit 29840ad

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

Diff for: src/libstd/cleanup.rs

+16-28
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use unstable::raw;
1717

1818
type DropGlue<'a> = 'a |**TyDesc, *c_void|;
1919

20+
static RC_IMMORTAL : uint = 0x77777777;
21+
2022
/*
2123
* Box annihilation
2224
*
@@ -25,24 +27,21 @@ type DropGlue<'a> = 'a |**TyDesc, *c_void|;
2527

2628
struct AnnihilateStats {
2729
n_total_boxes: uint,
28-
n_unique_boxes: uint,
2930
n_bytes_freed: uint
3031
}
3132

3233
unsafe fn each_live_alloc(read_next_before: bool,
33-
f: |alloc: *mut raw::Box<()>, uniq: bool| -> bool)
34+
f: |alloc: *mut raw::Box<()>| -> bool)
3435
-> bool {
3536
//! Walks the internal list of allocations
3637
37-
use managed;
3838
use rt::local_heap;
3939

4040
let mut alloc = local_heap::live_allocs();
4141
while alloc != ptr::mut_null() {
4242
let next_before = (*alloc).next;
43-
let uniq = (*alloc).ref_count == managed::RC_MANAGED_UNIQUE;
4443

45-
if !f(alloc, uniq) {
44+
if !f(alloc) {
4645
return false;
4746
}
4847

@@ -70,25 +69,19 @@ fn debug_mem() -> bool {
7069
pub unsafe fn annihilate() {
7170
use rt::local_heap::local_free;
7271
use mem;
73-
use managed;
7472

7573
let mut stats = AnnihilateStats {
7674
n_total_boxes: 0,
77-
n_unique_boxes: 0,
7875
n_bytes_freed: 0
7976
};
8077

8178
// Pass 1: Make all boxes immortal.
8279
//
8380
// In this pass, nothing gets freed, so it does not matter whether
8481
// we read the next field before or after the callback.
85-
each_live_alloc(true, |alloc, uniq| {
82+
each_live_alloc(true, |alloc| {
8683
stats.n_total_boxes += 1;
87-
if uniq {
88-
stats.n_unique_boxes += 1;
89-
} else {
90-
(*alloc).ref_count = managed::RC_IMMORTAL;
91-
}
84+
(*alloc).ref_count = RC_IMMORTAL;
9285
true
9386
});
9487

@@ -97,12 +90,10 @@ pub unsafe fn annihilate() {
9790
// In this pass, unique-managed boxes may get freed, but not
9891
// managed boxes, so we must read the `next` field *after* the
9992
// callback, as the original value may have been freed.
100-
each_live_alloc(false, |alloc, uniq| {
101-
if !uniq {
102-
let tydesc = (*alloc).type_desc;
103-
let data = &(*alloc).data as *();
104-
((*tydesc).drop_glue)(data as *i8);
105-
}
93+
each_live_alloc(false, |alloc| {
94+
let tydesc = (*alloc).type_desc;
95+
let data = &(*alloc).data as *();
96+
((*tydesc).drop_glue)(data as *i8);
10697
true
10798
});
10899

@@ -112,22 +103,19 @@ pub unsafe fn annihilate() {
112103
// unique-managed boxes, though I think that none of those are
113104
// left), so we must read the `next` field before, since it will
114105
// not be valid after.
115-
each_live_alloc(true, |alloc, uniq| {
116-
if !uniq {
117-
stats.n_bytes_freed +=
118-
(*((*alloc).type_desc)).size
119-
+ mem::size_of::<raw::Box<()>>();
120-
local_free(alloc as *i8);
121-
}
106+
each_live_alloc(true, |alloc| {
107+
stats.n_bytes_freed +=
108+
(*((*alloc).type_desc)).size
109+
+ mem::size_of::<raw::Box<()>>();
110+
local_free(alloc as *i8);
122111
true
123112
});
124113

125114
if debug_mem() {
126115
// We do logging here w/o allocation.
127116
debug!("annihilator stats:\n \
128117
total boxes: {}\n \
129-
unique boxes: {}\n \
130118
bytes freed: {}",
131-
stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed);
119+
stats.n_total_boxes, stats.n_bytes_freed);
132120
}
133121
}

Diff for: src/libstd/managed.rs

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use ptr::to_unsafe_ptr;
1414

1515
#[cfg(not(test))] use cmp::*;
1616

17-
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
18-
pub static RC_IMMORTAL : uint = 0x77777777;
19-
2017
/// Returns the refcount of a shared box (as just before calling this)
2118
#[inline]
2219
pub fn refcount<T>(t: @T) -> uint {

0 commit comments

Comments
 (0)