@@ -240,25 +240,25 @@ impl FdTable {
240
240
}
241
241
pub ( crate ) fn init ( mute_stdout_stderr : bool ) -> FdTable {
242
242
let mut fds = FdTable :: new ( ) ;
243
- fds. insert_fd ( io:: stdin ( ) ) ;
243
+ fds. insert_new ( io:: stdin ( ) ) ;
244
244
if mute_stdout_stderr {
245
- assert_eq ! ( fds. insert_fd ( NullOutput ) , 1 ) ;
246
- assert_eq ! ( fds. insert_fd ( NullOutput ) , 2 ) ;
245
+ assert_eq ! ( fds. insert_new ( NullOutput ) , 1 ) ;
246
+ assert_eq ! ( fds. insert_new ( NullOutput ) , 2 ) ;
247
247
} else {
248
- assert_eq ! ( fds. insert_fd ( io:: stdout( ) ) , 1 ) ;
249
- assert_eq ! ( fds. insert_fd ( io:: stderr( ) ) , 2 ) ;
248
+ assert_eq ! ( fds. insert_new ( io:: stdout( ) ) , 1 ) ;
249
+ assert_eq ! ( fds. insert_new ( io:: stderr( ) ) , 2 ) ;
250
250
}
251
251
fds
252
252
}
253
253
254
254
/// Insert a new file description to the FdTable.
255
- pub fn insert_fd ( & mut self , fd : impl FileDescription ) -> i32 {
255
+ pub fn insert_new ( & mut self , fd : impl FileDescription ) -> i32 {
256
256
let file_handle = FileDescriptionRef :: new ( fd) ;
257
- self . insert_fd_with_min_fd ( file_handle, 0 )
257
+ self . insert_ref_with_min_fd ( file_handle, 0 )
258
258
}
259
259
260
- /// Insert a new FD that is at least `min_fd`.
261
- fn insert_fd_with_min_fd ( & mut self , file_handle : FileDescriptionRef , min_fd : i32 ) -> i32 {
260
+ /// Insert a file description, giving it a file descriptor that is at least `min_fd`.
261
+ fn insert_ref_with_min_fd ( & mut self , file_handle : FileDescriptionRef , min_fd : i32 ) -> i32 {
262
262
// Find the lowest unused FD, starting from min_fd. If the first such unused FD is in
263
263
// between used FDs, the find_map combinator will return it. If the first such unused FD
264
264
// is after all other used FDs, the find_map combinator will return None, and we will use
@@ -294,7 +294,7 @@ impl FdTable {
294
294
Some ( fd. borrow_mut ( ) )
295
295
}
296
296
297
- pub fn dup ( & self , fd : i32 ) -> Option < FileDescriptionRef > {
297
+ pub fn get_ref ( & self , fd : i32 ) -> Option < FileDescriptionRef > {
298
298
let fd = self . fds . get ( & fd) ?;
299
299
Some ( fd. clone ( ) )
300
300
}
@@ -313,16 +313,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
313
313
fn dup ( & mut self , old_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
314
314
let this = self . eval_context_mut ( ) ;
315
315
316
- let Some ( dup_fd) = this. machine . fds . dup ( old_fd) else {
316
+ let Some ( dup_fd) = this. machine . fds . get_ref ( old_fd) else {
317
317
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
318
318
} ;
319
- Ok ( Scalar :: from_i32 ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, 0 ) ) )
319
+ Ok ( Scalar :: from_i32 ( this. machine . fds . insert_ref_with_min_fd ( dup_fd, 0 ) ) )
320
320
}
321
321
322
322
fn dup2 ( & mut self , old_fd : i32 , new_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
323
323
let this = self . eval_context_mut ( ) ;
324
324
325
- let Some ( dup_fd) = this. machine . fds . dup ( old_fd) else {
325
+ let Some ( dup_fd) = this. machine . fds . get_ref ( old_fd) else {
326
326
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
327
327
} ;
328
328
if new_fd != old_fd {
@@ -408,9 +408,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
408
408
}
409
409
let start = this. read_scalar ( & args[ 2 ] ) ?. to_i32 ( ) ?;
410
410
411
- match this. machine . fds . dup ( fd) {
411
+ match this. machine . fds . get_ref ( fd) {
412
412
Some ( dup_fd) =>
413
- Ok ( Scalar :: from_i32 ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, start) ) ) ,
413
+ Ok ( Scalar :: from_i32 ( this. machine . fds . insert_ref_with_min_fd ( dup_fd, start) ) ) ,
414
414
None => Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ,
415
415
}
416
416
} else if this. tcx . sess . target . os == "macos" && cmd == this. eval_libc_i32 ( "F_FULLFSYNC" ) {
@@ -481,7 +481,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
481
481
let communicate = this. machine . communicate ( ) ;
482
482
483
483
// We temporarily dup the FD to be able to retain mutable access to `this`.
484
- let Some ( fd) = this. machine . fds . dup ( fd) else {
484
+ let Some ( fd) = this. machine . fds . get_ref ( fd) else {
485
485
trace ! ( "read: FD not found" ) ;
486
486
return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ?, this) ) ;
487
487
} ;
@@ -546,7 +546,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
546
546
547
547
let bytes = this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( count) ) ?. to_owned ( ) ;
548
548
// We temporarily dup the FD to be able to retain mutable access to `this`.
549
- let Some ( fd) = this. machine . fds . dup ( fd) else {
549
+ let Some ( fd) = this. machine . fds . get_ref ( fd) else {
550
550
return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ?, this) ) ;
551
551
} ;
552
552
0 commit comments