@@ -245,6 +245,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
245
245
/// as a slice.
246
246
///
247
247
/// It is the caller's responsibility to check bounds and alignment beforehand.
248
+ /// Most likely, you want to use the `PlaceTy` and `OperandTy`-based methods
249
+ /// on `InterpCx` instead.
248
250
#[ inline]
249
251
pub fn get_bytes (
250
252
& self ,
@@ -275,6 +277,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
275
277
/// so be sure to actually put data there!
276
278
///
277
279
/// It is the caller's responsibility to check bounds and alignment beforehand.
280
+ /// Most likely, you want to use the `PlaceTy` and `OperandTy`-based methods
281
+ /// on `InterpCx` instead.
278
282
pub fn get_bytes_mut (
279
283
& mut self ,
280
284
cx : & impl HasDataLayout ,
@@ -297,6 +301,8 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
297
301
impl < ' tcx , Tag : Copy , Extra : AllocationExtra < Tag > > Allocation < Tag , Extra > {
298
302
/// Reads bytes until a `0` is encountered. Will error if the end of the allocation is reached
299
303
/// before a `0` is found.
304
+ ///
305
+ /// Most likely, you want to call `Memory::read_c_str` instead of this method.
300
306
pub fn read_c_str (
301
307
& self ,
302
308
cx : & impl HasDataLayout ,
@@ -342,33 +348,22 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
342
348
/// Writes `src` to the memory starting at `ptr.offset`.
343
349
///
344
350
/// It is the caller's responsibility to check bounds and alignment beforehand.
351
+ /// Most likely, you want to call `Memory::write_bytes` instead of this method.
345
352
pub fn write_bytes (
346
353
& mut self ,
347
354
cx : & impl HasDataLayout ,
348
355
ptr : Pointer < Tag > ,
349
- src : & [ u8 ] ,
356
+ src : impl IntoIterator < Item = u8 , IntoIter : iter :: ExactSizeIterator > ,
350
357
) -> InterpResult < ' tcx >
351
358
{
359
+ let mut src = src. into_iter ( ) ;
352
360
let bytes = self . get_bytes_mut ( cx, ptr, Size :: from_bytes ( src. len ( ) as u64 ) ) ?;
353
- bytes. clone_from_slice ( src) ;
354
- Ok ( ( ) )
355
- }
356
-
357
- /// Sets `count` bytes starting at `ptr.offset` with `val`. Basically `memset`.
358
- ///
359
- /// It is the caller's responsibility to check bounds and alignment beforehand.
360
- pub fn write_repeat (
361
- & mut self ,
362
- cx : & impl HasDataLayout ,
363
- ptr : Pointer < Tag > ,
364
- val : u8 ,
365
- count : Size
366
- ) -> InterpResult < ' tcx >
367
- {
368
- let bytes = self . get_bytes_mut ( cx, ptr, count) ?;
369
- for b in bytes {
370
- * b = val;
361
+ // `zip` would stop when the first iterator ends; we want to definitely
362
+ // cover all of `bytes`.
363
+ for dest in bytes {
364
+ * dest = src. next ( ) . expect ( "iterator was shorter than it said it would be" ) ;
371
365
}
366
+ src. next ( ) . expect_none ( "iterator was longer than it said it would be" ) ;
372
367
Ok ( ( ) )
373
368
}
374
369
@@ -380,6 +375,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
380
375
/// pointers being valid for ZSTs.
381
376
///
382
377
/// It is the caller's responsibility to check bounds and alignment beforehand.
378
+ /// Most likely, you want to call `InterpCx::read_scalar` instead of this method.
383
379
pub fn read_scalar (
384
380
& self ,
385
381
cx : & impl HasDataLayout ,
@@ -418,6 +414,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
418
414
/// Reads a pointer-sized scalar.
419
415
///
420
416
/// It is the caller's responsibility to check bounds and alignment beforehand.
417
+ /// Most likely, you want to call `InterpCx::read_scalar` instead of this method.
421
418
pub fn read_ptr_sized (
422
419
& self ,
423
420
cx : & impl HasDataLayout ,
@@ -435,6 +432,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
435
432
/// pointers being valid for ZSTs.
436
433
///
437
434
/// It is the caller's responsibility to check bounds and alignment beforehand.
435
+ /// Most likely, you want to call `InterpCx::write_scalar` instead of this method.
438
436
pub fn write_scalar (
439
437
& mut self ,
440
438
cx : & impl HasDataLayout ,
@@ -477,6 +475,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
477
475
/// Writes a pointer-sized scalar.
478
476
///
479
477
/// It is the caller's responsibility to check bounds and alignment beforehand.
478
+ /// Most likely, you want to call `InterpCx::write_scalar` instead of this method.
480
479
pub fn write_ptr_sized (
481
480
& mut self ,
482
481
cx : & impl HasDataLayout ,
0 commit comments