about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-06-30 23:49:37 +0200
committerRalf Jung <post@ralfj.de>2019-07-01 00:16:26 +0200
commit05f4a574f6409c932475aea0f95b6d8adfe4222b (patch)
treebee4a59df26ddd3b41c7808b7496f2e20d6ce98f
parent0af8e872ea5ac77effa59f8d3f8794f12cb8865c (diff)
forward read_c_str method from Memory to Alloc
-rw-r--r--src/librustc_mir/interpret/memory.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index c3eec677a48..f7610707880 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -677,6 +677,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,
@@ -690,6 +692,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,