Skip to content

Commit d9f6dd2

Browse files
James MillerAatch
James Miller
authored andcommitted
Set #[no_drop_flag] on Rc<T> and AtomicOption. Add Test
1 parent 0cca08a commit d9f6dd2

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

src/libextra/rc.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ impl<T> Rc<T> {
7070
impl<T> Drop for Rc<T> {
7171
fn finalize(&self) {
7272
unsafe {
73-
(*self.ptr).count -= 1;
74-
if (*self.ptr).count == 0 {
75-
ptr::replace_ptr(self.ptr, intrinsics::uninit());
76-
free(self.ptr as *c_void)
73+
if self.ptr.is_not_null() {
74+
(*self.ptr).count -= 1;
75+
if (*self.ptr).count == 0 {
76+
ptr::replace_ptr(self.ptr, intrinsics::uninit());
77+
free(self.ptr as *c_void)
78+
}
7779
}
7880
}
7981
}
@@ -220,10 +222,12 @@ impl<T> RcMut<T> {
220222
impl<T> Drop for RcMut<T> {
221223
fn finalize(&self) {
222224
unsafe {
223-
(*self.ptr).count -= 1;
224-
if (*self.ptr).count == 0 {
225-
ptr::replace_ptr(self.ptr, uninit());
226-
free(self.ptr as *c_void)
225+
if self.ptr.is_not_null() {
226+
(*self.ptr).count -= 1;
227+
if (*self.ptr).count == 0 {
228+
ptr::replace_ptr(self.ptr, uninit());
229+
free(self.ptr as *c_void)
230+
}
227231
}
228232
}
229233
}

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,7 @@ impl DtorKind {
38833883
pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
38843884
match cx.destructor_for_type.find(&struct_id) {
38853885
Some(&method_def_id) => {
3886-
let flag = has_attr(cx, struct_id, "no_drop_flag");
3886+
let flag = !has_attr(cx, struct_id, "no_drop_flag");
38873887

38883888
TraitDtor(method_def_id, flag)
38893889
}

src/libstd/unstable/atomics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub struct AtomicPtr<T> {
6262
/**
6363
* An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
6464
*/
65+
#[no_drop_flag]
6566
pub struct AtomicOption<T> {
6667
priv p: *mut c_void
6768
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::sys::size_of;
12+
13+
#[no_drop_flag]
14+
struct Test<T> {
15+
a: T
16+
}
17+
18+
#[unsafe_destructor]
19+
impl<T> Drop for Test<T> {
20+
fn finalize(&self) { }
21+
}
22+
23+
fn main() {
24+
assert_eq!(size_of::<int>(), size_of::<Test<int>>());
25+
}

0 commit comments

Comments
 (0)