@@ -22,12 +22,14 @@ use iterator::{FromIterator, Iterator, IteratorUtil};
2222use iter:: FromIter ;
2323use kinds:: Copy ;
2424use libc;
25+ use libc:: c_void;
2526use num:: Zero ;
2627use ops:: Add ;
2728use option:: { None , Option , Some } ;
2829use ptr:: to_unsafe_ptr;
2930use ptr;
3031use ptr:: RawPtr ;
32+ use rt:: global_heap:: realloc_raw;
3133use sys;
3234use sys:: size_of;
3335use uint;
@@ -52,12 +54,6 @@ pub mod rustrt {
5254
5355 #[ abi = "cdecl" ]
5456 pub extern {
55- // These names are terrible. reserve_shared applies
56- // to ~[] and reserve_shared_actual applies to @[].
57- #[ fast_ffi]
58- unsafe fn vec_reserve_shared ( t : * TyDesc ,
59- v : * * raw :: VecRepr ,
60- n : libc:: size_t ) ;
6157 #[ fast_ffi]
6258 unsafe fn vec_reserve_shared_actual ( t : * TyDesc ,
6359 v : * * raw :: VecRepr ,
@@ -1523,13 +1519,16 @@ impl<T> OwnedVector<T> for ~[T] {
15231519 use managed;
15241520 if self . capacity( ) < n {
15251521 unsafe {
1526- let ptr: * * raw :: VecRepr = cast:: transmute( self ) ;
1522+ let ptr: * mut * mut raw:: VecRepr = cast:: transmute( self ) ;
15271523 let td = get_tydesc :: < T > ( ) ;
15281524 if ( ( * * ptr) . box_header. ref_count ==
15291525 managed:: raw:: RC_MANAGED_UNIQUE ) {
1530- rustrt:: vec_reserve_shared_actual( td, ptr, n as libc:: size_t) ;
1526+ rustrt:: vec_reserve_shared_actual( td, ptr as * * raw :: VecRepr , n as libc:: size_t) ;
15311527 } else {
1532- rustrt:: vec_reserve_shared( td, ptr, n as libc:: size_t) ;
1528+ let alloc = n * sys:: nonzero_size_of:: < T > ( ) ;
1529+ * ptr = realloc_raw( * ptr as * mut c_void, alloc + size_of :: < raw:: VecRepr > ( ) )
1530+ as * mut raw:: VecRepr ;
1531+ ( * * ptr) . unboxed. alloc = alloc;
15331532 }
15341533 }
15351534 }
@@ -1551,12 +1550,15 @@ impl<T> OwnedVector<T> for ~[T] {
15511550 // Only make the (slow) call into the runtime if we have to
15521551 if self . capacity( ) < n {
15531552 unsafe {
1554- let ptr: * * raw :: VecRepr = cast:: transmute( self ) ;
1553+ let ptr: * mut * mut raw:: VecRepr = cast:: transmute( self ) ;
15551554 let td = get_tydesc :: < T > ( ) ;
15561555 if contains_managed :: < T > ( ) {
1557- rustrt:: vec_reserve_shared_actual( td, ptr, n as libc:: size_t) ;
1556+ rustrt:: vec_reserve_shared_actual( td, ptr as * * raw :: VecRepr , n as libc:: size_t) ;
15581557 } else {
1559- rustrt:: vec_reserve_shared( td, ptr, n as libc:: size_t) ;
1558+ let alloc = n * sys:: nonzero_size_of:: < T > ( ) ;
1559+ * ptr = realloc_raw( * ptr as * mut c_void, alloc + size_of :: < raw:: VecRepr > ( ) )
1560+ as * mut raw:: VecRepr ;
1561+ ( * * ptr) . unboxed. alloc = alloc;
15601562 }
15611563 }
15621564 }
0 commit comments