Merge remote-tracking branch 'remotes/origin/incoming' into incoming

This commit is contained in:
Erick Tryzelaar 2013-02-28 07:25:49 -08:00
commit d2c4b6492d
34 changed files with 168 additions and 102 deletions

View File

@ -297,7 +297,7 @@ the following forms:
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ? num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
| '0' [ [ dec_digit | '_' ] + num_suffix ? | '0' [ [ dec_digit | '_' ] + num_suffix ?
| 'b' [ '1' | '0' | '_' ] + int_suffix ? | 'b' [ '1' | '0' | '_' ] + int_suffix ?
| 'x' [ hex_digit | '-' ] + int_suffix ? ] ; | 'x' [ hex_digit | '_' ] + int_suffix ? ] ;
num_suffix : int_suffix | float_suffix ; num_suffix : int_suffix | float_suffix ;

View File

@ -154,7 +154,7 @@ fn debug_mem() -> bool {
#[cfg(notest)] #[cfg(notest)]
#[lang="annihilate"] #[lang="annihilate"]
pub unsafe fn annihilate() { pub unsafe fn annihilate() {
use rt::rt_free; use rt::local_free;
use io::WriterUtil; use io::WriterUtil;
use io; use io;
use libc; use libc;
@ -192,7 +192,7 @@ pub unsafe fn annihilate() {
stats.n_bytes_freed += stats.n_bytes_freed +=
(*((*box).header.type_desc)).size (*((*box).header.type_desc)).size
+ sys::size_of::<BoxRepr>(); + sys::size_of::<BoxRepr>();
rt_free(transmute(box)); local_free(transmute(box));
} }
} }

View File

