@@ -244,7 +244,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
244244 let new_ptr = self . allocate ( new_size, new_align, kind) ;
245245 let old_size = match old_size_and_align {
246246 Some ( ( size, _align) ) => size,
247- None => self . get_raw ( ptr. alloc_id ) ?. size ,
247+ None => self . get_raw ( ptr. alloc_id ) ?. size ( ) ,
248248 } ;
249249 self . copy ( ptr, new_ptr, old_size. min ( new_size) , /*nonoverlapping*/ true ) ?;
250250 self . deallocate ( ptr, old_size_and_align, kind) ?;
@@ -306,11 +306,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
306306 ) ;
307307 }
308308 if let Some ( ( size, align) ) = old_size_and_align {
309- if size != alloc. size || align != alloc. align {
309+ if size != alloc. size ( ) || align != alloc. align {
310310 throw_ub_format ! (
311311 "incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}" ,
312312 ptr. alloc_id,
313- alloc. size. bytes( ) ,
313+ alloc. size( ) . bytes( ) ,
314314 alloc. align. bytes( ) ,
315315 size. bytes( ) ,
316316 align. bytes( ) ,
@@ -319,11 +319,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
319319 }
320320
321321 // Let the machine take some extra action
322- let size = alloc. size ;
322+ let size = alloc. size ( ) ;
323323 AllocationExtra :: memory_deallocated ( & mut alloc, ptr, size) ?;
324324
325325 // Don't forget to remember size and align of this now-dead allocation
326- let old = self . dead_alloc_map . insert ( ptr. alloc_id , ( alloc. size , alloc. align ) ) ;
326+ let old = self . dead_alloc_map . insert ( ptr. alloc_id , ( alloc. size ( ) , alloc. align ) ) ;
327327 if old. is_some ( ) {
328328 bug ! ( "Nothing can be deallocated twice" ) ;
329329 }
@@ -586,7 +586,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
586586 // a) cause cycles in case `id` refers to a static
587587 // b) duplicate a global's allocation in miri
588588 if let Some ( ( _, alloc) ) = self . alloc_map . get ( id) {
589- return Ok ( ( alloc. size , alloc. align ) ) ;
589+ return Ok ( ( alloc. size ( ) , alloc. align ) ) ;
590590 }
591591
592592 // # Function pointers
@@ -614,7 +614,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
614614 Some ( GlobalAlloc :: Memory ( alloc) ) => {
615615 // Need to duplicate the logic here, because the global allocations have
616616 // different associated types than the interpreter-local ones.
617- Ok ( ( alloc. size , alloc. align ) )
617+ Ok ( ( alloc. size ( ) , alloc. align ) )
618618 }
619619 Some ( GlobalAlloc :: Function ( _) ) => bug ! ( "We already checked function pointers above" ) ,
620620 // The rest must be dead.
@@ -804,41 +804,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
804804 self . get_raw ( ptr. alloc_id ) ?. get_bytes ( self , ptr, size)
805805 }
806806
807- /// Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.
808- ///
809- /// Performs appropriate bounds checks.
810- pub fn read_c_str ( & self , ptr : Scalar < M :: PointerTag > ) -> InterpResult < ' tcx , & [ u8 ] > {
811- let ptr = self . force_ptr ( ptr) ?; // We need to read at least 1 byte, so we *need* a ptr.
812- self . get_raw ( ptr. alloc_id ) ?. read_c_str ( self , ptr)
813- }
814-
815- /// Reads a 0x0000-terminated u16-sequence from memory. Returns them as a Vec<u16>.
816- /// Terminator 0x0000 is not included in the returned Vec<u16>.
817- ///
818- /// Performs appropriate bounds checks.
819- pub fn read_wide_str ( & self , ptr : Scalar < M :: PointerTag > ) -> InterpResult < ' tcx , Vec < u16 > > {
820- let size_2bytes = Size :: from_bytes ( 2 ) ;
821- let align_2bytes = Align :: from_bytes ( 2 ) . unwrap ( ) ;
822- // We need to read at least 2 bytes, so we *need* a ptr.
823- let mut ptr = self . force_ptr ( ptr) ?;
824- let allocation = self . get_raw ( ptr. alloc_id ) ?;
825- let mut u16_seq = Vec :: new ( ) ;
826-
827- loop {
828- ptr = self
829- . check_ptr_access ( ptr. into ( ) , size_2bytes, align_2bytes) ?
830- . expect ( "cannot be a ZST" ) ;
831- let single_u16 = allocation. read_scalar ( self , ptr, size_2bytes) ?. to_u16 ( ) ?;
832- if single_u16 != 0x0000 {
833- u16_seq. push ( single_u16) ;
834- ptr = ptr. offset ( size_2bytes, self ) ?;
835- } else {
836- break ;
837- }
838- }
839- Ok ( u16_seq)
840- }
841-
842807 /// Writes the given stream of bytes into memory.
843808 ///
844809 /// Performs appropriate bounds checks.
@@ -866,46 +831,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
866831 self . get_raw_mut ( ptr. alloc_id ) ?. write_bytes ( & tcx, ptr, src)
867832 }
868833
869- /// Writes the given stream of u16s into memory.
870- ///
871- /// Performs appropriate bounds checks.
872- pub fn write_u16s (
873- & mut self ,
874- ptr : Scalar < M :: PointerTag > ,
875- src : impl IntoIterator < Item = u16 > ,
876- ) -> InterpResult < ' tcx > {
877- let mut src = src. into_iter ( ) ;
878- let ( lower, upper) = src. size_hint ( ) ;
879- let len = upper. expect ( "can only write bounded iterators" ) ;
880- assert_eq ! ( lower, len, "can only write iterators with a precise length" ) ;
881-
882- let size = Size :: from_bytes ( lower) ;
883- let ptr = match self . check_ptr_access ( ptr, size, Align :: from_bytes ( 2 ) . unwrap ( ) ) ? {
884- Some ( ptr) => ptr,
885- None => {
886- // zero-sized access
887- assert_matches ! (
888- src. next( ) ,
889- None ,
890- "iterator said it was empty but returned an element"
891- ) ;
892- return Ok ( ( ) ) ;
893- }
894- } ;
895- let tcx = self . tcx ;
896- let allocation = self . get_raw_mut ( ptr. alloc_id ) ?;
897-
898- for idx in 0 ..len {
899- let val = Scalar :: from_u16 (
900- src. next ( ) . expect ( "iterator was shorter than it said it would be" ) ,
901- ) ;
902- let offset_ptr = ptr. offset ( Size :: from_bytes ( idx) * 2 , & tcx) ?; // `Size` multiplication
903- allocation. write_scalar ( & tcx, offset_ptr, val. into ( ) , Size :: from_bytes ( 2 ) ) ?;
904- }
905- assert_matches ! ( src. next( ) , None , "iterator was longer than it said it would be" ) ;
906- Ok ( ( ) )
907- }
908-
909834 /// Expects the caller to have checked bounds and alignment.
910835 pub fn copy (
911836 & mut self ,
0 commit comments