@@ -22,12 +22,14 @@ use iterator::{FromIterator, Iterator, IteratorUtil};
22
22
use iter:: FromIter ;
23
23
use kinds:: Copy ;
24
24
use libc;
25
+ use libc:: c_void;
25
26
use num:: Zero ;
26
27
use ops:: Add ;
27
28
use option:: { None , Option , Some } ;
28
29
use ptr:: to_unsafe_ptr;
29
30
use ptr;
30
31
use ptr:: RawPtr ;
32
+ use rt:: global_heap:: realloc_raw;
31
33
use sys;
32
34
use sys:: size_of;
33
35
use uint;
@@ -52,12 +54,6 @@ pub mod rustrt {
52
54
53
55
#[ abi = "cdecl" ]
54
56
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 ) ;
61
57
#[ fast_ffi]
62
58
unsafe fn vec_reserve_shared_actual ( t : * TyDesc ,
63
59
v : * * raw :: VecRepr ,
@@ -1523,13 +1519,16 @@ impl<T> OwnedVector<T> for ~[T] {
1523
1519
use managed;
1524
1520
if self . capacity( ) < n {
1525
1521
unsafe {
1526
- let ptr: * * raw :: VecRepr = cast:: transmute( self ) ;
1522
+ let ptr: * mut * mut raw:: VecRepr = cast:: transmute( self ) ;
1527
1523
let td = get_tydesc :: < T > ( ) ;
1528
1524
if ( ( * * ptr) . box_header. ref_count ==
1529
1525
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) ;
1531
1527
} 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;
1533
1532
}
1534
1533
}
1535
1534
}
@@ -1551,12 +1550,15 @@ impl<T> OwnedVector<T> for ~[T] {
1551
1550
// Only make the (slow) call into the runtime if we have to
1552
1551
if self . capacity( ) < n {
1553
1552
unsafe {
1554
- let ptr: * * raw :: VecRepr = cast:: transmute( self ) ;
1553
+ let ptr: * mut * mut raw:: VecRepr = cast:: transmute( self ) ;
1555
1554
let td = get_tydesc :: < T > ( ) ;
1556
1555
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) ;
1558
1557
} 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;
1560
1562
}
1561
1563
}
1562
1564
}
0 commit comments