Skip to content

Commit 357ef1f

Browse files
committed
Rewrite boxed_region/memory_region in Rust
This drops more of the old C++ runtime to rather be written in rust. A few features were lost along the way, but hopefully not too many. The main loss is that there are no longer backtraces associated with allocations (rust doesn't have a way of acquiring those just yet). Other than that though, I believe that the rest of the debugging utilities made their way over into rust. Closes #8704
1 parent c5074ae commit 357ef1f

13 files changed

+253
-652
lines changed

mk/rt.mk

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
8989
rt/rust_upcall.cpp \
9090
rt/rust_uv.cpp \
9191
rt/miniz.cpp \
92-
rt/memory_region.cpp \
93-
rt/boxed_region.cpp \
9492
rt/rust_android_dummy.cpp \
9593
rt/rust_test_helpers.cpp
9694

src/libstd/at_vec.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ pub mod raw {
158158
use at_vec::capacity;
159159
use cast;
160160
use cast::{transmute, transmute_copy};
161-
use libc;
162161
use ptr;
163162
use mem;
164163
use uint;
@@ -250,7 +249,7 @@ pub mod raw {
250249
use rt::task::Task;
251250

252251
do Local::borrow |task: &mut Task| {
253-
task.heap.realloc(ptr as *libc::c_void, size) as *()
252+
task.heap.realloc(ptr as *mut Box<()>, size) as *()
254253
}
255254
}
256255
}

src/libstd/cleanup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#[doc(hidden)];
1212

1313
use libc::c_void;
14-
use ptr::null;
14+
use ptr;
1515
use unstable::intrinsics::TyDesc;
1616
use unstable::raw;
1717

@@ -37,7 +37,7 @@ unsafe fn each_live_alloc(read_next_before: bool,
3737
use rt::local_heap;
3838

3939
let mut box = local_heap::live_allocs();
40-
while box != null() {
40+
while box != ptr::mut_null() {
4141
let next_before = (*box).next;
4242
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;
4343

src/libstd/rt/env.rs

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use os;
1919

2020
static mut MIN_STACK: uint = 4000000;
2121
static mut DEBUG_BORROW: bool = false;
22+
static mut POISON_ON_FREE: bool = false;
2223

2324
pub fn init() {
2425
unsafe {
@@ -33,6 +34,10 @@ pub fn init() {
3334
Some(_) => DEBUG_BORROW = true,
3435
None => ()
3536
}
37+
match os::getenv("RUST_POISON_ON_FREE") {
38+
Some(_) => POISON_ON_FREE = true,
39+
None => ()
40+
}
3641
}
3742
}
3843

@@ -43,3 +48,7 @@ pub fn min_stack() -> uint {
4348
pub fn debug_borrow() -> bool {
4449
unsafe { DEBUG_BORROW }
4550
}
51+
52+
pub fn poison_on_free() -> bool {
53+
unsafe { POISON_ON_FREE }
54+
}

src/libstd/rt/global_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern {
1919
}
2020

2121
#[inline]
22-
fn get_box_size(body_size: uint, body_align: uint) -> uint {
22+
pub fn get_box_size(body_size: uint, body_align: uint) -> uint {
2323
let header_size = size_of::<raw::Box<()>>();
2424
// FIXME (#2699): This alignment calculation is suspicious. Is it right?
2525
let total_size = align_to(header_size, body_align) + body_size;

0 commit comments

Comments
 (0)