@@ -151,6 +151,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
151151 )
152152 }
153153
154+ /// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it
155+ /// using `f`.
156+ ///
157+ /// If the `fd` file descriptor does not corresponds to a file, this functions returns `Ok(-1)`
158+ /// and sets `Evaluator::last_error` to `libc::EBADF` (invalid file descriptor).
159+ ///
160+ /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
161+ /// functions return different integer types (like `read`, that returns an `i64`)
154162 fn get_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , f : F ) -> InterpResult < ' tcx , T >
155163 where
156164 F : Fn ( & FileHandle ) -> InterpResult < ' tcx , T > ,
@@ -164,6 +172,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
164172 }
165173 }
166174
175+ /// Helper function that removes a `FileHandle` and allows to manipulate it using the `f`
176+ /// closure. This function is quite useful when you need to modify a `FileHandle` but you need
177+ /// to modify `MiriEvalContext` at the same time, so you can modify the handle and reinsert it
178+ /// using `f`.
179+ ///
180+ /// If the `fd` file descriptor does not corresponds to a file, this functions returns `Ok(-1)`
181+ /// and sets `Evaluator::last_error` to `libc::EBADF` (invalid file descriptor).
182+ ///
183+ /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
184+ /// functions return different integer types (like `read`, that returns an `i64`)
167185 fn remove_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , mut f : F ) -> InterpResult < ' tcx , T >
168186 where
169187 F : FnMut ( FileHandle , & mut MiriEvalContext < ' mir , ' tcx > ) -> InterpResult < ' tcx , T > ,
@@ -177,6 +195,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
177195 }
178196 }
179197
198+ /// Helper function that consumes an `std::io::Result<T>` and returns an
199+ /// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
200+ /// OS error using `std::io::Error::raw_os_error`.
201+ ///
202+ /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
203+ /// functions return different integer types (like `read`, that returns an `i64`)
180204 fn consume_result < T : From < i32 > > ( & mut self , result : std:: io:: Result < T > ) -> InterpResult < ' tcx , T > {
181205 match result {
182206 Ok ( ok) => Ok ( ok) ,
0 commit comments