Skip to content

Commit 619ccf3

Browse files
committed
Rename set_last_error_from_io_result
1 parent 5c3c738 commit 619ccf3

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/helpers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
360360
this.read_scalar(errno_place.into())?.not_undef()
361361
}
362362

363-
/// Sets the last error variable using a `std::io::Error`. It fails if the error cannot be
364-
/// transformed to a raw os error succesfully.
363+
/// Sets the last OS error using a `std::io::Error`. This function tries to produce the most
364+
/// similar OS error from the `std::io::ErrorKind` and sets it as the last OS error.
365365
fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
366366
use std::io::ErrorKind::*;
367367
let this = self.eval_context_mut();
@@ -392,12 +392,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
392392
}
393393

394394
/// Helper function that consumes an `std::io::Result<T>` and returns an
395-
/// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
396-
/// OS error using `std::io::Error::raw_os_error`.
395+
/// `InterpResult<'tcx,T>::Ok` instead. In case the result is an error, this function returns
396+
/// `Ok(-1)` and sets the last OS error accordingly.
397397
///
398398
/// This function uses `T: From<i32>` instead of `i32` directly because some IO related
399399
/// functions return different integer types (like `read`, that returns an `i64`)
400-
fn set_last_error_from_io_result<T: From<i32>>(
400+
fn try_unwrap_io_result<T: From<i32>>(
401401
&mut self,
402402
result: std::io::Result<T>,
403403
) -> InterpResult<'tcx, T> {

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct Evaluator<'tcx> {
9191
pub(crate) argv: Option<Pointer<Tag>>,
9292
pub(crate) cmd_line: Option<Pointer<Tag>>,
9393

94-
/// Last OS error location in memory. It is a 32 bits integer (unsigned for Windows)
94+
/// Last OS error location in memory. It is a 32 bit integer (unsigned for Windows)
9595
pub(crate) last_error: Option<MPlaceTy<'tcx, Tag>>,
9696

9797
/// TLS state.

src/shims/fs.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
108108
fh.low
109109
});
110110

111-
this.set_last_error_from_io_result(fd)
111+
this.try_unwrap_io_result(fd)
112112
}
113113

114114
fn fcntl(
@@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
144144
let fd = this.read_scalar(fd_op)?.to_i32()?;
145145

146146
this.remove_handle_and(fd, |handle, this| {
147-
this.set_last_error_from_io_result(handle.file.sync_all().map(|_| 0i32))
147+
this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32))
148148
})
149149
}
150150

@@ -175,9 +175,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
175175
.get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
176176
.map(|buffer| handle.file.read(buffer))
177177
});
178-
// Reinsert the file handle
179178
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
180-
this.set_last_error_from_io_result(bytes?.map(|bytes| bytes as i64))
179+
this.try_unwrap_io_result(bytes?.map(|bytes| bytes as i64))
181180
})
182181
}
183182

@@ -206,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
206205
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
207206
});
208207
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
209-
this.set_last_error_from_io_result(bytes?)
208+
this.try_unwrap_io_result(bytes?)
210209
})
211210
}
212211

@@ -223,7 +222,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
223222

224223
let result = remove_file(path).map(|_| 0);
225224

226-
this.set_last_error_from_io_result(result)
225+
this.try_unwrap_io_result(result)
227226
}
228227

229228
/// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it

0 commit comments

Comments
 (0)