From 3386f12eca5db75ee679c5d08fecec88ae99e6a0 Mon Sep 17 00:00:00 2001 From: Samrat Man Singh Date: Mon, 3 Aug 2020 11:01:42 +0530 Subject: [PATCH] Wrap io::Result from `FileDescriptor::{read,write,seek}` in InterpResult The outer InterpResult will be used to indicate that a fn is not implemented for a struct(eg. `write` for Stdin). The inner io::Result is just the result from the read/write/seek. --- src/shims/posix/fs.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index 5415e9e1f77..6f46401ece6 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -25,9 +25,9 @@ struct FileHandle { trait FileDescriptor<'tcx> : std::fmt::Debug { fn as_file_handle(&self) -> InterpResult<'tcx, &FileHandle>; - fn read(&mut self, bytes: &mut [u8]) -> Result; - fn write(&mut self, bytes: &[u8]) -> Result; - fn seek(&mut self, offset: SeekFrom) -> Result; + fn read(&mut self, bytes: &mut [u8]) -> InterpResult<'tcx, io::Result>; + fn write(&mut self, bytes: &[u8]) -> InterpResult<'tcx, io::Result>; + fn seek(&mut self, offset: SeekFrom) -> InterpResult<'tcx, io::Result>; } impl<'tcx> FileDescriptor<'tcx> for FileHandle { @@ -35,16 +35,16 @@ fn as_file_handle(&self) -> InterpResult<'tcx, &FileHandle> { Ok(&self) } - fn read(&mut self, bytes: &mut [u8]) -> Result { - self.file.read(bytes) + fn read(&mut self, bytes: &mut [u8]) -> InterpResult<'tcx, io::Result> { + Ok(self.file.read(bytes)) } - fn write(&mut self, bytes: &[u8]) -> Result { - self.file.write(bytes) + fn write(&mut self, bytes: &[u8]) -> InterpResult<'tcx, io::Result> { + Ok(self.file.write(bytes)) } - fn seek(&mut self, offset: SeekFrom) -> Result { - self.file.seek(offset) + fn seek(&mut self, offset: SeekFrom) -> InterpResult<'tcx, io::Result> { + Ok(self.file.seek(offset)) } } @@ -509,7 +509,7 @@ fn read( // `File::read` never returns a value larger than `count`, // so this cannot fail. let result = file_descriptor - .read(&mut bytes) + .read(&mut bytes)? .map(|c| i64::try_from(c).unwrap()); match result { @@ -554,7 +554,7 @@ fn write( if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) { let bytes = this.memory.read_bytes(buf, Size::from_bytes(count))?; let result = file_descriptor - .write(&bytes) + .write(&bytes)? .map(|c| i64::try_from(c).unwrap()); this.try_unwrap_io_result(result) } else { @@ -590,7 +590,7 @@ fn lseek64( if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) { let result = file_descriptor - .seek(seek_from) + .seek(seek_from)? .map(|offset| i64::try_from(offset).unwrap()); this.try_unwrap_io_result(result) } else { -- 2.44.0