@@ -58,7 +58,7 @@ use core::kinds::marker::{ContravariantLifetime, InvariantType};
5858use core:: mem;
5959use core:: num:: { Int , UnsignedInt } ;
6060use core:: ops;
61- use core:: ptr;
61+ use core:: ptr:: { mod , OwnedPtr } ;
6262use core:: raw:: Slice as RawSlice ;
6363use core:: uint;
6464
@@ -133,7 +133,7 @@ use slice::CloneSliceExt;
133133#[ unsafe_no_drop_flag]
134134#[ stable]
135135pub struct Vec < T > {
136- ptr : * mut T ,
136+ ptr : OwnedPtr < T > ,
137137 len : uint ,
138138 cap : uint ,
139139}
@@ -176,7 +176,7 @@ impl<T> Vec<T> {
176176 // non-null value which is fine since we never call deallocate on the ptr
177177 // if cap is 0. The reason for this is because the pointer of a slice
178178 // being NULL would break the null pointer optimization for enums.
179- Vec { ptr : EMPTY as * mut T , len : 0 , cap : 0 }
179+ Vec { ptr : OwnedPtr ( EMPTY as * mut T ) , len : 0 , cap : 0 }
180180 }
181181
182182 /// Constructs a new, empty `Vec<T>` with the specified capacity.
@@ -209,15 +209,15 @@ impl<T> Vec<T> {
209209 #[ stable]
210210 pub fn with_capacity ( capacity : uint ) -> Vec < T > {
211211 if mem:: size_of :: < T > ( ) == 0 {
212- Vec { ptr : EMPTY as * mut T , len : 0 , cap : uint:: MAX }
212+ Vec { ptr : OwnedPtr ( EMPTY as * mut T ) , len : 0 , cap : uint:: MAX }
213213 } else if capacity == 0 {
214214 Vec :: new ( )
215215 } else {
216216 let size = capacity. checked_mul ( mem:: size_of :: < T > ( ) )
217217 . expect ( "capacity overflow" ) ;
218218 let ptr = unsafe { allocate ( size, mem:: min_align_of :: < T > ( ) ) } ;
219219 if ptr. is_null ( ) { :: alloc:: oom ( ) }
220- Vec { ptr : ptr as * mut T , len : 0 , cap : capacity }
220+ Vec { ptr : OwnedPtr ( ptr as * mut T ) , len : 0 , cap : capacity }
221221 }
222222 }
223223
@@ -284,7 +284,7 @@ impl<T> Vec<T> {
284284 #[ unstable = "needs finalization" ]
285285 pub unsafe fn from_raw_parts ( ptr : * mut T , length : uint ,
286286 capacity : uint ) -> Vec < T > {
287- Vec { ptr : ptr, len : length, cap : capacity }
287+ Vec { ptr : OwnedPtr ( ptr) , len : length, cap : capacity }
288288 }
289289
290290 /// Creates a vector by copying the elements from a raw pointer.
@@ -795,19 +795,19 @@ impl<T> Vec<T> {
795795 if self . len == 0 {
796796 if self . cap != 0 {
797797 unsafe {
798- dealloc ( self . ptr , self . cap )
798+ dealloc ( self . ptr . 0 , self . cap )
799799 }
800800 self . cap = 0 ;
801801 }
802802 } else {
803803 unsafe {
804804 // Overflow check is unnecessary as the vector is already at
805805 // least this large.
806- self . ptr = reallocate ( self . ptr as * mut u8 ,
807- self . cap * mem:: size_of :: < T > ( ) ,
808- self . len * mem:: size_of :: < T > ( ) ,
809- mem:: min_align_of :: < T > ( ) ) as * mut T ;
810- if self . ptr . is_null ( ) { :: alloc:: oom ( ) }
806+ self . ptr = OwnedPtr ( reallocate ( self . ptr . 0 as * mut u8 ,
807+ self . cap * mem:: size_of :: < T > ( ) ,
808+ self . len * mem:: size_of :: < T > ( ) ,
809+ mem:: min_align_of :: < T > ( ) ) as * mut T ) ;
810+ if self . ptr . 0 . is_null ( ) { :: alloc:: oom ( ) }
811811 }
812812 self . cap = self . len ;
813813 }
@@ -867,7 +867,7 @@ impl<T> Vec<T> {
867867 pub fn as_mut_slice < ' a > ( & ' a mut self ) -> & ' a mut [ T ] {
868868 unsafe {
869869 mem:: transmute ( RawSlice {
870- data : self . ptr as * const T ,
870+ data : self . ptr . 0 as * const T ,
871871 len : self . len ,
872872 } )
873873 }
@@ -890,9 +890,9 @@ impl<T> Vec<T> {
890890 #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
891891 pub fn into_iter ( self ) -> IntoIter < T > {
892892 unsafe {
893- let ptr = self . ptr ;
893+ let ptr = self . ptr . 0 ;
894894 let cap = self . cap ;
895- let begin = self . ptr as * const T ;
895+ let begin = self . ptr . 0 as * const T ;
896896 let end = if mem:: size_of :: < T > ( ) == 0 {
897897 ( ptr as uint + self . len ( ) ) as * const T
898898 } else {
@@ -1110,14 +1110,14 @@ impl<T> Vec<T> {
11101110 let size = max ( old_size, 2 * mem:: size_of :: < T > ( ) ) * 2 ;
11111111 if old_size > size { panic ! ( "capacity overflow" ) }
11121112 unsafe {
1113- self . ptr = alloc_or_realloc ( self . ptr , old_size, size) ;
1114- if self . ptr . is_null ( ) { :: alloc:: oom ( ) }
1113+ self . ptr = OwnedPtr ( alloc_or_realloc ( self . ptr . 0 , old_size, size) ) ;
1114+ if self . ptr . 0 . is_null ( ) { :: alloc:: oom ( ) }
11151115 }
11161116 self . cap = max ( self . cap , 2 ) * 2 ;
11171117 }
11181118
11191119 unsafe {
1120- let end = ( self . ptr as * const T ) . offset ( self . len as int ) as * mut T ;
1120+ let end = self . ptr . 0 . offset ( self . len as int ) ;
11211121 ptr:: write ( & mut * end, value) ;
11221122 self . len += 1 ;
11231123 }
@@ -1162,11 +1162,11 @@ impl<T> Vec<T> {
11621162 #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
11631163 pub fn drain < ' a > ( & ' a mut self ) -> Drain < ' a , T > {
11641164 unsafe {
1165- let begin = self . ptr as * const T ;
1165+ let begin = self . ptr . 0 as * const T ;
11661166 let end = if mem:: size_of :: < T > ( ) == 0 {
1167- ( self . ptr as uint + self . len ( ) ) as * const T
1167+ ( self . ptr . 0 as uint + self . len ( ) ) as * const T
11681168 } else {
1169- self . ptr . offset ( self . len ( ) as int ) as * const T
1169+ self . ptr . 0 . offset ( self . len ( ) as int ) as * const T
11701170 } ;
11711171 self . set_len ( 0 ) ;
11721172 Drain {
@@ -1231,8 +1231,10 @@ impl<T> Vec<T> {
12311231 let size = capacity. checked_mul ( mem:: size_of :: < T > ( ) )
12321232 . expect ( "capacity overflow" ) ;
12331233 unsafe {
1234- self . ptr = alloc_or_realloc ( self . ptr , self . cap * mem:: size_of :: < T > ( ) , size) ;
1235- if self . ptr . is_null ( ) { :: alloc:: oom ( ) }
1234+ self . ptr = OwnedPtr ( alloc_or_realloc ( self . ptr . 0 ,
1235+ self . cap * mem:: size_of :: < T > ( ) ,
1236+ size) ) ;
1237+ if self . ptr . 0 . is_null ( ) { :: alloc:: oom ( ) }
12361238 }
12371239 self . cap = capacity;
12381240 }
@@ -1355,7 +1357,7 @@ impl<T> AsSlice<T> for Vec<T> {
13551357 fn as_slice < ' a > ( & ' a self ) -> & ' a [ T ] {
13561358 unsafe {
13571359 mem:: transmute ( RawSlice {
1358- data : self . ptr as * const T ,
1360+ data : self . ptr . 0 as * const T ,
13591361 len : self . len
13601362 } )
13611363 }
@@ -1380,7 +1382,7 @@ impl<T> Drop for Vec<T> {
13801382 for x in self . iter ( ) {
13811383 ptr:: read ( x) ;
13821384 }
1383- dealloc ( self . ptr , self . cap )
1385+ dealloc ( self . ptr . 0 , self . cap )
13841386 }
13851387 }
13861388 }
@@ -1418,7 +1420,7 @@ impl<T> IntoIter<T> {
14181420 for _x in self { }
14191421 let IntoIter { allocation, cap, ptr : _ptr, end : _end } = self ;
14201422 mem:: forget ( self ) ;
1421- Vec { ptr : allocation, cap : cap, len : 0 }
1423+ Vec { ptr : OwnedPtr ( allocation) , cap : cap, len : 0 }
14221424 }
14231425 }
14241426
0 commit comments