forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3533 - Luv-Ray:file-descriptors-to-refcount-r…
…eferences, r=RalfJung Make file descriptors into refcount references fixes rust-lang#3525 Remove `fn dup` in `trait FileDescription`, define `struct FileDescriptor(Rc<RefCell<dyn FileDescription>>)`, and use `BTreeMap<i32, FileDescriptor>` in `FdTable`. --- There are some refactors similar to the following form: ```rust { // origin: if let Some(file_descriptor) = this.machine.fds.get_mut(fd) { // write file_descriptor this.try_unwrap_io_result(result) } else { this.fd_not_found() } } { // now: let Some(mut file_descriptor) = this.machine.fds.get_mut(fd) else { return this.fd_not_found(); }; // write file_descriptor drop(file_descriptor); this.try_unwrap_io_result(result) } ``` The origin form can't compile because as using `RefCell` to get interior mutability, `fn get_mut` return `Option<std::cell::RefMut<'_, dyn FileDescription>>` instead of `Option<&mut dyn FileDescription>` now, and the `deref_mut` on `file_descriptor: RefMut` will cause borrow `this` as mutable more than once at a time. So this form of refactors and manual drops are are implemented to avoid borrowing `this` at the same time.
- Loading branch information
Showing
6 changed files
with
193 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.