Skip to content

Commit 0e4d1fc

Browse files
committed
auto merge of #9922 : alexcrichton/rust/less-sys, r=thestinger
More progress on #2240
2 parents 737413d + 82f5f65 commit 0e4d1fc

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

src/libstd/managed.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ use ptr::to_unsafe_ptr;
1717
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
1818
pub static RC_IMMORTAL : uint = 0x77777777;
1919

20+
/// Returns the refcount of a shared box (as just before calling this)
21+
#[inline]
22+
pub fn refcount<T>(t: @T) -> uint {
23+
use unstable::raw::Repr;
24+
unsafe { (*t.repr()).ref_count }
25+
}
26+
2027
/// Determine if two shared boxes point to the same object
2128
#[inline]
2229
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {

src/libstd/sys.rs

-10
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@
1313
#[allow(missing_doc)];
1414

1515
use c_str::ToCStr;
16-
use cast;
1716
use libc::size_t;
1817
use libc;
1918
use repr;
2019
use rt::task;
2120
use str;
2221

23-
/// Returns the refcount of a shared box (as just before calling this)
24-
#[inline]
25-
pub fn refcount<T>(t: @T) -> uint {
26-
unsafe {
27-
let ref_ptr: *uint = cast::transmute_copy(&t);
28-
*ref_ptr - 1
29-
}
30-
}
31-
3222
pub fn log_str<T>(t: &T) -> ~str {
3323
use rt::io;
3424
use rt::io::Decorator;

src/test/run-pass/match-pattern-drop.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
enum t { make_t(@int), clam, }
1515

1616
fn foo(s: @int) {
17-
info2!("{:?}", ::std::sys::refcount(s));
18-
let count = ::std::sys::refcount(s);
17+
info2!("{:?}", ::std::managed::refcount(s));
18+
let count = ::std::managed::refcount(s);
1919
let x: t = make_t(s); // ref up
20-
assert_eq!(::std::sys::refcount(s), count + 1u);
21-
info2!("{:?}", ::std::sys::refcount(s));
20+
assert_eq!(::std::managed::refcount(s), count + 1u);
21+
info2!("{:?}", ::std::managed::refcount(s));
2222

2323
match x {
2424
make_t(y) => {
@@ -27,19 +27,19 @@ fn foo(s: @int) {
2727
}
2828
_ => { info2!("?"); fail2!(); }
2929
}
30-
info2!("{:?}", ::std::sys::refcount(s));
31-
assert_eq!(::std::sys::refcount(s), count + 1u);
32-
let _ = ::std::sys::refcount(s); // don't get bitten by last-use.
30+
info2!("{:?}", ::std::managed::refcount(s));
31+
assert_eq!(::std::managed::refcount(s), count + 1u);
32+
let _ = ::std::managed::refcount(s); // don't get bitten by last-use.
3333
}
3434

3535
pub fn main() {
3636
let s: @int = @0; // ref up
3737

38-
let count = ::std::sys::refcount(s);
38+
let count = ::std::managed::refcount(s);
3939

4040
foo(s); // ref up then down
4141

42-
info2!("{}", ::std::sys::refcount(s));
43-
let count2 = ::std::sys::refcount(s);
42+
info2!("{}", ::std::managed::refcount(s));
43+
let count2 = ::std::managed::refcount(s);
4444
assert_eq!(count, count2);
4545
}

src/test/run-pass/unique-copy-box.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
#[allow(unused_variable)];
1212

13-
use std::sys;
13+
use std::managed;
1414

1515
pub fn main() {
1616
let i = ~@1;
1717
let j = ~@2;
18-
let rc1 = sys::refcount(*i);
18+
let rc1 = managed::refcount(*i);
1919
let j = i.clone();
20-
let rc2 = sys::refcount(*i);
20+
let rc2 = managed::refcount(*i);
2121
error2!("rc1: {} rc2: {}", rc1, rc2);
2222
assert_eq!(rc1 + 1u, rc2);
2323
}

0 commit comments

Comments
 (0)