rustc: Make the box annihilator a language item

This commit is contained in:
Patrick Walton 2012-09-14 16:49:23 -07:00
parent c7e5c870f3
commit ce773352d0
3 changed files with 24 additions and 7 deletions

View File

@ -5,6 +5,8 @@ use rt::rt_free;
use sys::TypeDesc;
use unsafe::transmute;
export annihilate;
/**
* Runtime structures
*
@ -65,8 +67,7 @@ struct Task {
* This runs at task death to free all boxes.
*/
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
pub unsafe fn annihilate() {
unsafe fn do_annihilate() {
let task: *Task = transmute(rustrt::rust_get_task());
// Pass 1: Make all boxes immortal.
@ -104,6 +105,18 @@ pub unsafe fn annihilate() {
}
}
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
#[cfg(notest)]
#[lang="annihilate"]
pub unsafe fn annihilate() {
do_annihilate();
}
#[cfg(test)]
pub unsafe fn annihilate() {
do_annihilate();
}
/// Bindings to the runtime
extern mod rustrt {
#[rust_stack]
@ -116,7 +129,7 @@ extern mod rustrt {
#[cfg(test)]
mod tests {
/*struct Knot {
struct Knot {
mut a: Option<@Knot>
}
@ -147,6 +160,6 @@ mod tests {
unsafe::forget(f_ref);
unsafe::forget(f);
}
}*/
}
}

View File

@ -62,6 +62,7 @@ export flate;
export unit;
export uniq;
export repr;
export cleanup;
// NDM seems to be necessary for resolve to work
export option_iter;
@ -228,6 +229,7 @@ mod unsafe;
mod mutable;
mod flate;
mod repr;
mod cleanup;
// Modules supporting compiler-generated code
// Exported but not part of the public interface
@ -244,7 +246,6 @@ mod unicode;
mod private;
mod cmath;
mod stackwalk;
mod cleanup;
// Local Variables:
// mode: rust;

View File

@ -45,7 +45,8 @@ struct LanguageItems {
mut ord_trait: Option<def_id>,
mut str_eq_fn: Option<def_id>,
mut uniq_str_eq_fn: Option<def_id>
mut uniq_str_eq_fn: Option<def_id>,
mut annihilate_fn: Option<def_id>
}
mod LanguageItems {
@ -73,7 +74,8 @@ mod LanguageItems {
ord_trait: None,
str_eq_fn: None,
uniq_str_eq_fn: None
uniq_str_eq_fn: None,
annihilate_fn: None
}
}
}
@ -107,6 +109,7 @@ fn LanguageItemCollector(crate: @crate, session: session,
item_refs.insert(~"str_eq", &mut items.str_eq_fn);
item_refs.insert(~"uniq_str_eq", &mut items.uniq_str_eq_fn);
item_refs.insert(~"annihilate", &mut items.annihilate_fn);
LanguageItemCollector {
crate: crate,