@@ -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
@@ -176,7 +176,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
176
176
} ) ;
177
177
// Reinsert the file handle
178
178
this. machine . file_handler . handles . insert ( fd, handle) ;
179
- this. consume_result ( bytes?. map ( |bytes| bytes as i64 ) )
179
+ this. set_last_error_from_io_result ( bytes?. map ( |bytes| bytes as i64 ) )
180
180
} )
181
181
}
182
182
@@ -205,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
205
205
. map ( |bytes| handle. file . write ( bytes) . map ( |bytes| bytes as i64 ) )
206
206
} ) ;
207
207
this. machine . file_handler . handles . insert ( fd, handle) ;
208
- this. consume_result ( bytes?)
208
+ this. set_last_error_from_io_result ( bytes?)
209
209
} )
210
210
}
211
211
@@ -222,7 +222,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
222
222
223
223
let result = remove_file ( path) . map ( |_| 0 ) ;
224
224
225
- this. consume_result ( result)
225
+ this. set_last_error_from_io_result ( result)
226
226
}
227
227
228
228
/// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it
@@ -270,23 +270,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
270
270
Ok ( ( -1 ) . into ( ) )
271
271
}
272
272
}
273
-
274
- /// Helper function that consumes an `std::io::Result<T>` and returns an
275
- /// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
276
- /// OS error using `std::io::Error::raw_os_error`.
277
- ///
278
- /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
279
- /// functions return different integer types (like `read`, that returns an `i64`)
280
- fn consume_result < T : From < i32 > > (
281
- & mut self ,
282
- result : std:: io:: Result < T > ,
283
- ) -> InterpResult < ' tcx , T > {
284
- match result {
285
- Ok ( ok) => Ok ( ok) ,
286
- Err ( e) => {
287
- self . eval_context_mut ( ) . set_last_error_from_io_error ( e) ?;
288
- Ok ( ( -1 ) . into ( ) )
289
- }
290
- }
291
- }
292
273
}
0 commit comments