-
Notifications
You must be signed in to change notification settings - Fork 394
Insert FileDescription instead of FileDescriptor in insert_fd
#3763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,10 +192,6 @@ impl FileDescription for NullOutput { | |
pub struct FileDescriptor(Rc<RefCell<Box<dyn FileDescription>>>); | ||
|
||
impl FileDescriptor { | ||
pub fn new<T: FileDescription>(fd: T) -> Self { | ||
FileDescriptor(Rc::new(RefCell::new(Box::new(fd)))) | ||
} | ||
|
||
pub fn borrow(&self) -> Ref<'_, dyn FileDescription> { | ||
Ref::map(self.0.borrow(), |fd| fd.as_ref()) | ||
} | ||
|
@@ -227,20 +223,25 @@ impl VisitProvenance for FdTable { | |
} | ||
|
||
impl FdTable { | ||
pub(crate) fn new(mute_stdout_stderr: bool) -> FdTable { | ||
let mut fds: BTreeMap<_, FileDescriptor> = BTreeMap::new(); | ||
fds.insert(0i32, FileDescriptor::new(io::stdin())); | ||
fn new() -> Self { | ||
FdTable { fds: BTreeMap::new() } | ||
} | ||
pub(crate) fn init(mute_stdout_stderr: bool) -> FdTable { | ||
let mut fds = FdTable::new(); | ||
fds.insert_fd(io::stdin()); | ||
if mute_stdout_stderr { | ||
fds.insert(1i32, FileDescriptor::new(NullOutput)); | ||
fds.insert(2i32, FileDescriptor::new(NullOutput)); | ||
assert_eq!(fds.insert_fd(NullOutput), 1); | ||
assert_eq!(fds.insert_fd(NullOutput), 2); | ||
} else { | ||
fds.insert(1i32, FileDescriptor::new(io::stdout())); | ||
fds.insert(2i32, FileDescriptor::new(io::stderr())); | ||
assert_eq!(fds.insert_fd(io::stdout()), 1); | ||
assert_eq!(fds.insert_fd(io::stderr()), 2); | ||
} | ||
FdTable { fds } | ||
fds | ||
} | ||
|
||
pub fn insert_fd(&mut self, file_handle: FileDescriptor) -> i32 { | ||
/// Insert a file descriptor to the FdTable. | ||
pub fn insert_fd<T: FileDescription>(&mut self, fd: T) -> i32 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the motivation is for this API change, but it seems odd to me. Note that
I don't understand how it is possible for this change to be needed. This change means that the API is now strictly less powerful than it was before. The only argument I can currently imagine for this change is ergonomics, and I don't agree that's worth it given the API inconsistencies this introduces. IMO this should be reverted, both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API didn't need to be as powerful as it was, so this seems good (restricting to the use case we need). It's also the only sane design I see for having each There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We considered do it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is pure coincidence that we have no operation which creates a 2nd file descriptor for an existing file description, and calls this function. In fact arguably this here should just call And having two Creating a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just have Then we can maybe have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could call the functions The PR description should have mentioned the point about |
||
let file_handle = FileDescriptor(Rc::new(RefCell::new(Box::new(fd)))); | ||
self.insert_fd_with_min_fd(file_handle, 0) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment seems to contradict the signature? This is a file description, isn't it?