Skip to content

Commit

Permalink
Fix an off-by-one in managed::refcount
Browse files Browse the repository at this point in the history
This fixes a bug I accidentally introduced in #9922
  • Loading branch information
alexcrichton committed Oct 18, 2013
1 parent a1848bc commit 6a11e17
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/libstd/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub static RC_IMMORTAL : uint = 0x77777777;
#[inline]
pub fn refcount<T>(t: @T) -> uint {
use unstable::raw::Repr;
unsafe { (*t.repr()).ref_count }
unsafe { (*t.repr()).ref_count - 1 }
}

/// Determine if two shared boxes point to the same object
Expand Down Expand Up @@ -110,3 +110,14 @@ fn test() {
assert!((!ptr_eq::<int>(x, y)));
assert!((!ptr_eq::<int>(y, x)));
}

#[test]
fn refcount_test() {
use clone::Clone;

let x = @3;
assert_eq!(refcount(x), 1);
let y = x.clone();
assert_eq!(refcount(x), 2);
assert_eq!(refcount(y), 2);
}

5 comments on commit 6a11e17

@bors
Copy link
Contributor

@bors bors commented on 6a11e17 Oct 18, 2013

Choose a reason for hiding this comment

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

saw approval from thestinger
at alexcrichton@6a11e17

@bors
Copy link
Contributor

@bors bors commented on 6a11e17 Oct 18, 2013

Choose a reason for hiding this comment

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

merging alexcrichton/rust/refcount-tests = 6a11e17 into auto

@bors
Copy link
Contributor

@bors bors commented on 6a11e17 Oct 18, 2013

Choose a reason for hiding this comment

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

alexcrichton/rust/refcount-tests = 6a11e17 merged ok, testing candidate = a1b25f2

@bors
Copy link
Contributor

@bors bors commented on 6a11e17 Oct 18, 2013

@bors
Copy link
Contributor

@bors bors commented on 6a11e17 Oct 18, 2013

Choose a reason for hiding this comment

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

fast-forwarding master to auto = a1b25f2

Please sign in to comment.