File tree Expand file tree Collapse file tree 4 files changed +10
-6
lines changed
starlark/src/values/layout Expand file tree Collapse file tree 4 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -163,11 +163,12 @@ pub(crate) trait AValue<'v>: StarlarkValueDyn<'v> + Sized {
163163 Self :: offset_of_extra( ) % mem:: align_of:: <Self :: ExtraElem >( ) == 0 ,
164164 "extra must be aligned"
165165 ) ;
166- cmp:: max (
166+ let size = cmp:: max (
167167 mem:: size_of :: < Self :: StarlarkValue > ( ) ,
168168 // Content is not necessarily aligned to end of `A`.
169169 Self :: offset_of_extra ( ) + ( mem:: size_of :: < Self :: ExtraElem > ( ) * extra_len) ,
170- )
170+ ) ;
171+ AValueHeader :: align_up ( size)
171172 }
172173
173174 unsafe fn heap_freeze (
Original file line number Diff line number Diff line change @@ -132,8 +132,6 @@ impl<'c> Iterator for ChunkIter<'c> {
132132 let or_forward = & * ( self . chunk . as_ptr ( ) as * const AValueOrForward ) ;
133133 let n = or_forward. alloc_size ( ) ;
134134 debug_assert ! ( n <= self . chunk. len( ) ) ;
135- let n = AValueHeader :: align_up ( n) ;
136- let n = cmp:: min ( n, self . chunk . len ( ) ) ;
137135 self . chunk = self . chunk . split_at ( n) . 1 ;
138136 Some ( or_forward)
139137 }
@@ -174,6 +172,7 @@ impl Arena {
174172 mem:: size_of :: < AValueHeader > ( ) + T :: memory_size_for_extra_len ( extra_len) ,
175173 MIN_ALLOC ,
176174 ) ;
175+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
177176 let layout = Layout :: from_size_align ( size, mem:: align_of :: < AValueHeader > ( ) ) . unwrap ( ) ;
178177 let p = bump. alloc_layout ( layout) . as_ptr ( ) ;
179178 unsafe {
Original file line number Diff line number Diff line change @@ -179,7 +179,9 @@ impl AValueOrForward {
179179 }
180180 } ;
181181 let n = mem:: size_of :: < AValueHeader > ( ) + n;
182- cmp:: max ( n, MIN_ALLOC )
182+ let size = cmp:: max ( n, MIN_ALLOC ) ;
183+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
184+ size
183185 }
184186}
185187
Original file line number Diff line number Diff line change @@ -223,7 +223,9 @@ pub(crate) struct AValueDyn<'v> {
223223impl < ' v > AValueDyn < ' v > {
224224 #[ inline]
225225 pub ( crate ) fn memory_size ( self ) -> usize {
226- ( self . vtable . memory_size ) ( self . value as * const ( ) )
226+ let size = ( self . vtable . memory_size ) ( self . value as * const ( ) ) ;
227+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
228+ size
227229 }
228230
229231 pub ( crate ) fn total_memory ( self ) -> usize {
You can’t perform that action at this time.
0 commit comments