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"] #[abi = "cdecl"]
native mod rustrt { native mod rustrt {
pure fn refcount(t: *()) -> libc::intptr_t;
fn unsupervise(); fn unsupervise();
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> str; 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>() } unchecked { rusti::pref_align_of::<T>() }
} }
#[doc = "Returns the refcount of a shared box"] #[doc = "Returns the refcount of a shared box (as just before calling this)"]
pure fn refcount<T>(t: @T) -> uint { pure fn refcount<T>(+t: @T) -> uint {
unsafe { 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_tag;
export debug_fn; export debug_fn;
export ptr_cast; export ptr_cast;
export refcount;
export breakpoint; export breakpoint;
#[abi = "cdecl"] #[abi = "cdecl"]
@ -48,11 +47,6 @@ unsafe fn ptr_cast<T, U>(x: @T) -> @U {
reinterpret_cast(x))) reinterpret_cast(x)))
} }
fn refcount<T>(a: @T) -> uint unsafe {
let p: *uint = unsafe::reinterpret_cast(a);
ret *p;
}
#[doc = "Triggers a debugger breakpoint"] #[doc = "Triggers a debugger breakpoint"]
fn breakpoint() { fn breakpoint() {
rustrt::rust_dbg_breakpoint(); rustrt::rust_dbg_breakpoint();

View file

@ -127,13 +127,6 @@ rust_env_pairs() {
} }
#endif #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 extern "C" CDECL void
unsupervise() { unsupervise() {
rust_task *task = rust_get_current_task(); rust_task *task = rust_get_current_task();

View file

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

View file

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

View file

@ -11,7 +11,6 @@ native mod rustrt {
fn unsupervise(); fn unsupervise();
fn last_os_error() -> str; fn last_os_error() -> str;
fn rust_getcwd() -> str; fn rust_getcwd() -> str;
fn refcount(box: @int);
fn get_task_id(); fn get_task_id();
fn sched_threads(); fn sched_threads();
fn rust_get_task(); fn rust_get_task();
@ -20,7 +19,6 @@ native mod rustrt {
fn calllink01() { rustrt::unsupervise(); } fn calllink01() { rustrt::unsupervise(); }
fn calllink02() { rustrt::last_os_error(); } fn calllink02() { rustrt::last_os_error(); }
fn calllink03() { rustrt::rust_getcwd(); } fn calllink03() { rustrt::rust_getcwd(); }
fn calllink04() { rustrt::refcount(@0); }
fn calllink08() { rustrt::get_task_id(); } fn calllink08() { rustrt::get_task_id(); }
fn calllink09() { rustrt::sched_threads(); } fn calllink09() { rustrt::sched_threads(); }
fn calllink10() { rustrt::rust_get_task(); } fn calllink10() { rustrt::rust_get_task(); }
@ -52,7 +50,6 @@ fn main() {
calllink01, calllink01,
calllink02, calllink02,
calllink03, calllink03,
calllink04,
calllink08, calllink08,
calllink09, calllink09,
calllink10 calllink10