@@ -107,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
107107 fh. low
108108 } ) ;
109109
110- this. consume_result ( fd)
110+ this. set_last_error_from_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. consume_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) )
146+ this. set_last_error_from_io_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) )
147147 } )
148148 }
149149
@@ -178,7 +178,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
178178 } ) ;
179179 // Reinsert the file handle
180180 this. machine . file_handler . handles . insert ( fd, handle) ;
181- this. consume_result ( bytes?. map ( |bytes| bytes as i64 ) )
181+ this. set_last_error_from_io_result ( bytes?. map ( |bytes| bytes as i64 ) )
182182 } )
183183 }
184184
@@ -209,7 +209,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
209209 . map ( |bytes| handle. file . write ( bytes) . map ( |bytes| bytes as i64 ) )
210210 } ) ;
211211 this. machine . file_handler . handles . insert ( fd, handle) ;
212- this. consume_result ( bytes?)
212+ this. set_last_error_from_io_result ( bytes?)
213213 } )
214214 }
215215
@@ -226,7 +226,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226226
227227 let result = remove_file ( path) . map ( |_| 0 ) ;
228228
229- this. consume_result ( result)
229+ this. set_last_error_from_io_result ( result)
230230 }
231231
232232 /// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it
@@ -274,23 +274,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274274 Ok ( ( -1 ) . into ( ) )
275275 }
276276 }
277-
278- /// Helper function that consumes an `std::io::Result<T>` and returns an
279- /// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
280- /// OS error using `std::io::Error::raw_os_error`.
281- ///
282- /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
283- /// functions return different integer types (like `read`, that returns an `i64`)
284- fn consume_result < T : From < i32 > > (
285- & mut self ,
286- result : std:: io:: Result < T > ,
287- ) -> InterpResult < ' tcx , T > {
288- match result {
289- Ok ( ok) => Ok ( ok) ,
290- Err ( e) => {
291- self . eval_context_mut ( ) . set_last_error_from_io_error ( e) ?;
292- Ok ( ( -1 ) . into ( ) )
293- }
294- }
295- }
296277}
0 commit comments