Skip to content

Commit

Permalink
Rollup merge of rust-lang#62257 - RalfJung:miri-c-str, r=estebank
Browse files Browse the repository at this point in the history
forward read_c_str method from Memory to Alloc

This is more convenient to call when one starts with a `Scalar` (which is the common case).

`read_c_str` is only used in Miri.
  • Loading branch information
Centril authored Jul 6, 2019
2 parents 182248a + 05f4a57 commit 947d7cf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {

/// Reading and writing.
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
/// Reads the given number of bytes from memory. Returns them as a slice.
///
/// Performs appropriate bounds checks.
pub fn read_bytes(
&self,
Expand All @@ -741,6 +743,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
}

/// Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.
///
/// Performs appropriate bounds checks.
pub fn read_c_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, &[u8]> {
let ptr = self.force_ptr(ptr)?; // We need to read at least 1 byte, so we *need* a ptr.
self.get(ptr.alloc_id)?.read_c_str(self, ptr)
}

/// Performs appropriate bounds checks.
pub fn copy(
&mut self,
Expand Down

0 comments on commit 947d7cf

Please sign in to comment.