@@ -107,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
107
107
fh. low
108
108
} ) ;
109
109
110
- this. consume_result ( fd)
110
+ this. set_last_error_from_io_result ( fd)
111
111
}
112
112
113
113
fn fcntl (
@@ -143,7 +143,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
143
143
let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
144
144
145
145
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 ) )
147
147
} )
148
148
}
149
149
@@ -178,7 +178,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
178
178
} ) ;
179
179
// Reinsert the file handle
180
180
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 ) )
182
182
} )
183
183
}
184
184
@@ -209,7 +209,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
209
209
. map ( |bytes| handle. file . write ( bytes) . map ( |bytes| bytes as i64 ) )
210
210
} ) ;
211
211
this. machine . file_handler . handles . insert ( fd, handle) ;
212
- this. consume_result ( bytes?)
212
+ this. set_last_error_from_io_result ( bytes?)
213
213
} )
214
214
}
215
215
@@ -226,7 +226,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226
226
227
227
let result = remove_file ( path) . map ( |_| 0 ) ;
228
228
229
- this. consume_result ( result)
229
+ this. set_last_error_from_io_result ( result)
230
230
}
231
231
232
232
/// 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
274
274
Ok ( ( -1 ) . into ( ) )
275
275
}
276
276
}
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
- }
296
277
}
0 commit comments