Skip to content

Commit 5222c08

Browse files
committed
Rename set_last_error_from_io_result
1 parent 86b5be5 commit 5222c08

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/helpers.rs

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

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

393393
/// Helper function that consumes an `std::io::Result<T>` and returns an
394-
/// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
395-
/// OS error using `std::io::Error::raw_os_error`.
394+
/// `InterpResult<'tcx,T>::Ok` instead. In case the result is an error, this function returns
395+
/// `Ok(-1)` and sets the last OS error accordingly.
396396
///
397397
/// This function uses `T: From<i32>` instead of `i32` directly because some IO related
398398
/// functions return different integer types (like `read`, that returns an `i64`)
399-
fn set_last_error_from_io_result<T: From<i32>>(
399+
fn try_unwrap_io_result<T: From<i32>>(
400400
&mut self,
401401
result: std::io::Result<T>,
402402
) -> 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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
107107
fh.low
108108
});
109109

110-
this.set_last_error_from_io_result(fd)
110+
this.try_unwrap_io_result(fd)
111111
}
112112

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

145145
this.remove_handle_and(fd, |handle, this| {
146-
this.set_last_error_from_io_result(handle.file.sync_all().map(|_| 0i32))
146+
this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32))
147147
})
148148
}
149149

@@ -176,7 +176,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
176176
});
177177
// Reinsert the file handle
178178
this.machine.file_handler.handles.insert(fd, handle);
179-
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))
180180
})
181181
}
182182

@@ -205,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
205205
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
206206
});
207207
this.machine.file_handler.handles.insert(fd, handle);
208-
this.set_last_error_from_io_result(bytes?)
208+
this.try_unwrap_io_result(bytes?)
209209
})
210210
}
211211

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

223223
let result = remove_file(path).map(|_| 0);
224224

225-
this.set_last_error_from_io_result(result)
225+
this.try_unwrap_io_result(result)
226226
}
227227

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

0 commit comments

Comments
 (0)