diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-28 07:25:49 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-28 07:25:49 -0800 |
| commit | d2c4b6492dbccc1bb60f163ac583467bc63abce6 (patch) | |
| tree | d17faf8bcf8622272d8f8f3d31ef8e0fd795031d /src/libcore | |
| parent | 3953bdd812d73a51f9a7be4a1c57c60d56c6aa1a (diff) | |
| parent | b171d0ef7b68fed961597d38e6a474d748243987 (diff) | |
| download | rust-d2c4b6492dbccc1bb60f163ac583467bc63abce6.tar.gz rust-d2c4b6492dbccc1bb60f163ac583467bc63abce6.zip | |
Merge remote-tracking branch 'remotes/origin/incoming' into incoming
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cleanup.rs | 4 | ||||
| -rw-r--r-- | src/libcore/io.rs | 10 | ||||
| -rw-r--r-- | src/libcore/option.rs | 5 | ||||
| -rw-r--r-- | src/libcore/pipes.rs | 5 | ||||
| -rw-r--r-- | src/libcore/private.rs | 15 | ||||
| -rw-r--r-- | src/libcore/rand.rs | 5 | ||||
| -rw-r--r-- | src/libcore/rt.rs | 28 | ||||
| -rw-r--r-- | src/libcore/run.rs | 5 | ||||
| -rw-r--r-- | src/libcore/task/spawn.rs | 10 | ||||
| -rw-r--r-- | src/libcore/to_str.rs | 26 | ||||
| -rw-r--r-- | src/libcore/util.rs | 5 |
11 files changed, 66 insertions, 52 deletions
diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 567d6da23a6..6912d6d995b 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -154,7 +154,7 @@ fn debug_mem() -> bool { #[cfg(notest)] #[lang="annihilate"] pub unsafe fn annihilate() { - use rt::rt_free; + use rt::local_free; use io::WriterUtil; use io; use libc; @@ -192,7 +192,7 @@ pub unsafe fn annihilate() { stats.n_bytes_freed += (*((*box).header.type_desc)).size + sys::size_of::<BoxRepr>(); - rt_free(transmute(box)); + local_free(transmute(box)); } } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 421eb94a291..45d89b29a2e 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -474,7 +474,10 @@ impl<R:Reader,C> Reader for Wrapper<R, C> { pub struct FILERes { f: *libc::FILE, - drop { +} + +impl Drop for FILERes { + fn finalize(&self) { unsafe { libc::fclose(self.f); } @@ -683,7 +686,10 @@ impl Writer for fd_t { pub struct FdRes { fd: fd_t, - drop { +} + +impl Drop for FdRes { + fn finalize(&self) { unsafe { libc::close(self.fd); } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 1c2df949a2e..12ed0df0076 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -450,7 +450,10 @@ fn test_unwrap_str() { fn test_unwrap_resource() { struct R { i: @mut int, - drop { *(self.i) += 1; } + } + + impl ::ops::Drop for R { + fn finalize(&self) { *(self.i) += 1; } } fn R(i: @mut int) -> R { diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 15a6e700ffd..a0a29c6b516 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -346,7 +346,10 @@ pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> { struct BufferResource<T> { buffer: ~Buffer<T>, - drop { +} + +impl<T> ::ops::Drop for BufferResource<T> { + fn finalize(&self) { unsafe { let b = move_it!(self.buffer); //let p = ptr::addr_of(*b); diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 2580efe6d09..e4fab18966c 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -126,7 +126,10 @@ struct ArcData<T> { struct ArcDestruct<T> { mut data: *libc::c_void, - drop { +} + +impl<T> Drop for ArcDestruct<T>{ + fn finalize(&self) { unsafe { if self.data.is_null() { 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> { mut ptr: Option<~ArcData<T>>, mut response: Option<comm::ChanOne<bool>>, - drop { + } + + impl<T> Drop for DeathThroes<T>{ + fn finalize(&self) { unsafe { let response = option::swap_unwrap(&mut self.response); // 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 { l: rust_little_lock, - drop { +} + +impl Drop for LittleLock { + fn finalize(&self) { unsafe { rustrt::rust_destroy_little_lock(self.l); } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index a88b8346516..15362f89e3f 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -365,7 +365,10 @@ impl Rng { struct RandRes { rng: *rust_rng, - drop { +} + +impl Drop for RandRes { + fn finalize(&self) { unsafe { rustrt::rand_free(self.rng); } diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index c3e4f925c40..5d0bad3ceb3 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -36,60 +36,54 @@ pub extern mod rustrt { unsafe fn rust_upcall_free(ptr: *c_char); } -#[rt(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); } -#[rt(fail_bounds_check)] #[lang="fail_bounds_check"] -pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t, - index: size_t, len: size_t) { +pub unsafe fn fail_bounds_check(file: *c_char, line: size_t, + index: size_t, len: size_t) { let msg = fmt!("index out of bounds: the len is %d but the index is %d", len as int, index as int); 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"; do str::as_buf(msg) |msg_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 -#[rt(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))) } // 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 // problem occurs, call exit instead. -#[rt(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)) } -#[rt(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); } // 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 // problem occurs, call exit instead. -#[rt(free)] #[lang="free"] -pub unsafe fn rt_free(ptr: *c_char) { +pub unsafe fn local_free(ptr: *c_char) { 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) { let a: *mut BoxRepr = transmute(a); if ((*a).header.ref_count & FROZEN_BIT) != 0 { - rt_fail_borrowed(); + fail_borrowed(); } } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 4e2337b8331..aa1e473e3bf 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -248,7 +248,10 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program { } struct ProgRes { r: ProgRepr, - drop { + } + + impl Drop for ProgRes { + fn finalize(&self) { unsafe { // FIXME #4943: This is bad. destroy_repr(cast::transmute(&self.r)); diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 5110f70ff11..bf7209f9fc3 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -308,8 +308,11 @@ struct TCB { mut ancestors: AncestorList, is_main: bool, notifier: Option<AutoNotify>, +} + +impl Drop for TCB { // Runs on task exit. - drop { + fn finalize(&self) { unsafe { // If we are failing, the whole taskgroup needs to die. if rt::rust_task_is_unwinding(self.me) { @@ -353,7 +356,10 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, struct AutoNotify { notify_chan: Chan<TaskResult>, mut failed: bool, - drop { +} + +impl Drop for AutoNotify { + fn finalize(&self) { let result = if self.failed { Failure } else { Success }; self.notify_chan.send(result); } diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 17e4e042a5a..916c188a9c3 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -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 // 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)] #[allow(non_implicitly_copyable_typarams)] mod tests { @@ -170,19 +161,12 @@ mod tests { } #[test] - #[ignore] fn test_vectors() { let x: ~[int] = ~[]; - assert x.to_str() == ~"~[]"; - assert (~[1]).to_str() == ~"~[1]"; - assert (~[1, 2, 3]).to_str() == ~"~[1, 2, 3]"; + assert x.to_str() == ~"[]"; + assert (~[1]).to_str() == ~"[1]"; + assert (~[1, 2, 3]).to_str() == ~"[1, 2, 3]"; assert (~[~[], ~[1], ~[1, 1]]).to_str() == - ~"~[~[], ~[1], ~[1, 1]]"; - } - - #[test] - fn test_pointer_types() { - assert (@1).to_str() == ~"@1"; - assert (~(true, false)).to_str() == ~"~(true, false)"; + ~"[[], [1], [1, 1]]"; } } diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 629c4a3291c..522cb2d2783 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -66,7 +66,10 @@ pub fn replace<T>(dest: &mut T, src: T) -> T { /// A non-copyable dummy type. pub struct NonCopyable { i: (), - drop { } +} + +impl Drop for NonCopyable { + fn finalize(&self) { } } pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } } |
