Skip to content

Commit

Permalink
Update to rustix 0.38
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Jul 17, 2023
1 parent 6a46fbd commit 381a9ff
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 76 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.56.0
- uses: dtolnay/rust-toolchain@1.63.0

# build
- name: cargo check x11rb-protocol with all features
run: cargo build --package x11rb-protocol --verbose --lib --all-features
- name: cargo check x11rb with all features
run: cargo build --package x11rb --verbose --lib --all-features
- name: Pin last log release supporting our msrv of Rust 1.56
run: cargo update --package log --precise 0.4.18
- name: cargo check x11rb-async with all features
run: cargo build --package x11rb-async --verbose --lib --all-features

Expand Down
5 changes: 3 additions & 2 deletions x11rb-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
repository = "https://github.com/psychon/x11rb"
readme = "../README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11", "async"]

Expand All @@ -25,8 +25,9 @@ x11rb = { version = "0.12.0", path = "../x11rb", default-features = false }
x11rb-protocol = { version = "0.12.0", path = "../x11rb-protocol" }

[target.'cfg(unix)'.dev-dependencies.rustix]
version = "0.37.16"
version = "0.38"
default-features = false
features = ["pipe"]

[features]
# Enable this feature to enable all the X11 extensions
Expand Down
4 changes: 2 additions & 2 deletions x11rb-async/tests/connection_regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ fn retry_for_left_over_fds() {
// Right now that error is WriteZero. That is still better than no error at all.

let fds = {
let (fd0, fd1) = rustix::io::pipe().unwrap();
vec![RawFdContainer::new(fd0), RawFdContainer::new(fd1)]
let (fd0, fd1) = rustix::pipe::pipe().unwrap();
vec![fd0, fd1]
};

// Send a large request. This should be larger than the write buffer size, which is 16384 bytes.
Expand Down
4 changes: 2 additions & 2 deletions x11rb-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
repository = "https://github.com/psychon/x11rb"
readme = "../README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11"]

Expand All @@ -21,7 +21,7 @@ serde = { version = "1", features = ["derive"], optional = true }
criterion = "0.4"

[target.'cfg(unix)'.dependencies.rustix]
version = "0.37.16"
version = "0.38"
default-features = false
features = ["std"]
optional = true
Expand Down
55 changes: 2 additions & 53 deletions x11rb-protocol/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,13 @@
#[cfg(all(feature = "std", unix))]
mod raw_fd_container {
use rustix::fd::OwnedFd;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::os::unix::io::OwnedFd;

/// A simple wrapper around RawFd that closes the fd on drop.
///
/// On non-unix systems, this type is empty and does not provide
/// any method.
#[derive(Debug)]
pub struct RawFdContainer(OwnedFd);

impl RawFdContainer {
/// Create a new `RawFdContainer` for the given `RawFd`.
///
/// The `RawFdContainer` takes ownership of the `RawFd` and closes it on drop.
pub fn new(fd: OwnedFd) -> Self {
RawFdContainer(fd)
}

/// Tries to clone the `RawFdContainer` creating a new FD
/// with `dup`. The new `RawFdContainer` will take ownership
/// of the `dup`ed version, whereas the original `RawFdContainer`
/// will keep the ownership of its FD.
pub fn try_clone(&self) -> Result<Self, std::io::Error> {
Ok(Self::new(rustix::io::dup(&self.0)?))
}

/// Get the `RawFd` out of this `RawFdContainer`.
///
/// This function would be an implementation of `IntoRawFd` if that were possible. However, it
/// causes a conflict with an `impl` from libcore...
pub fn into_raw_fd(self) -> RawFd {
self.0.into_raw_fd()
}
}

impl<T: Into<OwnedFd>> From<T> for RawFdContainer {
fn from(fd: T) -> Self {
Self::new(fd.into())
}
}

impl AsRawFd for RawFdContainer {
fn as_raw_fd(&self) -> RawFd {
self.0.as_raw_fd()
}
}

impl IntoRawFd for RawFdContainer {
fn into_raw_fd(self) -> RawFd {
self.0.into_raw_fd()
}
}

impl rustix::fd::AsFd for RawFdContainer {
fn as_fd(&self) -> rustix::fd::BorrowedFd<'_> {
rustix::fd::AsFd::as_fd(&self.0)
}
}
pub type RawFdContainer = OwnedFd;
}