@ -474,7 +474,10 @@ impl<R:Reader,C> Reader for Wrapper<R, C> {
pub struct FILERes { pub struct FILERes {
f: *libc::FILE, f: *libc::FILE,
drop { }
impl Drop for FILERes {
fn finalize(&self) {
unsafe { unsafe {
libc::fclose(self.f); libc::fclose(self.f);
} }
@ -683,7 +686,10 @@ impl Writer for fd_t {
pub struct FdRes { pub struct FdRes {
fd: fd_t, fd: fd_t,
drop { }
impl Drop for FdRes {
fn finalize(&self) {
unsafe { unsafe {
libc::close(self.fd); libc::close(self.fd);
} }

View File

@ -450,7 +450,10 @@ fn test_unwrap_str() {
fn test_unwrap_resource() { fn test_unwrap_resource() {
struct R { struct R {
i: @mut int, i: @mut int,
drop { *(self.i) += 1; } }
impl ::ops::Drop for R {
fn finalize(&self) { *(self.i) += 1; }
} }
fn R(i: @mut int) -> R { fn R(i: @mut int) -> R {

View File

@ -346,7 +346,10 @@ pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> {
struct BufferResource<T> { struct BufferResource<T> {
buffer: ~Buffer<T>, buffer: ~Buffer<T>,
drop { }
impl<T> ::ops::Drop for BufferResource<T> {
fn finalize(&self) {
unsafe { unsafe {
let b = move_it!(self.buffer); let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b); //let p = ptr::addr_of(*b);

View File

@ -126,7 +126,10 @@ struct ArcData<T> {
struct ArcDestruct<T> { struct ArcDestruct<T> {
mut data: *libc::c_void, mut data: *libc::c_void,
drop { }
impl<T> Drop for ArcDestruct<T>{
fn finalize(&self) {
unsafe { unsafe {
if self.data.is_null() { if self.data.is_null() {
return; // Happens when destructing an unwrapper's handle. return; // Happens when destructing an unwrapper's handle.
@ -178,7 +181,10 @@ pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
struct DeathThroes<T> { struct DeathThroes<T> {
mut ptr: Option<~ArcData<T>>, mut ptr: Option<~ArcData<T>>,
mut response: Option<comm::ChanOne<bool>>, mut response: Option<comm::ChanOne<bool>>,
drop { }
impl<T> Drop for DeathThroes<T>{
fn finalize(&self) {
unsafe { unsafe {
let response = option::swap_unwrap(&mut self.response); let response = option::swap_unwrap(&mut self.response);
// In case we get killed early, we need to tell the person who // In case we get killed early, we need to tell the person who
@ -311,7 +317,10 @@ type rust_little_lock = *libc::c_void;
struct LittleLock { struct LittleLock {
l: rust_little_lock, l: rust_little_lock,
drop { }
impl Drop for LittleLock {
fn finalize(&self) {
unsafe { unsafe {
rustrt::rust_destroy_little_lock(self.l); rustrt::rust_destroy_little_lock(self.l);
} }

View File

@ -365,7 +365,10 @@ impl Rng {
struct RandRes { struct RandRes {
rng: *rust_rng, rng: *rust_rng,
drop { }
impl Drop for RandRes {
fn finalize(&self) {
unsafe { unsafe {
rustrt::rand_free(self.rng); rustrt::rand_free(self.rng);
} }

View File

@ -36,60 +36,54 @@ pub extern mod rustrt {
unsafe fn rust_upcall_free(ptr: *c_char); unsafe fn rust_upcall_free(ptr: *c_char);
} }
#[rt(fail_)]
#[lang="fail_"] #[lang="fail_"]
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
sys::begin_unwind_(expr, file, line); sys::begin_unwind_(expr, file, line);
} }
#[rt(fail_bounds_check)]
#[lang="fail_bounds_check"] #[lang="fail_bounds_check"]
pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t, pub unsafe fn fail_bounds_check(file: *c_char, line: size_t,
index: size_t, len: size_t) { index: size_t, len: size_t) {
let msg = fmt!("index out of bounds: the len is %d but the index is %d", let msg = fmt!("index out of bounds: the len is %d but the index is %d",
len as int, index as int); len as int, index as int);
do str::as_buf(msg) |p, _len| { do str::as_buf(msg) |p, _len| {
rt_fail_(p as *c_char, file, line); fail_(p as *c_char, file, line);
} }
} }
pub unsafe fn rt_fail_borrowed() { pub unsafe fn fail_borrowed() {
let msg = "borrowed"; let msg = "borrowed";
do str::as_buf(msg) |msg_p, _| { do str::as_buf(msg) |msg_p, _| {
do str::as_buf("???") |file_p, _| { do str::as_buf("???") |file_p, _| {
rt_fail_(msg_p as *c_char, file_p as *c_char, 0); fail_(msg_p as *c_char, file_p as *c_char, 0);
} }
} }
} }
// FIXME #4942: Make these signatures agree with exchange_alloc's signatures // FIXME #4942: Make these signatures agree with exchange_alloc's signatures
#[rt(exchange_malloc)]
#[lang="exchange_malloc"] #[lang="exchange_malloc"]
pub unsafe fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
transmute(exchange_alloc::malloc(transmute(td), transmute(size))) transmute(exchange_alloc::malloc(transmute(td), transmute(size)))
} }
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a // inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead. // problem occurs, call exit instead.
#[rt(exchange_free)]
#[lang="exchange_free"] #[lang="exchange_free"]
pub unsafe fn rt_exchange_free(ptr: *c_char) { pub unsafe fn exchange_free(ptr: *c_char) {
exchange_alloc::free(transmute(ptr)) exchange_alloc::free(transmute(ptr))
} }
#[rt(malloc)]
#[lang="malloc"] #[lang="malloc"]
pub unsafe fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size); return rustrt::rust_upcall_malloc(td, size);
} }
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a // inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead. // problem occurs, call exit instead.
#[rt(free)]
#[lang="free"] #[lang="free"]
pub unsafe fn rt_free(ptr: *c_char) { pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr); rustrt::rust_upcall_free(ptr);
} }
@ -112,7 +106,7 @@ pub unsafe fn return_to_mut(a: *u8) {
pub unsafe fn check_not_borrowed(a: *u8) { pub unsafe fn check_not_borrowed(a: *u8) {
let a: *mut BoxRepr = transmute(a); let a: *mut BoxRepr = transmute(a);
if ((*a).header.ref_count & FROZEN_BIT) != 0 { if ((*a).header.ref_count & FROZEN_BIT) != 0 {
rt_fail_borrowed(); fail_borrowed();
} }
} }

View File

@ -248,7 +248,10 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
} }
struct ProgRes { struct ProgRes {
r: ProgRepr, r: ProgRepr,
drop { }
impl Drop for ProgRes {
fn finalize(&self) {
unsafe { unsafe {
// FIXME #4943: This is bad. // FIXME #4943: This is bad.
destroy_repr(cast::transmute(&self.r)); destroy_repr(cast::transmute(&self.r));

View File

@ -308,8 +308,11 @@ struct TCB {
mut ancestors: AncestorList, mut ancestors: AncestorList,
is_main: bool, is_main: bool,
notifier: Option<AutoNotify>, notifier: Option<AutoNotify>,
}
impl Drop for TCB {
// Runs on task exit. // Runs on task exit.
drop { fn finalize(&self) {
unsafe { unsafe {
// If we are failing, the whole taskgroup needs to die. // If we are failing, the whole taskgroup needs to die.
if rt::rust_task_is_unwinding(self.me) { if rt::rust_task_is_unwinding(self.me) {
@ -353,7 +356,10 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
struct AutoNotify { struct AutoNotify {
notify_chan: Chan<TaskResult>, notify_chan: Chan<TaskResult>,
mut failed: bool, mut failed: bool,
drop { }
impl Drop for AutoNotify {
fn finalize(&self) {
let result = if self.failed { Failure } else { Success }; let result = if self.failed { Failure } else { Success };
self.notify_chan.send(result); self.notify_chan.send(result);
} }

View File

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
@ -137,15 +137,6 @@ impl<A:ToStr> ToStr for @[A] {
} }
} }
impl<A:ToStr> ToStr for @A {
#[inline(always)]
pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() }
}
impl<A:ToStr> ToStr for ~A {
#[inline(always)]
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
}
#[cfg(test)] #[cfg(test)]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
mod tests { mod tests {
@ -170,19 +161,12 @@ mod tests {
} }
#[test] #[test]
#[ignore]
fn test_vectors() { fn test_vectors() {
let x: ~[int] = ~[]; let x: ~[int] = ~[];
assert x.to_str() == ~"~[]"; assert x.to_str() == ~"[]";
assert (~[1]).to_str() == ~"~[1]"; assert (~[1]).to_str() == ~"[1]";
assert (~[1, 2, 3]).to_str() == ~"~[1, 2, 3]"; assert (~[1, 2, 3]).to_str() == ~"[1, 2, 3]";
assert (~[~[], ~[1], ~[1, 1]]).to_str() == assert (~[~[], ~[1], ~[1, 1]]).to_str() ==
~"~[~[], ~[1], ~[1, 1]]"; ~"[[], [1], [1, 1]]";
}
#[test]
fn test_pointer_types() {
assert (@1).to_str() == ~"@1";
assert (~(true, false)).to_str() == ~"~(true, false)";
} }
} }

View File

@ -66,7 +66,10 @@ pub fn replace<T>(dest: &mut T, src: T) -> T {
/// A non-copyable dummy type. /// A non-copyable dummy type.
pub struct NonCopyable { pub struct NonCopyable {
i: (), i: (),
drop { } }
impl Drop for NonCopyable {
fn finalize(&self) { }
} }
pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } } pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }

View File

@ -1458,7 +1458,10 @@ pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
pub struct target_data_res { pub struct target_data_res {
TD: TargetDataRef, TD: TargetDataRef,
drop { }
impl Drop for target_data_res {
fn finalize(&self) {
unsafe { unsafe {
llvm::LLVMDisposeTargetData(self.TD); llvm::LLVMDisposeTargetData(self.TD);
} }
@ -1492,7 +1495,10 @@ pub fn mk_target_data(string_rep: ~str) -> TargetData {
pub struct pass_manager_res { pub struct pass_manager_res {
PM: PassManagerRef, PM: PassManagerRef,
drop { }
impl Drop for pass_manager_res {
fn finalize(&self) {
unsafe { unsafe {
llvm::LLVMDisposePassManager(self.PM); llvm::LLVMDisposePassManager(self.PM);
} }
@ -1525,7 +1531,10 @@ pub fn mk_pass_manager() -> PassManager {
pub struct object_file_res { pub struct object_file_res {
ObjectFile: ObjectFileRef, ObjectFile: ObjectFileRef,
drop { }
impl Drop for object_file_res {
fn finalize(&self) {
unsafe { unsafe {
llvm::LLVMDisposeObjectFile(self.ObjectFile); llvm::LLVMDisposeObjectFile(self.ObjectFile);
} }
@ -1559,7 +1568,10 @@ pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
pub struct section_iter_res { pub struct section_iter_res {
SI: SectionIteratorRef, SI: SectionIteratorRef,
drop { }
impl Drop for section_iter_res {
fn finalize(&self) {
unsafe { unsafe {
llvm::LLVMDisposeSectionIterator(self.SI); llvm::LLVMDisposeSectionIterator(self.SI);
} }

View File

@ -1054,7 +1054,7 @@ pub fn compare_values(cx: block,
let scratch_rhs = alloca(cx, val_ty(rhs)); let scratch_rhs = alloca(cx, val_ty(rhs));
Store(cx, rhs, scratch_rhs); Store(cx, rhs, scratch_rhs);
let did = cx.tcx().lang_items.uniq_str_eq_fn(); let did = cx.tcx().lang_items.uniq_str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did, let bcx = callee::trans_lang_call(cx, did,
~[scratch_lhs, ~[scratch_lhs,
scratch_rhs], scratch_rhs],
expr::SaveIn( expr::SaveIn(
@ -1069,7 +1069,7 @@ pub fn compare_values(cx: block,
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()), let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
false); false);
let did = cx.tcx().lang_items.str_eq_fn(); let did = cx.tcx().lang_items.str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did, let bcx = callee::trans_lang_call(cx, did,
~[lhs, rhs], ~[lhs, rhs],
expr::SaveIn( expr::SaveIn(
scratch_result.val)); scratch_result.val));

View File

@ -90,7 +90,10 @@ use syntax::{ast, ast_util, codemap, ast_map};
pub struct icx_popper { pub struct icx_popper {
ccx: @CrateContext, ccx: @CrateContext,
drop { }
impl Drop for icx_popper {
fn finalize(&self) {
if self.ccx.sess.count_llvm_insns() { if self.ccx.sess.count_llvm_insns() {
self.ccx.stats.llvm_insn_ctxt.pop(); self.ccx.stats.llvm_insn_ctxt.pop();
} }
@ -304,7 +307,7 @@ pub fn malloc_raw_dyn(bcx: block,
// Allocate space: // Allocate space:
let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8())); let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8()));
let rval = alloca(bcx, T_ptr(T_i8())); let rval = alloca(bcx, T_ptr(T_i8()));
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx,
langcall, langcall,
~[tydesc, size], ~[tydesc, size],

View File

@ -332,11 +332,11 @@ pub fn trans_method_call(in_cx: block,
DontAutorefArg) DontAutorefArg)
} }
pub fn trans_rtcall_or_lang_call(bcx: block, pub fn trans_lang_call(bcx: block,
did: ast::def_id, did: ast::def_id,
args: &[ValueRef], args: &[ValueRef],
dest: expr::Dest) dest: expr::Dest)
-> block { -> block {
let fty = if did.crate == ast::local_crate { let fty = if did.crate == ast::local_crate {
ty::node_id_to_type(bcx.ccx().tcx, did.node) ty::node_id_to_type(bcx.ccx().tcx, did.node)
} else { } else {
@ -349,12 +349,12 @@ pub fn trans_rtcall_or_lang_call(bcx: block,
ArgVals(args), dest, DontAutorefArg); ArgVals(args), dest, DontAutorefArg);
} }
pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block, pub fn trans_lang_call_with_type_params(bcx: block,
did: ast::def_id, did: ast::def_id,
args: &[ValueRef], args: &[ValueRef],
type_params: ~[ty::t], type_params: ~[ty::t],
dest: expr::Dest) dest: expr::Dest)
-> block { -> block {
let fty; let fty;
if did.crate == ast::local_crate { if did.crate == ast::local_crate {
fty = ty::node_id_to_type(bcx.tcx(), did.node); fty = ty::node_id_to_type(bcx.tcx(), did.node);

View File

@ -500,7 +500,7 @@ pub fn make_opaque_cbox_take_glue(
// Allocate memory, update original ptr, and copy existing data // Allocate memory, update original ptr, and copy existing data
let opaque_tydesc = PointerCast(bcx, tydesc, T_ptr(T_i8())); let opaque_tydesc = PointerCast(bcx, tydesc, T_ptr(T_i8()));
let rval = alloca(bcx, T_ptr(T_i8())); let rval = alloca(bcx, T_ptr(T_i8()));
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx,
bcx.tcx().lang_items.exchange_malloc_fn(), bcx.tcx().lang_items.exchange_malloc_fn(),
~[opaque_tydesc, sz], ~[opaque_tydesc, sz],

View File

@ -141,7 +141,10 @@ pub struct Stats {
pub struct BuilderRef_res { pub struct BuilderRef_res {
B: BuilderRef, B: BuilderRef,
drop { }
impl Drop for BuilderRef_res {
fn finalize(&self) {
unsafe { unsafe {
llvm::LLVMDisposeBuilder(self.B); llvm::LLVMDisposeBuilder(self.B);
} }
@ -442,7 +445,7 @@ pub fn add_clean_frozen_root(bcx: block, val: ValueRef, t: ty::t) {
do in_scope_cx(bcx) |scope_info| { do in_scope_cx(bcx) |scope_info| {
scope_info.cleanups.push( scope_info.cleanups.push(
clean_temp(val, |bcx| { clean_temp(val, |bcx| {
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx,
bcx.tcx().lang_items.return_to_mut_fn(), bcx.tcx().lang_items.return_to_mut_fn(),
~[ ~[

View File

@ -216,7 +216,7 @@ pub fn trans_log(log_ex: @ast::expr,
// Call the polymorphic log function // Call the polymorphic log function
let val = val_datum.to_ref_llval(bcx); let val = val_datum.to_ref_llval(bcx);
let did = bcx.tcx().lang_items.log_type_fn(); let did = bcx.tcx().lang_items.log_type_fn();
let bcx = callee::trans_rtcall_or_lang_call_with_type_params( let bcx = callee::trans_lang_call_with_type_params(
bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore); bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore);
bcx bcx
} }
@ -384,7 +384,7 @@ fn trans_fail_value(bcx: block,
let V_str = PointerCast(bcx, V_fail_str, T_ptr(T_i8())); let V_str = PointerCast(bcx, V_fail_str, T_ptr(T_i8()));
let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8())); let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8()));
let args = ~[V_str, V_filename, C_int(ccx, V_line)]; let args = ~[V_str, V_filename, C_int(ccx, V_line)];
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx.tcx().lang_items.fail_fn(), args, expr::Ignore); bcx, bcx.tcx().lang_items.fail_fn(), args, expr::Ignore);
Unreachable(bcx); Unreachable(bcx);
return bcx; return bcx;
@ -401,7 +401,7 @@ pub fn trans_fail_bounds_check(bcx: block, sp: span,
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8())); let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
let args = ~[filename, line, index, len]; let args = ~[filename, line, index, len];
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx.tcx().lang_items.fail_bounds_check_fn(), args, expr::Ignore); bcx, bcx.tcx().lang_items.fail_bounds_check_fn(), args, expr::Ignore);
Unreachable(bcx); Unreachable(bcx);
return bcx; return bcx;

View File

@ -544,7 +544,7 @@ pub impl Datum {
// If we need to freeze the box, do that now. // If we need to freeze the box, do that now.
if root_info.freezes { if root_info.freezes {
callee::trans_rtcall_or_lang_call( callee::trans_lang_call(
bcx, bcx,
bcx.tcx().lang_items.borrow_as_imm_fn(), bcx.tcx().lang_items.borrow_as_imm_fn(),
~[ ~[
@ -566,7 +566,7 @@ pub impl Datum {
ByRef => Load(bcx, self.val), ByRef => Load(bcx, self.val),
}; };
callee::trans_rtcall_or_lang_call( callee::trans_lang_call(
bcx, bcx,
bcx.tcx().lang_items.check_not_borrowed_fn(), bcx.tcx().lang_items.check_not_borrowed_fn(),
~[ PointerCast(bcx, llval, T_ptr(T_i8())) ], ~[ PointerCast(bcx, llval, T_ptr(T_i8())) ],

View File

@ -30,7 +30,7 @@ use core::str;
pub fn trans_free(cx: block, v: ValueRef) -> block { pub fn trans_free(cx: block, v: ValueRef) -> block {
let _icx = cx.insn_ctxt("trans_free"); let _icx = cx.insn_ctxt("trans_free");
callee::trans_rtcall_or_lang_call( callee::trans_lang_call(
cx, cx,
cx.tcx().lang_items.free_fn(), cx.tcx().lang_items.free_fn(),
~[PointerCast(cx, v, T_ptr(T_i8()))], ~[PointerCast(cx, v, T_ptr(T_i8()))],
@ -39,7 +39,7 @@ pub fn trans_free(cx: block, v: ValueRef) -> block {
pub fn trans_exchange_free(cx: block, v: ValueRef) -> block { pub fn trans_exchange_free(cx: block, v: ValueRef) -> block {
let _icx = cx.insn_ctxt("trans_exchange_free"); let _icx = cx.insn_ctxt("trans_exchange_free");
callee::trans_rtcall_or_lang_call( callee::trans_lang_call(
cx, cx,
cx.tcx().lang_items.exchange_free_fn(), cx.tcx().lang_items.exchange_free_fn(),
~[PointerCast(cx, v, T_ptr(T_i8()))], ~[PointerCast(cx, v, T_ptr(T_i8()))],

View File

@ -306,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block,
let llsizeval = C_uint(bcx.ccx(), s.len()); let llsizeval = C_uint(bcx.ccx(), s.len());
let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq); let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq);
let lldestval = datum::scratch_datum(bcx, typ, false); let lldestval = datum::scratch_datum(bcx, typ, false);
let bcx = callee::trans_rtcall_or_lang_call( let bcx = callee::trans_lang_call(
bcx, bcx,
bcx.tcx().lang_items.strdup_uniq_fn(), bcx.tcx().lang_items.strdup_uniq_fn(),
~[ llptrval, llsizeval ], ~[ llptrval, llsizeval ],

View File

@ -336,7 +336,10 @@ pub fn monitor(+f: fn~(diagnostic::Emitter)) {
struct finally { struct finally {
ch: SharedChan<monitor_msg>, ch: SharedChan<monitor_msg>,
drop { self.ch.send(done); } }
impl Drop for finally {
fn finalize(&self) { self.ch.send(done); }
} }
let _finally = finally { ch: ch }; let _finally = finally { ch: ch };

View File

@ -32,7 +32,10 @@ pub fn indent<R>(op: fn() -> R) -> R {
pub struct _indenter { pub struct _indenter {
_i: (), _i: (),
drop { debug!("<<"); } }
impl Drop for _indenter {
fn finalize(&self) { debug!("<<"); }
} }
pub fn _indenter(_i: ()) -> _indenter { pub fn _indenter(_i: ()) -> _indenter {

View File

@ -125,7 +125,10 @@ mod blade_runner {
*/ */
struct Bored { struct Bored {
bored: bool, bored: bool,
drop { log(error, self.bored); } }
impl Drop for Bored {
fn finalize(&self) { log(error, self.bored); }
} }
/** /**

View File

@ -28,7 +28,10 @@ pub struct TaskPool<T> {
channels: ~[Chan<Msg<T>>], channels: ~[Chan<Msg<T>>],
mut next_index: uint, mut next_index: uint,
drop { }
impl<T> Drop for TaskPool<T> {
fn finalize(&self) {
for self.channels.each |channel| { for self.channels.each |channel| {
channel.send(Quit); channel.send(Quit);
} }

View File

@ -259,7 +259,11 @@ pub struct Parser {
/// Used to determine the path to externally loaded source files /// Used to determine the path to externally loaded source files
mod_path_stack: @mut ~[~str], mod_path_stack: @mut ~[~str],
drop {} /* do not copy the parser; its state is tied to outside state */ }
impl Drop for Parser {
/* do not copy the parser; its state is tied to outside state */
fn finalize(&self) {}
} }
pub impl Parser { pub impl Parser {

View File

@ -12,7 +12,10 @@
pub struct S { pub struct S {
x: int, x: int,
drop { }
impl Drop for S {
fn finalize(&self) {
io::println("goodbye"); io::println("goodbye");
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// xfail-test
struct HTMLImageData { struct HTMLImageData {
image: Option<~str> image: Option<~str>
} }
@ -25,18 +24,19 @@ enum NodeKind {
Element(ElementData) Element(ElementData)
} }
enum NodeData = { struct NodeData {
kind: ~NodeKind kind: ~NodeKind
}; }
fn main() { fn main() {
let mut id = HTMLImageData { image: None }; let mut id = HTMLImageData { image: None };
let ed = ElementData { kind: ~HTMLImageElement(id) }; let ed = ElementData { kind: ~HTMLImageElement(id) };
let n = NodeData({kind : ~Element(ed)}); let n = NodeData {kind : ~Element(ed)};
// n.b. span could be better
match n.kind { match n.kind {
~Element(ed) => match ed.kind { ~Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns
~HTMLImageElement(d) if d.image.is_some() => { true } ~HTMLImageElement(ref d) if d.image.is_some() => { true }
}, },
_ => fail!(~"WAT") //~ ERROR wat _ => fail!(~"WAT") //~ ERROR unreachable pattern
}; };
} }

View File

@ -1,6 +1,9 @@
struct S { struct S {
x: int, x: int,
drop {} }
impl Drop for S {
fn finalize(&self) {}
} }
impl S { impl S {

View File

@ -21,7 +21,10 @@ fn recurse() {
struct r { struct r {
recursed: *mut bool, recursed: *mut bool,
drop { }
impl Drop for r {
fn finalize(&self) {
unsafe { unsafe {
if !*(self.recursed) { if !*(self.recursed) {
*(self.recursed) = true; *(self.recursed) = true;

View File

@ -12,7 +12,10 @@
struct r { struct r {
i: int, i: int,
drop { fail!(~"squirrel") } }
impl Drop for r {
fn finalize(&self) { fail!(~"squirrel") }
} }
fn r(i: int) -> r { r { i: i } } fn r(i: int) -> r { r { i: i } }

View File

@ -13,7 +13,10 @@
struct r { struct r {
i: int, i: int,
drop { fail!(~"wombat") } }
impl Drop for r {
fn finalize(&self) { fail!(~"wombat") }
} }
fn r(i: int) -> r { r { i: i } } fn r(i: int) -> r { r { i: i } }

View File

@ -54,7 +54,10 @@ struct AsciiArt
// This struct can be quite large so we'll disable copying: developers need // This struct can be quite large so we'll disable copying: developers need
// to either pass these structs around via borrowed pointers or move them. // to either pass these structs around via borrowed pointers or move them.
drop {} }
impl Drop for AsciiArt {
fn finalize(&self) {}
} }
// It's common to define a constructor sort of function to create struct instances. // It's common to define a constructor sort of function to create struct instances.