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