@@ -151,6 +151,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
151
151
)
152
152
}
153
153
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`)
154
162
fn get_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , f : F ) -> InterpResult < ' tcx , T >
155
163
where
156
164
F : Fn ( & FileHandle ) -> InterpResult < ' tcx , T > ,
@@ -164,6 +172,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
164
172
}
165
173
}
166
174
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`)
167
185
fn remove_handle_and < F , T : From < i32 > > ( & mut self , fd : i32 , mut f : F ) -> InterpResult < ' tcx , T >
168
186
where
169
187
F : FnMut ( FileHandle , & mut MiriEvalContext < ' mir , ' tcx > ) -> InterpResult < ' tcx , T > ,
@@ -177,6 +195,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
177
195
}
178
196
}
179
197
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`)
180
204
fn consume_result < T : From < i32 > > ( & mut self , result : std:: io:: Result < T > ) -> InterpResult < ' tcx , T > {
181
205
match result {
182
206
Ok ( ok) => Ok ( ok) ,
0 commit comments