Skip to content

Commit b456ab7

Browse files
committed
---
yaml --- r: 142637 b: refs/heads/try2 c: aa9210d h: refs/heads/master i: 142635: 20bfd1e v: v3
1 parent 4ef8645 commit b456ab7

File tree

8 files changed

+68
-46
lines changed

8 files changed

+68
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 95eb01957bf23922abdf083f677c6c2d6927713a
8+
refs/heads/try2: aa9210d25afb3779e1d95722b73b62a7be6274fe
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/at_vec.rs

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ use vec;
2323
/// Code for dealing with @-vectors. This is pretty incomplete, and
2424
/// contains a bunch of duplication from the code for ~-vectors.
2525
26-
pub mod rustrt {
27-
use libc;
28-
use sys;
29-
use vec;
30-
31-
#[abi = "cdecl"]
32-
#[link_name = "rustrt"]
33-
pub extern {
34-
pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
35-
v: **vec::raw::VecRepr,
36-
n: libc::size_t);
37-
}
38-
}
39-
4026
/// Returns the number of elements the vector can hold without reallocating
4127
#[inline]
4228
pub fn capacity<T>(v: @[T]) -> uint {
@@ -189,14 +175,16 @@ pub mod traits {
189175
pub mod traits {}
190176

191177
pub mod raw {
192-
use at_vec::{capacity, rustrt};
178+
use at_vec::capacity;
193179
use cast::{transmute, transmute_copy};
194180
use libc;
195181
use ptr;
196182
use sys;
197183
use uint;
198184
use unstable::intrinsics::{move_val_init};
199185
use vec;
186+
use vec::UnboxedVecRepr;
187+
use sys::TypeDesc;
200188

201189
pub type VecRepr = vec::raw::VecRepr;
202190
pub type SliceRepr = vec::raw::SliceRepr;
@@ -257,9 +245,47 @@ pub mod raw {
257245
pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
258246
// Only make the (slow) call into the runtime if we have to
259247
if capacity(*v) < n {
260-
let ptr: **VecRepr = transmute(v);
261-
rustrt::vec_reserve_shared_actual(sys::get_type_desc::<T>(),
262-
ptr, n as libc::size_t);
248+
let ptr: *mut *mut VecRepr = transmute(v);
249+
let ty = sys::get_type_desc::<T>();
250+
return reserve_raw(ty, ptr, n);
251+
}
252+
}
253+
254+
// Implementation detail. Shouldn't be public
255+
#[allow(missing_doc)]
256+
pub fn reserve_raw(ty: *TypeDesc, ptr: *mut *mut VecRepr, n: uint) {
257+
258+
unsafe {
259+
let size_in_bytes = n * (*ty).size;
260+
if size_in_bytes > (**ptr).unboxed.alloc {
261+
let total_size = size_in_bytes + sys::size_of::<UnboxedVecRepr>();
262+
// XXX: UnboxedVecRepr has an extra u8 at the end
263+
let total_size = total_size - sys::size_of::<u8>();
264+
(*ptr) = local_realloc(*ptr as *(), total_size) as *mut VecRepr;
265+
(**ptr).unboxed.alloc = size_in_bytes;
266+
}
267+
}
268+
269+
fn local_realloc(ptr: *(), size: uint) -> *() {
270+
use rt;
271+
use rt::OldTaskContext;
272+
use rt::local::Local;
273+
use rt::task::Task;
274+
275+
if rt::context() == OldTaskContext {
276+
unsafe {
277+
return rust_local_realloc(ptr, size as libc::size_t);
278+
}
279+
280+
extern {
281+
#[fast_ffi]
282+
fn rust_local_realloc(ptr: *(), size: libc::size_t) -> *();
283+
}
284+
} else {
285+
do Local::borrow::<Task, *()> |task| {
286+
task.heap.realloc(ptr as *libc::c_void, size) as *()
287+
}
288+
}
263289
}
264290
}
265291

branches/try2/src/libstd/rt/local_heap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ impl LocalHeap {
4949
}
5050
}
5151

52+
pub fn realloc(&mut self, ptr: *OpaqueBox, size: uint) -> *OpaqueBox {
53+
unsafe {
54+
return rust_boxed_region_realloc(self.boxed_region, ptr, size as size_t);
55+
}
56+
}
57+
5258
pub fn free(&mut self, box: *OpaqueBox) {
5359
unsafe {
5460
return rust_boxed_region_free(self.boxed_region, box);
@@ -76,5 +82,8 @@ extern {
7682
fn rust_boxed_region_malloc(region: *BoxedRegion,
7783
td: *TypeDesc,
7884
size: size_t) -> *OpaqueBox;
85+
fn rust_boxed_region_realloc(region: *BoxedRegion,
86+
ptr: *OpaqueBox,
87+
size: size_t) -> *OpaqueBox;
7988
fn rust_boxed_region_free(region: *BoxedRegion, box: *OpaqueBox);
8089
}

branches/try2/src/libstd/vec.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ pub mod rustrt {
4848
// to ~[] and reserve_shared_actual applies to @[].
4949
#[fast_ffi]
5050
unsafe fn vec_reserve_shared(t: *sys::TypeDesc,
51-
v: **raw::VecRepr,
51+
v: *mut *mut raw::VecRepr,
5252
n: libc::size_t);
53-
#[fast_ffi]
54-
unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
55-
v: **raw::VecRepr,
56-
n: libc::size_t);
5753
}
5854
}
5955

@@ -79,11 +75,11 @@ pub fn reserve<T>(v: &mut ~[T], n: uint) {
7975
use managed;
8076
if capacity(v) < n {
8177
unsafe {
82-
let ptr: **raw::VecRepr = cast::transmute(v);
78+
let ptr: *mut *mut raw::VecRepr = cast::transmute(v);
8379
let td = sys::get_type_desc::<T>();
8480
if ((**ptr).box_header.ref_count ==
8581
managed::raw::RC_MANAGED_UNIQUE) {
86-
rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t);
82+
::at_vec::raw::reserve_raw(td, ptr, n);
8783
} else {
8884
rustrt::vec_reserve_shared(td, ptr, n as libc::size_t);
8985
}

branches/try2/src/rt/rust_builtin.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ rust_env_pairs() {
6868
}
6969
#endif
7070

71-
extern "C" CDECL void
72-
vec_reserve_shared_actual(type_desc* ty, rust_vec_box** vp,
73-
size_t n_elts) {
71+
extern "C" CDECL void *
72+
rust_local_realloc(rust_opaque_box *ptr, size_t size) {
7473
rust_task *task = rust_get_current_task();
75-
reserve_vec_exact_shared(task, vp, n_elts * ty->size);
74+
return task->boxed.realloc(ptr, size);
7675
}
7776

7877
// This is completely misnamed.
@@ -899,6 +898,11 @@ rust_boxed_region_malloc(boxed_region *region, type_desc *td, size_t size) {
899898
return region->malloc(td, size);
900899
}
901900

901+
extern "C" CDECL rust_opaque_box*
902+
rust_boxed_region_realloc(boxed_region *region, rust_opaque_box *ptr, size_t size) {
903+
return region->realloc(ptr, size);
904+
}
905+
902906
extern "C" CDECL void
903907
rust_boxed_region_free(boxed_region *region, rust_opaque_box *box) {
904908
region->free(box);

branches/try2/src/rt/rust_util.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ vec_data(rust_vec *v) {
5757
return reinterpret_cast<T*>(v->data);
5858
}
5959

60-
inline void reserve_vec_exact_shared(rust_task* task, rust_vec_box** vpp,
61-
size_t size) {
62-
rust_opaque_box** ovpp = (rust_opaque_box**)vpp;
63-
if (size > (*vpp)->body.alloc) {
64-
*vpp = (rust_vec_box*)task->boxed.realloc(
65-
*ovpp, size + sizeof(rust_vec));
66-
(*vpp)->body.alloc = size;
67-
}
68-
}
69-
7060
inline void reserve_vec_exact(rust_vec_box** vpp,
7161
size_t size) {
7262
if (size > (*vpp)->body.alloc) {

branches/try2/src/rt/rustrt.def.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ rust_get_stack_segment
5353
rust_get_c_stack
5454
rust_log_str
5555
start_task
56-
vec_reserve_shared_actual
56+
rust_local_realloc
5757
vec_reserve_shared
5858
task_clear_event_reject
5959
task_wait_event
@@ -231,6 +231,7 @@ rust_delete_memory_region
231231
rust_new_boxed_region
232232
rust_delete_boxed_region
233233
rust_boxed_region_malloc
234+
rust_boxed_region_realloc
234235
rust_boxed_region_free
235236
rust_try
236237
rust_begin_unwind

branches/try2/src/test/run-pass/extern-pub.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
use std::libc;
2-
use std::sys;
3-
use std::vec;
42

53
extern {
6-
pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
7-
v: **vec::raw::VecRepr,
8-
n: libc::size_t);
4+
pub unsafe fn debug_get_stk_seg() -> *libc::c_void;
95
}
106

117
pub fn main() {

0 commit comments

Comments
 (0)