提交 d9f6dd26 编写于 作者: J James Miller 提交者: James Miller

Set #[no_drop_flag] on Rc<T> and AtomicOption. Add Test

上级 0cca08a2
......@@ -70,10 +70,12 @@ pub fn borrow<'r>(&'r self) -> &'r T {
impl<T> Drop for Rc<T> {
fn finalize(&self) {
unsafe {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, intrinsics::uninit());
free(self.ptr as *c_void)
if self.ptr.is_not_null() {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, intrinsics::uninit());
free(self.ptr as *c_void)
}
}
}
}
......@@ -220,10 +222,12 @@ pub fn with_mut_borrow<U>(&self, f: &fn(&mut T) -> U) -> U {
impl<T> Drop for RcMut<T> {
fn finalize(&self) {
unsafe {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, uninit());
free(self.ptr as *c_void)
if self.ptr.is_not_null() {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, uninit());
free(self.ptr as *c_void)
}
}
}
}
......
......@@ -3883,7 +3883,7 @@ pub fn has_drop_flag(&self) -> bool {
pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
match cx.destructor_for_type.find(&struct_id) {
Some(&method_def_id) => {
let flag = has_attr(cx, struct_id, "no_drop_flag");
let flag = !has_attr(cx, struct_id, "no_drop_flag");
TraitDtor(method_def_id, flag)
}
......
......@@ -62,6 +62,7 @@ pub struct AtomicPtr<T> {
/**
* An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
*/
#[no_drop_flag]
pub struct AtomicOption<T> {
priv p: *mut c_void
}
......
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::sys::size_of;
#[no_drop_flag]
struct Test<T> {
a: T
}
#[unsafe_destructor]
impl<T> Drop for Test<T> {
fn finalize(&self) { }
}
fn main() {
assert_eq!(size_of::<int>(), size_of::<Test<int>>());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册