Skip to content

Commit

Permalink
Rewrite boxed_region/memory_region in Rust
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcrichton committed Oct 26, 2013
1 parent c5074ae commit 357ef1f
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 652 deletions.
2 changes: 0 additions & 2 deletions mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
rt/rust_upcall.cpp \
rt/rust_uv.cpp \
rt/miniz.cpp \
rt/memory_region.cpp \
rt/boxed_region.cpp \
rt/rust_android_dummy.cpp \
rt/rust_test_helpers.cpp

Expand Down
3 changes: 1 addition & 2 deletions src/libstd/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ pub mod raw {
use at_vec::capacity;
use cast;
use cast::{transmute, transmute_copy};
use libc;
use ptr;
use mem;
use uint;
Expand Down Expand Up @@ -250,7 +249,7 @@ pub mod raw {
use rt::task::Task;

do Local::borrow |task: &mut Task| {
task.heap.realloc(ptr as *libc::c_void, size) as *()
task.heap.realloc(ptr as *mut Box<()>, size) as *()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[doc(hidden)];

use libc::c_void;
use ptr::null;
use ptr;
use unstable::intrinsics::TyDesc;
use unstable::raw;

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

let mut box = local_heap::live_allocs();
while box != null() {
while box != ptr::mut_null() {
let next_before = (*box).next;
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;

Expand Down
9 changes: 9 additions & 0 deletions src/libstd/rt/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use os;

static mut MIN_STACK: uint = 4000000;
static mut DEBUG_BORROW: bool = false;
static mut POISON_ON_FREE: bool = false;

pub fn init() {
unsafe {
Expand All @@ -33,6 +34,10 @@ pub fn init() {
Some(_) => DEBUG_BORROW = true,
None => ()
}
match os::getenv("RUST_POISON_ON_FREE") {
Some(_) => POISON_ON_FREE = true,
None => ()
}
}
}

Expand All @@ -43,3 +48,7 @@ pub fn min_stack() -> uint {
pub fn debug_borrow() -> bool {
unsafe { DEBUG_BORROW }
}

pub fn poison_on_free() -> bool {
unsafe { POISON_ON_FREE }
}
2 changes: 1 addition & 1 deletion src/libstd/rt/global_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern {
}

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

5 comments on commit 357ef1f

@bors
Copy link
Contributor

@bors bors commented on 357ef1f Oct 28, 2013

Choose a reason for hiding this comment

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

saw approval from pcwalton
at alexcrichton@357ef1f

@bors
Copy link
Contributor

@bors bors commented on 357ef1f Oct 28, 2013

Choose a reason for hiding this comment

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

merging alexcrichton/rust/issue-8704 = 357ef1f into auto

@bors
Copy link
Contributor

@bors bors commented on 357ef1f Oct 28, 2013

Choose a reason for hiding this comment

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

alexcrichton/rust/issue-8704 = 357ef1f merged ok, testing candidate = bee40a9

@bors
Copy link
Contributor

@bors bors commented on 357ef1f Oct 28, 2013

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 357ef1f Oct 28, 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 = bee40a9

Please sign in to comment.