diff options
| author | bors <bors@rust-lang.org> | 2013-07-26 19:46:36 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-26 19:46:36 -0700 |
| commit | 4989799799df1fb7c23fc0bf017be8faa356387f (patch) | |
| tree | 31cdd51e5e11c9d131d5a74ce8cd05c76c796e70 /src/libstd/rt | |
| parent | 5c4cd30f80273ba573df048b6295ea6e543df599 (diff) | |
| parent | 5aaaca0c6a837ef60260b07121f4b4c4984afc70 (diff) | |
| download | rust-4989799799df1fb7c23fc0bf017be8faa356387f.tar.gz rust-4989799799df1fb7c23fc0bf017be8faa356387f.zip | |
auto merge of #7986 : alexcrichton/rust/raw-repr, r=brson
This moves the raw struct layout of closures, vectors, boxes, and strings into a new `unstable::raw` module. This is meant to be a centralized location to find information for the layout of these values. As safe method, `unwrap`, is provided to convert a rust value to its raw representation. Unsafe methods to convert back are not provided because they are rarely used and too numerous to write an implementation for each (not much of a common pattern). This is progress on #6790. I tried to get a nice interface for a trait to implement in the raw module, but I was unable to come up with one. The hard part is that there are so many different directions to go from one way to another that it's difficult to find a pattern to follow to implement a trait with. Someone else might have some better luck though.
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 32 | ||||
| -rw-r--r-- | src/libstd/rt/global_heap.rs | 8 | ||||
| -rw-r--r-- | src/libstd/rt/local_heap.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/sched.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 2 |
5 files changed, 26 insertions, 26 deletions
diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index 1a468fcf215..2d489e4dbc3 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -12,12 +12,12 @@ use cast::transmute; use libc::{c_char, c_void, size_t, STDERR_FILENO}; use io; use io::{Writer, WriterUtil}; -use managed::raw::BoxRepr; use option::{Option, None, Some}; use uint; use str; use str::{OwnedStr, StrSlice}; use sys; +use unstable::raw; use vec::ImmutableVector; #[allow(non_camel_case_types)] @@ -29,7 +29,7 @@ static ALL_BITS: uint = FROZEN_BIT | MUT_BIT; #[deriving(Eq)] struct BorrowRecord { - box: *mut BoxRepr, + box: *mut raw::Box<()>, file: *c_char, line: size_t } @@ -70,7 +70,7 @@ pub unsafe fn clear_task_borrow_list() { let _ = try_take_task_borrow_list(); } -unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) { +unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) { debug_borrow("fail_borrowed: ", box, 0, 0, file, line); match try_take_task_borrow_list() { @@ -172,8 +172,8 @@ impl DebugPrints for io::fd_t { #[inline] pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint { - let a: *mut BoxRepr = transmute(a); - let old_ref_count = (*a).header.ref_count; + let a = a as *mut raw::Box<()>; + let old_ref_count = (*a).ref_count; let new_ref_count = old_ref_count | FROZEN_BIT; debug_borrow("borrow_as_imm:", a, old_ref_count, new_ref_count, file, line); @@ -182,15 +182,15 @@ pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint { fail_borrowed(a, file, line); } - (*a).header.ref_count = new_ref_count; + (*a).ref_count = new_ref_count; old_ref_count } #[inline] pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint { - let a: *mut BoxRepr = transmute(a); - let old_ref_count = (*a).header.ref_count; + let a = a as *mut raw::Box<()>; + let old_ref_count = (*a).ref_count; let new_ref_count = old_ref_count | MUT_BIT | FROZEN_BIT; debug_borrow("borrow_as_mut:", a, old_ref_count, new_ref_count, file, line); @@ -199,7 +199,7 @@ pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint { fail_borrowed(a, file, line); } - (*a).header.ref_count = new_ref_count; + (*a).ref_count = new_ref_count; old_ref_count } @@ -208,7 +208,7 @@ pub unsafe fn record_borrow(a: *u8, old_ref_count: uint, file: *c_char, line: size_t) { if (old_ref_count & ALL_BITS) == 0 { // was not borrowed before - let a: *mut BoxRepr = transmute(a); + let a = a as *mut raw::Box<()>; debug_borrow("record_borrow:", a, old_ref_count, 0, file, line); do swap_task_borrow_list |borrow_list| { let mut borrow_list = borrow_list; @@ -223,7 +223,7 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint, if (old_ref_count & ALL_BITS) == 0 { // was not borrowed before, so we should find the record at // the end of the list - let a: *mut BoxRepr = transmute(a); + let a = a as *mut raw::Box<()>; debug_borrow("unrecord_borrow:", a, old_ref_count, 0, file, line); do swap_task_borrow_list |borrow_list| { let mut borrow_list = borrow_list; @@ -246,15 +246,15 @@ pub unsafe fn return_to_mut(a: *u8, orig_ref_count: uint, // Sometimes the box is null, if it is conditionally frozen. // See e.g. #4904. if !a.is_null() { - let a: *mut BoxRepr = transmute(a); - let old_ref_count = (*a).header.ref_count; + let a = a as *mut raw::Box<()>; + let old_ref_count = (*a).ref_count; let new_ref_count = (old_ref_count & !ALL_BITS) | (orig_ref_count & ALL_BITS); debug_borrow("return_to_mut:", a, old_ref_count, new_ref_count, file, line); - (*a).header.ref_count = new_ref_count; + (*a).ref_count = new_ref_count; } } @@ -262,8 +262,8 @@ pub unsafe fn return_to_mut(a: *u8, orig_ref_count: uint, pub unsafe fn check_not_borrowed(a: *u8, file: *c_char, line: size_t) { - let a: *mut BoxRepr = transmute(a); - let ref_count = (*a).header.ref_count; + let a = a as *mut raw::Box<()>; + let ref_count = (*a).ref_count; debug_borrow("check_not_borrowed:", a, ref_count, 0, file, line); if (ref_count & FROZEN_BIT) != 0 { fail_borrowed(a, file, line); diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 54e9cb263db..7488b08da42 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -9,8 +9,8 @@ // except according to those terms. use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc}; -use managed::raw::{BoxHeaderRepr, BoxRepr}; use unstable::intrinsics::TyDesc; +use unstable::raw; use sys::size_of; extern { @@ -20,7 +20,7 @@ extern { #[inline] fn get_box_size(body_size: uint, body_align: uint) -> uint { - let header_size = size_of::<BoxHeaderRepr>(); + 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; total_size @@ -82,8 +82,8 @@ pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { let total_size = get_box_size(size, (*td).align); let p = malloc_raw(total_size as uint); - let box: *mut BoxRepr = p as *mut BoxRepr; - (*box).header.type_desc = td; + let box = p as *mut raw::Box<()>; + (*box).type_desc = td; box as *c_char } diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 85917ae3edf..cd8e8549211 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -13,11 +13,11 @@ use libc; use libc::{c_void, uintptr_t, size_t}; use ops::Drop; -use repr::BoxRepr; use rt; use rt::OldTaskContext; use rt::local::Local; use rt::task::Task; +use unstable::raw; type MemoryRegion = c_void; @@ -26,7 +26,7 @@ struct Env { priv opaque: () } struct BoxedRegion { env: *Env, backing_region: *MemoryRegion, - live_allocs: *BoxRepr + live_allocs: *raw::Box<()>, } pub type OpaqueBox = c_void; @@ -103,7 +103,7 @@ pub unsafe fn local_free(ptr: *libc::c_char) { } } -pub fn live_allocs() -> *BoxRepr { +pub fn live_allocs() -> *raw::Box<()> { let region = match rt::context() { OldTaskContext => { unsafe { rust_current_boxed_region() } diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index d8d61806a5b..33cfd69fcd2 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -10,9 +10,9 @@ use either::{Left, Right}; use option::{Option, Some, None}; -use sys; use cast::transmute; use clone::Clone; +use unstable::raw; use super::sleeper_list::SleeperList; use super::work_queue::WorkQueue; @@ -698,7 +698,7 @@ impl SchedHandle { // XXX: Some hacks to put a &fn in Scheduler without borrowck // complaining -type UnsafeTaskReceiver = sys::Closure; +type UnsafeTaskReceiver = raw::Closure; trait ClosureConverter { fn from_fn(&fn(&mut Scheduler, BlockedTask)) -> Self; fn to_fn(self) -> &fn(&mut Scheduler, BlockedTask); diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index d2975148350..8cf864b9222 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -281,7 +281,7 @@ static UNWIND_TOKEN: uintptr_t = 839147; impl Unwinder { pub fn try(&mut self, f: &fn()) { - use sys::Closure; + use unstable::raw::Closure; unsafe { let closure: Closure = transmute(f); |
