Skip to content

Commit ce77335

Browse files
committed
rustc: Make the box annihilator a language item
1 parent c7e5c87 commit ce77335

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/libcore/cleanup.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use rt::rt_free;
55
use sys::TypeDesc;
66
use unsafe::transmute;
77

8+
export annihilate;
9+
810
/**
911
* Runtime structures
1012
*
@@ -65,8 +67,7 @@ struct Task {
6567
* This runs at task death to free all boxes.
6668
*/
6769

68-
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
69-
pub unsafe fn annihilate() {
70+
unsafe fn do_annihilate() {
7071
let task: *Task = transmute(rustrt::rust_get_task());
7172

7273
// Pass 1: Make all boxes immortal.
@@ -104,6 +105,18 @@ pub unsafe fn annihilate() {
104105
}
105106
}
106107

108+
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
109+
#[cfg(notest)]
110+
#[lang="annihilate"]
111+
pub unsafe fn annihilate() {
112+
do_annihilate();
113+
}
114+
115+
#[cfg(test)]
116+
pub unsafe fn annihilate() {
117+
do_annihilate();
118+
}
119+
107120
/// Bindings to the runtime
108121
extern mod rustrt {
109122
#[rust_stack]
@@ -116,7 +129,7 @@ extern mod rustrt {
116129

117130
#[cfg(test)]
118131
mod tests {
119-
/*struct Knot {
132+
struct Knot {
120133
mut a: Option<@Knot>
121134
}
122135

@@ -147,6 +160,6 @@ mod tests {
147160
unsafe::forget(f_ref);
148161
unsafe::forget(f);
149162
}
150-
}*/
163+
}
151164
}
152165

src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export flate;
6262
export unit;
6363
export uniq;
6464
export repr;
65+
export cleanup;
6566

6667
// NDM seems to be necessary for resolve to work
6768
export option_iter;
@@ -228,6 +229,7 @@ mod unsafe;
228229
mod mutable;
229230
mod flate;
230231
mod repr;
232+
mod cleanup;
231233

232234
// Modules supporting compiler-generated code
233235
// Exported but not part of the public interface
@@ -244,7 +246,6 @@ mod unicode;
244246
mod private;
245247
mod cmath;
246248
mod stackwalk;
247-
mod cleanup;
248249

249250
// Local Variables:
250251
// mode: rust;

src/rustc/middle/lang_items.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ struct LanguageItems {
4545
mut ord_trait: Option<def_id>,
4646

4747
mut str_eq_fn: Option<def_id>,
48-
mut uniq_str_eq_fn: Option<def_id>
48+
mut uniq_str_eq_fn: Option<def_id>,
49+
mut annihilate_fn: Option<def_id>
4950
}
5051

5152
mod LanguageItems {
@@ -73,7 +74,8 @@ mod LanguageItems {
7374
ord_trait: None,
7475

7576
str_eq_fn: None,
76-
uniq_str_eq_fn: None
77+
uniq_str_eq_fn: None,
78+
annihilate_fn: None
7779
}
7880
}
7981
}
@@ -107,6 +109,7 @@ fn LanguageItemCollector(crate: @crate, session: session,
107109

108110
item_refs.insert(~"str_eq", &mut items.str_eq_fn);
109111
item_refs.insert(~"uniq_str_eq", &mut items.uniq_str_eq_fn);
112+
item_refs.insert(~"annihilate", &mut items.annihilate_fn);
110113

111114
LanguageItemCollector {
112115
crate: crate,

0 commit comments

Comments
 (0)