#[cfg(not(all(feature = "std", unix)))]
Expand Down
4 changes: 2 additions & 2 deletions x11rb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
repository = "https://github.com/psychon/x11rb"
readme = "../README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11"]

Expand All @@ -22,7 +22,7 @@ once_cell = { version = "1.17", optional = true }
gethostname = "0.3.0"
as-raw-xcb-connection = { version = "1.0", optional = true }
tracing = { version = "0.1", optional = true, default-features = false }
rustix = { version = "0.37.16", default-features = false, features = ["std", "fs", "net"] }
rustix = { version = "0.38", default-features = false, features = ["std", "event", "fs", "net"] }

[dev-dependencies]
polling = "2.8.0"
Expand Down
18 changes: 9 additions & 9 deletions x11rb/src/rust_connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn do_write(
) -> Result<usize> {
use rustix::fd::{AsFd, BorrowedFd};
use rustix::io::Errno;
use rustix::net::{sendmsg_noaddr, SendAncillaryBuffer, SendAncillaryMessage, SendFlags};
use rustix::net::{sendmsg, SendAncillaryBuffer, SendAncillaryMessage, SendFlags};

fn sendmsg_wrapper(
fd: BorrowedFd<'_>,
Expand All @@ -338,7 +338,7 @@ fn do_write(
flags: SendFlags,
) -> Result<usize> {
loop {
match sendmsg_noaddr(fd, iov, cmsgs, flags) {
match sendmsg(fd, iov, cmsgs, flags) {
Ok(n) => return Ok(n),
// try again
Err(Errno::INTR) => {}
Expand Down Expand Up @@ -370,7 +370,8 @@ fn do_write(

impl Stream for DefaultStream {
fn poll(&self, mode: PollMode) -> Result<()> {
use rustix::io::{poll, Errno, PollFd, PollFlags};
use rustix::event::{poll, PollFd, PollFlags};
use rustix::io::Errno;

let mut poll_flags = PollFlags::empty();
if mode.readable() {
Expand Down Expand Up @@ -422,8 +423,7 @@ impl Stream for DefaultStream {
RecvAncillaryMessage::ScmRights(r) => Some(r),
_ => None,
})
.flatten()
.map(RawFdContainer::new);
.flatten();

let mut cloexec_error = Ok(());
fd_storage.extend(recvmsg::after_recvmsg(fds_received, &mut cloexec_error));
Expand Down Expand Up @@ -516,15 +516,15 @@ fn connect_abstract_unix_stream(
) -> std::result::Result<RawFdContainer, rustix::io::Errno> {
use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags};
use rustix::net::{
connect_unix, socket_with, AddressFamily, Protocol, SocketAddrUnix, SocketFlags, SocketType,
connect_unix, socket_with, AddressFamily, SocketAddrUnix, SocketFlags, SocketType,
};

let socket = RawFdContainer::new(socket_with(
let socket = socket_with(
AddressFamily::UNIX,
SocketType::STREAM,
SocketFlags::CLOEXEC,
Protocol::default(),
)?);
None,
)?;

connect_unix(&socket, &SocketAddrUnix::new_abstract_name(path)?)?;

Expand Down
5 changes: 2 additions & 3 deletions x11rb/src/xcb_ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use std::ffi::CStr;
use std::io::{Error as IOError, ErrorKind, IoSlice};
use std::os::raw::c_int;
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use std::ptr::{null, null_mut};
use std::sync::{atomic::Ordering, Mutex};

use libc::c_void;
use rustix::fd::{FromRawFd, OwnedFd};

use crate::connection::{
compute_length_field, Connection, ReplyOrError, RequestConnection, RequestKind,
Expand Down Expand Up @@ -477,7 +476,7 @@ impl RequestConnection for XCBConnection {
let fd_slice = unsafe { std::slice::from_raw_parts(fd_ptr, usize::from(buffer[1])) };
let fd_vec = fd_slice
.iter()
.map(|&fd| RawFdContainer::new(unsafe { OwnedFd::from_raw_fd(fd) }))
.map(|&fd| unsafe { OwnedFd::from_raw_fd(fd) })
.collect();

Ok(ReplyOrError::Reply((buffer, fd_vec)))
Expand Down

0 comments on commit 381a9ff

Please sign in to comment.