@@ -40,9 +40,16 @@ pub trait AllocBytes: Clone + fmt::Debug + Deref<Target = [u8]> + DerefMut<Targe
40
40
/// Gives direct access to the raw underlying storage.
41
41
///
42
42
/// Crucially this pointer is compatible with:
43
- /// - other pointers retunred by this method, and
43
+ /// - other pointers returned by this method, and
44
44
/// - references returned from `deref()`, as long as there was no write.
45
45
fn as_mut_ptr ( & mut self ) -> * mut u8 ;
46
+
47
+ /// Gives direct access to the raw underlying storage.
48
+ ///
49
+ /// Crucially this pointer is compatible with:
50
+ /// - other pointers returned by this method, and
51
+ /// - references returned from `deref()`, as long as there was no write.
52
+ fn as_ptr ( & self ) -> * const u8 ;
46
53
}
47
54
48
55
/// Default `bytes` for `Allocation` is a `Box<u8>`.
@@ -62,6 +69,11 @@ impl AllocBytes for Box<[u8]> {
62
69
// Carefully avoiding any intermediate references.
63
70
ptr:: addr_of_mut!( * * self ) . cast ( )
64
71
}
72
+
73
+ fn as_ptr ( & self ) -> * const u8 {
74
+ // Carefully avoiding any intermediate references.
75
+ ptr:: addr_of!( * * self ) . cast ( )
76
+ }
65
77
}
66
78
67
79
/// This type represents an Allocation in the Miri/CTFE core engine.
@@ -490,19 +502,27 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
490
502
self . provenance . clear ( range, cx) ?;
491
503
492
504
assert ! ( range. end( ) . bytes_usize( ) <= self . bytes. len( ) ) ; // need to do our own bounds-check
493
- // Cruciall , we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
505
+ // Crucially , we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`.
494
506
let begin_ptr = self . bytes . as_mut_ptr ( ) . wrapping_add ( range. start . bytes_usize ( ) ) ;
495
507
let len = range. end ( ) . bytes_usize ( ) - range. start . bytes_usize ( ) ;
496
508
Ok ( ptr:: slice_from_raw_parts_mut ( begin_ptr, len) )
497
509
}
498
510
499
511
/// This gives direct mutable access to the entire buffer, just exposing their internal state
500
- /// without reseting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
512
+ /// without resetting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if
501
513
/// `OFFSET_IS_ADDR` is true.
502
514
pub fn get_bytes_unchecked_raw_mut ( & mut self ) -> * mut u8 {
503
515
assert ! ( Prov :: OFFSET_IS_ADDR ) ;
504
516
self . bytes . as_mut_ptr ( )
505
517
}
518
+
519
+ /// This gives direct immutable access to the entire buffer, just exposing their internal state
520
+ /// without resetting anything. Directly exposes `AllocBytes::as_ptr`. Only works if
521
+ /// `OFFSET_IS_ADDR` is true.
522
+ pub fn get_bytes_unchecked_raw ( & self ) -> * const u8 {
523
+ assert ! ( Prov :: OFFSET_IS_ADDR ) ;
524
+ self . bytes . as_ptr ( )
525
+ }
506
526
}
507
527
508
528
/// Reading and writing.
0 commit comments