Skip to content

Commit

Permalink
Miscellaneous cleanups (#842)
Browse files Browse the repository at this point in the history
- Update to libc 0.2.148, which has `SO_DOMAIN` for OpenBSD and Solarish.
 - Enable `Mode` constants on WASI, which now defines them.
 - Simplify some `cfg`s and `allow`s.
  • Loading branch information
sunfishcode authored Sep 20, 2023
1 parent 26ece58 commit 37ef021
Show file tree
Hide file tree
Showing 30 changed files with 79 additions and 110 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ once_cell = { version = "1.5.2", optional = true }
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.4.7", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.1", default-features = false, optional = true }
libc = { version = "0.2.147", default-features = false, features = ["extra_traits"], optional = true }
libc = { version = "0.2.148", default-features = false, features = ["extra_traits"], optional = true }

# Dependencies for platforms where only libc is supported:
#
# On all other Unix-family platforms, and under Miri, we always use the libc
# backend, so enable its dependencies unconditionally.
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
libc_errno = { package = "errno", version = "0.3.1", default-features = false }
libc = { version = "0.2.147", default-features = false, features = ["extra_traits"] }
libc = { version = "0.2.148", default-features = false, features = ["extra_traits"] }

# Additional dependencies for Linux with the libc backend:
#
Expand Down Expand Up @@ -74,7 +74,7 @@ default-features = false

[dev-dependencies]
tempfile = "3.5.0"
libc = "0.2.147"
libc = "0.2.148"
libc_errno = { package = "errno", version = "0.3.1", default-features = false }
serial_test = "2.0.0"
memoffset = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod suite {
b.iter(|| {
let mut s = std::mem::MaybeUninit::<libc::stat>::uninit();
unsafe {
assert_eq!(libc::fstat(libc::STDIN_FILENO, s.as_mut_ptr(),), 0);
assert_eq!(libc::fstat(libc::STDIN_FILENO, s.as_mut_ptr()), 0);
}
})
});
Expand Down
30 changes: 15 additions & 15 deletions src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,63 +92,63 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Mode: RawMode {
/// `S_IRWXU`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const RWXU = c::S_IRWXU as RawMode;

/// `S_IRUSR`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const RUSR = c::S_IRUSR as RawMode;

/// `S_IWUSR`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const WUSR = c::S_IWUSR as RawMode;

/// `S_IXUSR`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const XUSR = c::S_IXUSR as RawMode;

/// `S_IRWXG`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const RWXG = c::S_IRWXG as RawMode;

/// `S_IRGRP`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const RGRP = c::S_IRGRP as RawMode;

/// `S_IWGRP`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const WGRP = c::S_IWGRP as RawMode;

/// `S_IXGRP`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const XGRP = c::S_IXGRP as RawMode;

/// `S_IRWXO`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const RWXO = c::S_IRWXO as RawMode;

/// `S_IROTH`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const ROTH = c::S_IROTH as RawMode;

/// `S_IWOTH`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const WOTH = c::S_IWOTH as RawMode;

/// `S_IXOTH`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const XOTH = c::S_IXOTH as RawMode;

/// `S_ISUID`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const SUID = c::S_ISUID as RawMode;

/// `S_ISGID`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const SGID = c::S_ISGID as RawMode;

/// `S_ISVTX`
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags.
#[cfg(not(target_os = "espidf"))]
const SVTX = c::S_ISVTX as RawMode;

/// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags>
Expand Down
4 changes: 0 additions & 4 deletions src/backend/libc/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ pub(crate) mod sockopt {
use crate::net::sockopt::Timeout;
#[cfg(not(any(
apple,
solarish,
windows,
target_os = "aix",
target_os = "dragonfly",
Expand All @@ -532,7 +531,6 @@ pub(crate) mod sockopt {
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "openbsd"
)))]
use crate::net::AddressFamily;
use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};
Expand Down Expand Up @@ -835,7 +833,6 @@ pub(crate) mod sockopt {
#[inline]
#[cfg(not(any(
apple,
solarish,
windows,
target_os = "aix",
target_os = "dragonfly",
Expand All @@ -844,7 +841,6 @@ pub(crate) mod sockopt {
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "openbsd"
)))]
pub(crate) fn get_socket_domain(fd: BorrowedFd<'_>) -> io::Result<AddressFamily> {
let domain: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_DOMAIN)?;
Expand Down
1 change: 0 additions & 1 deletion src/backend/linux_raw/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ pub(in crate::backend) unsafe fn indirect_syscall5(
FromAsm::from_asm(r0)
}

#[allow(clippy::too_many_arguments)]
#[inline]
pub(in crate::backend) unsafe fn indirect_syscall6(
callee: SyscallType,
Expand Down
1 change: 0 additions & 1 deletion src/backend/linux_raw/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub(crate) use linux_raw_sys::general::{
XATTR_REPLACE,
};

#[allow(unused)]
pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE};

#[cfg(feature = "io_uring")]
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/event/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::{c_int, c_uint, ret_owned_fd, ret_usize, slice_mut};
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/io_uring/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend::syscalls` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{by_mut, c_uint, pass_usize, ret_c_uint, ret_owned_fd};
use crate::fd::{BorrowedFd, OwnedFd};
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use super::msghdr::{
with_noaddr_msghdr, with_recv_msghdr, with_unix_msghdr, with_v4_msghdr, with_v6_msghdr,
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/pid/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::ret_usize_infallible;
use crate::pid::{Pid, RawPid};
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/pipe/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{c_int, c_uint, opt_mut, pass_usize, ret, ret_usize, slice};
use crate::backend::{c, MAX_IOV};
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/prctl/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::{c_int, ret_c_int};
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/process/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use super::types::RawCpuSet;
use crate::backend::c;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/pty/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{by_ref, c_uint, ret};
use crate::fd::BorrowedFd;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/rand/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{ret_usize, slice_mut};
use crate::io;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/runtime/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
#[cfg(target_arch = "x86")]
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/system/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use super::types::RawUname;
use crate::backend::conv::{ret, ret_infallible, slice};
Expand Down
4 changes: 1 addition & 3 deletions src/backend/linux_raw/termios/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::{by_ref, c_uint, ret};
Expand Down Expand Up @@ -230,7 +229,6 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool {
}

#[cfg(all(feature = "alloc", feature = "procfs"))]
#[allow(unsafe_code)]
pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> {
let fd_stat = crate::backend::fs::syscalls::fstat(fd)?;

Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::{
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/time/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{ret, ret_infallible};
use crate::clockid::ClockId;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/linux_raw/ugid/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::ret_usize_infallible;
Expand Down
4 changes: 2 additions & 2 deletions src/bitcast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(unused_macros)]

// Ensure that the source and destination types are both primitive integer
// types and the same size, and then bitcast.
#[allow(unused_macros)]
macro_rules! bitcast {
($x:expr) => {{
if false {
Expand All @@ -24,7 +25,6 @@ macro_rules! bitcast {

/// Return a [`bitcast`] of the value of `$x.bits()`, where `$x` is a
/// `bitflags` type.
#[allow(unused_macros)]
macro_rules! bitflags_bits {
($x:expr) => {{
bitcast!($x.bits())
Expand Down
2 changes: 1 addition & 1 deletion src/fs/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)
let mode = backend::fs::syscalls::fcntl_getfl(fd)?;

// Check for `O_PATH`.
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "emscripten"))]
#[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))]
if mode.contains(OFlags::PATH) {
return Ok((false, false));
}
Expand Down
Loading

0 comments on commit 37ef021

Please sign in to comment.