Skip to content

Commit

Permalink
Use unsafe borrow_raw method
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Sep 2, 2023
1 parent 0491215 commit 92f750b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp;
use std::collections::HashMap;
use std::fs::{File, OpenOptions};
use std::io::{self, BufReader, ErrorKind, Read, Write};
use std::os::unix::io::{AsFd, BorrowedFd, IntoRawFd, RawFd};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, SyncSender};
Expand Down Expand Up @@ -185,7 +185,8 @@ pub struct PosixRawReader {

impl AsFd for PosixRawReader {
fn as_fd(&self) -> BorrowedFd<'_> {
self.tty_in.get_ref().fd
let fd = self.tty_in.get_ref().fd;
unsafe { BorrowedFd::borrow_raw(fd) }
}
}

Expand Down Expand Up @@ -699,27 +700,26 @@ impl PosixRawReader {

fn select(&mut self, single_esc_abort: bool) -> Result<Event> {
let tty_in = self.as_fd();
let sigwinch_pipe = self.tty_in.get_ref().sigwinch_pipe;
let sigwinch_pipe = self
.tty_in
.get_ref()
.sigwinch_pipe
.map(|fd| unsafe { BorrowedFd::borrow_raw(fd) });
let pipe_reader = self
.pipe_reader
.as_ref()
.map(|pr| pr.lock().unwrap().0.as_fd());
.map(|pr| pr.lock().unwrap().0.as_raw_fd())
.map(|fd| unsafe { BorrowedFd::borrow_raw(fd) });
loop {
let mut readfds = FdSet::new();
if let Some(sigwinch_pipe) = sigwinch_pipe {
if let Some(ref sigwinch_pipe) = sigwinch_pipe {
readfds.insert(sigwinch_pipe);
}
readfds.insert(&tty_in);
if let Some(pipe_reader) = pipe_reader {
if let Some(ref pipe_reader) = pipe_reader {
readfds.insert(pipe_reader);
}
if let Err(err) = select::select(
None,
Some(&mut readfds),
None,
None,
None,
) {
if let Err(err) = select::select(None, Some(&mut readfds), None, None, None) {
if err == Errno::EINTR && self.tty_in.get_ref().sigwinch()? {
return Err(ReadlineError::WindowResized);
} else if err != Errno::EINTR {
Expand All @@ -728,7 +728,7 @@ impl PosixRawReader {
continue;
}
};
if sigwinch_pipe.map_or(false, |fd| readfds.contains(fd)) {
if sigwinch_pipe.map_or(false, |fd| readfds.contains(&fd)) {
self.tty_in.get_ref().sigwinch()?;
return Err(ReadlineError::WindowResized);
} else if readfds.contains(&tty_in) {
Expand Down

0 comments on commit 92f750b

Please sign in to comment.