@@ -11,8 +11,9 @@ use rustc_data_structures::sorted_map::SortedMap;
1111use rustc_target:: abi:: { Align , HasDataLayout , Size } ;
1212
1313use super :: {
14- read_target_uint, write_target_uint, AllocId , InterpError , Pointer , Scalar , ScalarMaybeUninit ,
15- UndefinedBehaviorInfo , UninitBytesAccess , UnsupportedOpInfo ,
14+ read_target_uint, write_target_uint, AllocId , InterpError , InterpResult , Pointer ,
15+ ResourceExhaustionInfo , Scalar , ScalarMaybeUninit , UndefinedBehaviorInfo , UninitBytesAccess ,
16+ UnsupportedOpInfo ,
1617} ;
1718
1819/// This type represents an Allocation in the Miri/CTFE core engine.
@@ -121,15 +122,23 @@ impl<Tag> Allocation<Tag> {
121122 Allocation :: from_bytes ( slice, Align :: ONE , Mutability :: Not )
122123 }
123124
124- pub fn uninit ( size : Size , align : Align ) -> Self {
125- Allocation {
126- bytes : vec ! [ 0 ; size. bytes_usize( ) ] ,
125+ /// Try to create an Allocation of `size` bytes, failing if there is not enough memory
126+ /// available to the compiler to do so.
127+ pub fn uninit ( size : Size , align : Align ) -> InterpResult < ' static , Self > {
128+ let mut bytes = Vec :: new ( ) ;
129+ bytes. try_reserve ( size. bytes_usize ( ) ) . map_err ( |_| {
130+ InterpError :: ResourceExhaustion ( ResourceExhaustionInfo :: MemoryExhausted )
131+ } ) ?;
132+ bytes. resize ( size. bytes_usize ( ) , 0 ) ;
133+ bytes. fill ( 0 ) ;
134+ Ok ( Allocation {
135+ bytes : bytes,
127136 relocations : Relocations :: new ( ) ,
128137 init_mask : InitMask :: new ( size, false ) ,
129138 align,
130139 mutability : Mutability :: Mut ,
131140 extra : ( ) ,
132- }
141+ } )
133142 }
134143}
135144
0 commit comments