Fix sys::refcount and remove dbg::refcount

This commit is contained in:
Ben Blum 2012-06-28 14:40:31 -04:00
parent ad8280712f
commit af2d01e36b
6 changed files with 12 additions and 31 deletions

View file

@ -20,7 +20,6 @@ type rust_cond_lock = *libc::c_void;
#[abi = "cdecl"]
native mod rustrt {
pure fn refcount(t: *()) -> libc::intptr_t;
fn unsupervise();
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> str;
@ -71,10 +70,11 @@ pure fn pref_align_of<T>() -> uint {
unchecked { rusti::pref_align_of::<T>() }
}
#[doc = "Returns the refcount of a shared box"]
pure fn refcount<T>(t: @T) -> uint {
#[doc = "Returns the refcount of a shared box (as just before calling this)"]
pure fn refcount<T>(+t: @T) -> uint {
unsafe {
ret rustrt::refcount(unsafe::reinterpret_cast(t)) as uint;
let ref_ptr: *uint = unsafe::reinterpret_cast(t);
*ref_ptr - 1
}
}

View file

@ -8,7 +8,6 @@ export debug_box;
export debug_tag;
export debug_fn;
export ptr_cast;
export refcount;
export breakpoint;
#[abi = "cdecl"]
@ -48,11 +47,6 @@ unsafe fn ptr_cast<T, U>(x: @T) -> @U {
reinterpret_cast(x)))
}
fn refcount<T>(a: @T) -> uint unsafe {
let p: *uint = unsafe::reinterpret_cast(a);
ret *p;
}
#[doc = "Triggers a debugger breakpoint"]
fn breakpoint() {
rustrt::rust_dbg_breakpoint();

View file

@ -127,13 +127,6 @@ rust_env_pairs() {
}
#endif
extern "C" CDECL intptr_t
refcount(intptr_t *v) {
// Passed-in value has refcount 1 too high
// because it was ref'ed while making the call.
return (*v) - 1;
}
extern "C" CDECL void
unsupervise() {
rust_task *task = rust_get_current_task();

View file

@ -29,7 +29,6 @@ rand_new
rand_new_seeded
rand_next
rand_seed
refcount
rust_get_sched_id
rust_new_sched
rust_new_task_in_sched

View file

@ -1,14 +1,12 @@
// -*- rust -*-
use std;
import std::dbg;
import core::sys;
enum t { make_t(@int), clam, }
fn foo(s: @int) {
let count = dbg::refcount(s);
let count = sys::refcount(s);
let x: t = make_t(s); // ref up
alt x {
@ -18,17 +16,17 @@ fn foo(s: @int) {
}
_ { #debug("?"); fail; }
}
log(debug, dbg::refcount(s));
assert (dbg::refcount(s) == count + 1u);
log(debug, sys::refcount(s));
assert (sys::refcount(s) == count + 1u);
}
fn main() {
let s: @int = @0; // ref up
let count = dbg::refcount(s);
let count = sys::refcount(s);
foo(s); // ref up then down
log(debug, dbg::refcount(s));
assert (dbg::refcount(s) == count);
log(debug, sys::refcount(s));
assert (sys::refcount(s) == count);
}

View file

@ -11,7 +11,6 @@ native mod rustrt {
fn unsupervise();
fn last_os_error() -> str;
fn rust_getcwd() -> str;
fn refcount(box: @int);
fn get_task_id();
fn sched_threads();
fn rust_get_task();
@ -20,7 +19,6 @@ native mod rustrt {
fn calllink01() { rustrt::unsupervise(); }
fn calllink02() { rustrt::last_os_error(); }
fn calllink03() { rustrt::rust_getcwd(); }
fn calllink04() { rustrt::refcount(@0); }
fn calllink08() { rustrt::get_task_id(); }
fn calllink09() { rustrt::sched_threads(); }
fn calllink10() { rustrt::rust_get_task(); }
@ -52,7 +50,6 @@ fn main() {
calllink01,
calllink02,
calllink03,
calllink04,
calllink08,
calllink09,
calllink10
@ -63,4 +60,4 @@ fn main() {
let frame_backoff = rng.next() % 10u32 + 1u32;
task::try {|| runtest(f, frame_backoff) };
}
}
}