Rename set_last_error_from_io_result

This commit is contained in:
Christian Poveda 2019-10-18 14:33:25 -05:00
parent 5c3c738c4b
commit 619ccf3834
3 changed files with 11 additions and 12 deletions

View File

@ -360,8 +360,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.read_scalar(errno_place.into())?.not_undef()
}
/// Sets the last error variable using a `std::io::Error`. It fails if the error cannot be
/// transformed to a raw os error succesfully.
/// Sets the last OS error using a `std::io::Error`. This function tries to produce the most
/// similar OS error from the `std::io::ErrorKind` and sets it as the last OS error.
fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
use std::io::ErrorKind::*;
let this = self.eval_context_mut();
@ -392,12 +392,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
/// Helper function that consumes an `std::io::Result<T>` and returns an
/// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
/// OS error using `std::io::Error::raw_os_error`.
/// `InterpResult<'tcx,T>::Ok` instead. In case the result is an error, this function returns
/// `Ok(-1)` and sets the last OS error accordingly.
///
/// This function uses `T: From<i32>` instead of `i32` directly because some IO related
/// functions return different integer types (like `read`, that returns an `i64`)
fn set_last_error_from_io_result<T: From<i32>>(
fn try_unwrap_io_result<T: From<i32>>(
&mut self,
result: std::io::Result<T>,
) -> InterpResult<'tcx, T> {

View File

@ -91,7 +91,7 @@ pub struct Evaluator<'tcx> {
pub(crate) argv: Option<Pointer<Tag>>,
pub(crate) cmd_line: Option<Pointer<Tag>>,
/// Last OS error location in memory. It is a 32 bits integer (unsigned for Windows)
/// Last OS error location in memory. It is a 32 bit integer (unsigned for Windows)
pub(crate) last_error: Option<MPlaceTy<'tcx, Tag>>,
/// TLS state.

View File

@ -108,7 +108,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fh.low
});
this.set_last_error_from_io_result(fd)
this.try_unwrap_io_result(fd)
}
fn fcntl(
@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let fd = this.read_scalar(fd_op)?.to_i32()?;
this.remove_handle_and(fd, |handle, this| {
this.set_last_error_from_io_result(handle.file.sync_all().map(|_| 0i32))
this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32))
})
}
@ -175,9 +175,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
.get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
.map(|buffer| handle.file.read(buffer))
});
// Reinsert the file handle
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
this.set_last_error_from_io_result(bytes?.map(|bytes| bytes as i64))
this.try_unwrap_io_result(bytes?.map(|bytes| bytes as i64))
})
}
@ -206,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
});
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
this.set_last_error_from_io_result(bytes?)
this.try_unwrap_io_result(bytes?)
})
}
@ -223,7 +222,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let result = remove_file(path).map(|_| 0);
this.set_last_error_from_io_result(result)
this.try_unwrap_io_result(result)
}
/// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it