Revert "Convert libstd to use the Drop trait"

This reverts commit 28c7a25151.
This commit is contained in:
Brian Anderson
2012-11-14 14:51:16 -08:00
parent 11024eaebb
commit c44c9a47d8
8 changed files with 52 additions and 107 deletions

View File

@@ -217,10 +217,7 @@ fn check_poison(is_mutex: bool, failed: bool) {
#[doc(hidden)] #[doc(hidden)]
struct PoisonOnFail { struct PoisonOnFail {
failed: &mut bool, failed: &mut bool,
} drop {
impl PoisonOnFail : Drop {
fn finalize() {
/* assert !*self.failed; -- might be false in case of cond.wait() */ /* assert !*self.failed; -- might be false in case of cond.wait() */
if task::failing() { *self.failed = true; } if task::failing() { *self.failed = true; }
} }

View File

@@ -55,10 +55,7 @@ pub struct Arena {
priv mut head: Chunk, priv mut head: Chunk,
priv mut pod_head: Chunk, priv mut pod_head: Chunk,
priv mut chunks: @List<Chunk>, priv mut chunks: @List<Chunk>,
} drop {
impl Arena : Drop {
fn finalize() {
unsafe { unsafe {
destroy_chunk(&self.head); destroy_chunk(&self.head);
for list::each(self.chunks) |chunk| { for list::each(self.chunks) |chunk| {

View File

@@ -39,15 +39,12 @@ pub enum CVec<T> {
struct DtorRes { struct DtorRes {
dtor: Option<fn@()>, dtor: Option<fn@()>,
} drop {
impl DtorRes : Drop {
fn finalize() {
match self.dtor { match self.dtor {
option::None => (), option::None => (),
option::Some(f) => f() option::Some(f) => f()
} }
} }
} }
fn DtorRes(dtor: Option<fn@()>) -> DtorRes { fn DtorRes(dtor: Option<fn@()>) -> DtorRes {

View File

@@ -23,12 +23,10 @@ use cast::copy_lifetime;
#[doc = "The future type"] #[doc = "The future type"]
pub struct Future<A> { pub struct Future<A> {
/*priv*/ mut state: FutureState<A>, /*priv*/ mut state: FutureState<A>,
}
// FIXME(#2829) -- futures should not be copyable, because they close // FIXME(#2829) -- futures should not be copyable, because they close
// over fn~'s that have pipes and so forth within! // over fn~'s that have pipes and so forth within!
impl<A> Future<A> : Drop { drop {}
fn finalize() {}
} }
priv enum FutureState<A> { priv enum FutureState<A> {

View File

@@ -27,14 +27,11 @@ extern mod rustrt {
*/ */
struct TcpSocket { struct TcpSocket {
socket_data: @TcpSocketData, socket_data: @TcpSocketData,
} drop {
impl TcpSocket : Drop {
fn finalize() {
unsafe { unsafe {
tear_down_socket_data(self.socket_data) tear_down_socket_data(self.socket_data)
} }
} }
} }
pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket { pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {

View File

@@ -1133,10 +1133,7 @@ mod big_tests {
val: uint, val: uint,
key: fn(@uint), key: fn(@uint),
} drop {
impl LVal : Drop {
fn finalize() {
let x = unsafe { task::local_data::local_data_get(self.key) }; let x = unsafe { task::local_data::local_data_get(self.key) };
match x { match x {
Some(@y) => { Some(@y) => {

View File

@@ -150,12 +150,7 @@ impl &Sem<~[mut Waitqueue]> {
#[doc(hidden)] #[doc(hidden)]
struct SemRelease { struct SemRelease {
sem: &Sem<()>, sem: &Sem<()>,
} drop { self.sem.release(); }
impl SemRelease : Drop {
fn finalize() {
self.sem.release();
}
} }
fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r { fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r {
@@ -167,12 +162,7 @@ fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r {
#[doc(hidden)] #[doc(hidden)]
struct SemAndSignalRelease { struct SemAndSignalRelease {
sem: &Sem<~[mut Waitqueue]>, sem: &Sem<~[mut Waitqueue]>,
} drop { self.sem.release(); }
impl SemAndSignalRelease : Drop {
fn finalize() {
self.sem.release();
}
} }
fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>) fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>)
@@ -183,9 +173,7 @@ fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>)
} }
/// A mechanism for atomic-unlock-and-deschedule blocking and signalling. /// A mechanism for atomic-unlock-and-deschedule blocking and signalling.
pub struct Condvar { priv sem: &Sem<~[mut Waitqueue]> } pub struct Condvar { priv sem: &Sem<~[mut Waitqueue]>, drop { } }
impl Condvar : Drop { fn finalize() {} }
impl &Condvar { impl &Condvar {
/** /**
@@ -254,15 +242,10 @@ impl &Condvar {
// bounded in when it gets released, this shouldn't hang forever. // bounded in when it gets released, this shouldn't hang forever.
struct SemAndSignalReacquire { struct SemAndSignalReacquire {
sem: &Sem<~[mut Waitqueue]>, sem: &Sem<~[mut Waitqueue]>,
} drop unsafe {
// Needs to succeed, instead of itself dying.
impl SemAndSignalReacquire : Drop { do task::unkillable {
fn finalize() { self.sem.acquire();
unsafe {
// Needs to succeed, instead of itself dying.
do task::unkillable {
self.sem.acquire();
}
} }
} }
} }
@@ -598,26 +581,21 @@ impl &RWlock {
#[doc(hidden)] #[doc(hidden)]
struct RWlockReleaseRead { struct RWlockReleaseRead {
lock: &RWlock, lock: &RWlock,
} drop unsafe {
do task::unkillable {
impl RWlockReleaseRead : Drop { let mut last_reader = false;
fn finalize() { do self.lock.state.with |state| {
unsafe { assert state.read_mode;
do task::unkillable { assert state.read_count > 0;
let mut last_reader = false; state.read_count -= 1;
do self.lock.state.with |state| { if state.read_count == 0 {
assert state.read_mode; last_reader = true;
assert state.read_count > 0; state.read_mode = false;
state.read_count -= 1;
if state.read_count == 0 {
last_reader = true;
state.read_mode = false;
}
}
if last_reader {
(&self.lock.access_lock).release();
} }
} }
if last_reader {
(&self.lock.access_lock).release();
}
} }
} }
} }
@@ -632,33 +610,27 @@ fn RWlockReleaseRead(lock: &r/RWlock) -> RWlockReleaseRead/&r {
#[doc(hidden)] #[doc(hidden)]
struct RWlockReleaseDowngrade { struct RWlockReleaseDowngrade {
lock: &RWlock, lock: &RWlock,
} drop unsafe {
do task::unkillable {
impl RWlockReleaseDowngrade : Drop { let mut writer_or_last_reader = false;
fn finalize() { do self.lock.state.with |state| {
unsafe { if state.read_mode {
do task::unkillable { assert state.read_count > 0;
let mut writer_or_last_reader = false; state.read_count -= 1;
do self.lock.state.with |state| { if state.read_count == 0 {
if state.read_mode { // Case 1: Writer downgraded & was the last reader
assert state.read_count > 0;
state.read_count -= 1;
if state.read_count == 0 {
// Case 1: Writer downgraded & was the last reader
writer_or_last_reader = true;
state.read_mode = false;
} else {
// Case 2: Writer downgraded & was not the last
// reader
}
} else {
// Case 3: Writer did not downgrade
writer_or_last_reader = true; writer_or_last_reader = true;
state.read_mode = false;
} else {
// Case 2: Writer downgraded & was not the last reader
} }
} else {
// Case 3: Writer did not downgrade
writer_or_last_reader = true;
} }
if writer_or_last_reader { }
(&self.lock.access_lock).release(); if writer_or_last_reader {
} (&self.lock.access_lock).release();
} }
} }
} }
@@ -671,11 +643,9 @@ fn RWlockReleaseDowngrade(lock: &r/RWlock) -> RWlockReleaseDowngrade/&r {
} }
/// The "write permission" token used for rwlock.write_downgrade(). /// The "write permission" token used for rwlock.write_downgrade().
pub struct RWlockWriteMode { /* priv */ lock: &RWlock } pub struct RWlockWriteMode { /* priv */ lock: &RWlock, drop { } }
impl RWlockWriteMode : Drop { fn finalize() {} }
/// The "read permission" token used for rwlock.write_downgrade(). /// The "read permission" token used for rwlock.write_downgrade().
pub struct RWlockReadMode { priv lock: &RWlock } pub struct RWlockReadMode { priv lock: &RWlock, drop { } }
impl RWlockReadMode : Drop { fn finalize() {} }
impl &RWlockWriteMode { impl &RWlockWriteMode {
/// Access the pre-downgrade rwlock in write mode. /// Access the pre-downgrade rwlock in write mode.
@@ -984,12 +954,7 @@ mod tests {
} }
struct SendOnFailure { struct SendOnFailure {
c: pipes::Chan<()>, c: pipes::Chan<()>,
} drop { self.c.send(()); }
impl SendOnFailure : Drop {
fn finalize() {
self.c.send(());
}
} }
fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure { fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure {

View File

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