FD: refactor API names a little
This commit is contained in:
parent
f1e8c54082
commit
6283c4dae6
5 changed files with 17 additions and 17 deletions
|
|
@ -240,25 +240,25 @@ impl FdTable {
|
|||
}
|
||||
pub(crate) fn init(mute_stdout_stderr: bool) -> FdTable {
|
||||
let mut fds = FdTable::new();
|
||||
fds.insert_fd(io::stdin());
|
||||
fds.insert_new(io::stdin());
|
||||
if mute_stdout_stderr {
|
||||
assert_eq!(fds.insert_fd(NullOutput), 1);
|
||||
assert_eq!(fds.insert_fd(NullOutput), 2);
|
||||
assert_eq!(fds.insert_new(NullOutput), 1);
|
||||
assert_eq!(fds.insert_new(NullOutput), 2);
|
||||
} else {
|
||||
assert_eq!(fds.insert_fd(io::stdout()), 1);
|
||||
assert_eq!(fds.insert_fd(io::stderr()), 2);
|
||||
assert_eq!(fds.insert_new(io::stdout()), 1);
|
||||
assert_eq!(fds.insert_new(io::stderr()), 2);
|
||||
}
|
||||
fds
|
||||
}
|
||||
|
||||
/// Insert a new file description to the FdTable.
|
||||
pub fn insert_fd(&mut self, fd: impl FileDescription) -> i32 {
|
||||
pub fn insert_new(&mut self, fd: impl FileDescription) -> i32 {
|
||||
let file_handle = FileDescriptionRef::new(fd);
|
||||
self.insert_fd_with_min_fd(file_handle, 0)
|
||||
self.insert_ref_with_min_fd(file_handle, 0)
|
||||
}
|
||||
|
||||
/// Insert a new FD that is at least `min_fd`.
|
||||
fn insert_fd_with_min_fd(&mut self, file_handle: FileDescriptionRef, min_fd: i32) -> i32 {
|
||||
/// Insert a file description, giving it a file descriptor that is at least `min_fd`.
|
||||
fn insert_ref_with_min_fd(&mut self, file_handle: FileDescriptionRef, min_fd: i32) -> i32 {
|
||||
// Find the lowest unused FD, starting from min_fd. If the first such unused FD is in
|
||||
// between used FDs, the find_map combinator will return it. If the first such unused FD
|
||||
// is after all other used FDs, the find_map combinator will return None, and we will use
|
||||
|
|
@ -316,7 +316,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let Some(dup_fd) = this.machine.fds.dup(old_fd) else {
|
||||
return Ok(Scalar::from_i32(this.fd_not_found()?));
|
||||
};
|
||||
Ok(Scalar::from_i32(this.machine.fds.insert_fd_with_min_fd(dup_fd, 0)))
|
||||
Ok(Scalar::from_i32(this.machine.fds.insert_ref_with_min_fd(dup_fd, 0)))
|
||||
}
|
||||
|
||||
fn dup2(&mut self, old_fd: i32, new_fd: i32) -> InterpResult<'tcx, Scalar> {
|
||||
|
|
@ -410,7 +410,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
|
||||
match this.machine.fds.dup(fd) {
|
||||
Some(dup_fd) =>
|
||||
Ok(Scalar::from_i32(this.machine.fds.insert_fd_with_min_fd(dup_fd, start))),
|
||||
Ok(Scalar::from_i32(this.machine.fds.insert_ref_with_min_fd(dup_fd, start))),
|
||||
None => Ok(Scalar::from_i32(this.fd_not_found()?)),
|
||||
}
|
||||
} else if this.tcx.sess.target.os == "macos" && cmd == this.eval_libc_i32("F_FULLFSYNC") {
|
||||
|
|
|
|||
|
|
@ -545,7 +545,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
|
||||
let fd = options
|
||||
.open(path)
|
||||
.map(|file| this.machine.fds.insert_fd(FileHandle { file, writable }));
|
||||
.map(|file| this.machine.fds.insert_new(FileHandle { file, writable }));
|
||||
|
||||
Ok(Scalar::from_i32(this.try_unwrap_io_result(fd)?))
|
||||
}
|
||||
|
|
@ -1634,7 +1634,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
|
||||
match file {
|
||||
Ok(f) => {
|
||||
let fd = this.machine.fds.insert_fd(FileHandle { file: f, writable: true });
|
||||
let fd = this.machine.fds.insert_new(FileHandle { file: f, writable: true });
|
||||
return Ok(Scalar::from_i32(fd));
|
||||
}
|
||||
Err(e) =>
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
let fd = this.machine.fds.insert_fd(Epoll::default());
|
||||
let fd = this.machine.fds.insert_new(Epoll::default());
|
||||
Ok(Scalar::from_i32(fd))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
throw_unsup_format!("eventfd: encountered unknown unsupported flags {:#x}", flags);
|
||||
}
|
||||
|
||||
let fd = this.machine.fds.insert_fd(Event {
|
||||
let fd = this.machine.fds.insert_new(Event {
|
||||
counter: val.into(),
|
||||
is_nonblock,
|
||||
clock: VClock::default(),
|
||||
|
|
|
|||
|
|
@ -219,8 +219,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
};
|
||||
|
||||
let fds = &mut this.machine.fds;
|
||||
let sv0 = fds.insert_fd(socketpair_0);
|
||||
let sv1 = fds.insert_fd(socketpair_1);
|
||||
let sv0 = fds.insert_new(socketpair_0);
|
||||
let sv1 = fds.insert_new(socketpair_1);
|
||||
let sv0 = Scalar::from_int(sv0, sv.layout.size);
|
||||
let sv1 = Scalar::from_int(sv1, sv.layout.size);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue