Skip to content

use the #[non_owned] and #[mutable] attributes #6305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libstd/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ struct RWARCInner<T> { lock: RWlock, failed: bool, data: T }
*
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
*/
#[mutable]
struct RWARC<T> {
x: SharedMutableState<RWARCInner<T>>,
cant_nest: ()
Expand Down
13 changes: 7 additions & 6 deletions src/libstd/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ struct RcBox<T> {
}

/// Immutable reference counted pointer type
#[non_owned]
pub struct Rc<T> {
priv ptr: *mut RcBox<T>,
priv non_owned: Option<@()> // FIXME: #5601: replace with `#[non_owned]`
}

pub impl<'self, T: Owned> Rc<T> {
Expand All @@ -35,7 +35,7 @@ pub impl<'self, T: Owned> Rc<T> {
let ptr = malloc(sys::size_of::<RcBox<T>>() as size_t) as *mut RcBox<T>;
assert!(!ptr::is_null(ptr));
intrinsics::move_val_init(&mut *ptr, RcBox{value: value, count: 1});
Rc{ptr: ptr, non_owned: None}
Rc{ptr: ptr}
}
}

Expand Down Expand Up @@ -64,7 +64,7 @@ impl<T: Owned> Clone for Rc<T> {
fn clone(&self) -> Rc<T> {
unsafe {
(*self.ptr).count += 1;
Rc{ptr: self.ptr, non_owned: None}
Rc{ptr: self.ptr}
}
}
}
Expand Down Expand Up @@ -113,9 +113,10 @@ struct RcMutBox<T> {
}

/// Mutable reference counted pointer type
#[non_owned]
#[mutable]
pub struct RcMut<T> {
priv ptr: *mut RcMutBox<T>,
priv non_owned: Option<@mut ()> // FIXME: #5601: replace with `#[non_owned]` and `#[non_const]`
}

pub impl<'self, T: Owned> RcMut<T> {
Expand All @@ -124,7 +125,7 @@ pub impl<'self, T: Owned> RcMut<T> {
let ptr = malloc(sys::size_of::<RcMutBox<T>>() as size_t) as *mut RcMutBox<T>;
assert!(!ptr::is_null(ptr));
intrinsics::move_val_init(&mut *ptr, RcMutBox{value: value, count: 1, borrow: Nothing});
RcMut{ptr: ptr, non_owned: None}
RcMut{ptr: ptr}
}
}

Expand Down Expand Up @@ -171,7 +172,7 @@ impl<T: Owned> Clone for RcMut<T> {
fn clone(&self) -> RcMut<T> {
unsafe {
(*self.ptr).count += 1;
RcMut{ptr: self.ptr, non_owned: None}
RcMut{ptr: self.ptr}
}
}
}
Expand Down