Skip to content

Abort on root count overflows #35

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 1 commit into from
Aug 7, 2016
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
5 changes: 4 additions & 1 deletion gc/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ impl<T: Trace + ?Sized> GcBox<T> {
/// Roots prevent the GcBox from being destroyed by
/// the garbage collector.
pub unsafe fn root_inner(&self) {
self.header.roots.set(self.header.roots.get() + 1);
// abort if the count overflows to prevent `mem::forget` loops that could otherwise lead to
// erroneous drops
self.header.roots.set(self.header.roots.get()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panic should be ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I was just copying the behavior of {Arc, Rc}.

.checked_add(1).unwrap_or_else(|| ::std::intrinsics::abort()));
}

/// Decrease the root count on this GcBox.
Expand Down
2 changes: 1 addition & 1 deletion gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! It is marked as non-sendable because the garbage collection only occurs
//! thread locally.

#![feature(borrow_state, coerce_unsized, optin_builtin_traits, nonzero, unsize)]
#![feature(borrow_state, coerce_unsized, core_intrinsics, optin_builtin_traits, nonzero, unsize)]

extern crate core;

Expand Down