Skip to content

Commit c636c2b

Browse files
authored
Fix compilation on various cfg configurations (#1119)
Fix some clippy lints, and fix compilation on various targets with various feature flags enabled.
1 parent 4440881 commit c636c2b

File tree

12 files changed

+41
-31
lines changed

12 files changed

+41
-31
lines changed

src/backend/libc/c.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ pub(crate) const XCASE: tcflag_t = linux_raw_sys::general::XCASE as _;
8686
#[cfg(target_os = "aix")]
8787
pub(crate) const MSG_DONTWAIT: c_int = libc::MSG_NONBLOCK;
8888

89-
// TODO: Remove once https://github.com/rust-lang/libc/pull/3377 is merged and released.
89+
// TODO: Remove once <https://github.com/rust-lang/libc/pull/3377> is merged and released.
9090
#[cfg(target_os = "netbsd")]
9191
#[cfg(feature = "net")]
9292
pub(crate) const SO_NOSIGPIPE: c_int = 0x0800;
9393

94-
// It is defined as 0 in libc under 64-bit platforms, but is automatically set by kernel.
95-
// https://github.com/torvalds/linux/blob/v6.7/fs/open.c#L1458-L1459
94+
// It is defined as 0 in libc under 64-bit platforms, but is automatically set
95+
// by kernel. <https://github.com/torvalds/linux/blob/v6.7/fs/open.c#L1458-L1459>
9696
#[cfg(linux_kernel)]
9797
pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _;
9898

9999
// Gated under `_LARGEFILE_SOURCE` but automatically set by the kernel.
100-
// https://github.com/illumos/illumos-gate/blob/fb2cb638e5604b214d8ea8d4f01ad2e77b437c17/usr/src/ucbhead/sys/fcntl.h#L64
100+
// <https://github.com/illumos/illumos-gate/blob/fb2cb638e5604b214d8ea8d4f01ad2e77b437c17/usr/src/ucbhead/sys/fcntl.h#L64>
101101
#[cfg(target_os = "illumos")]
102102
pub(crate) const O_LARGEFILE: c_int = 0x2000;
103103

src/backend/libc/event/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::event::PollFd;
88
#[cfg(any(linux_kernel, bsd, solarish, target_os = "espidf"))]
99
use crate::fd::OwnedFd;
1010
use crate::io;
11-
#[cfg(any(bsd, solarish))]
11+
#[cfg(any(all(feature = "alloc", bsd), solarish))]
1212
use {crate::backend::conv::borrowed_fd, crate::fd::BorrowedFd, core::mem::MaybeUninit};
1313
#[cfg(solarish)]
1414
use {

src/backend/libc/io/windows_syscalls.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Windows system calls in the `io` module.
22
33
use crate::backend::c;
4+
#[cfg(feature = "try_close")]
5+
use crate::backend::conv::ret;
46
use crate::backend::conv::{borrowed_fd, ret_c_int};
57
use crate::backend::fd::LibcFd;
68
use crate::fd::{BorrowedFd, RawFd};
@@ -11,6 +13,11 @@ pub(crate) unsafe fn close(raw_fd: RawFd) {
1113
let _ = c::close(raw_fd as LibcFd);
1214
}
1315

16+
#[cfg(feature = "try_close")]
17+
pub(crate) unsafe fn try_close(raw_fd: RawFd) -> io::Result<()> {
18+
ret(c::close(raw_fd as LibcFd))
19+
}
20+
1421
#[inline]
1522
pub(crate) unsafe fn ioctl(
1623
fd: BorrowedFd<'_>,

src/backend/libc/process/syscalls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::types::RawCpuSet;
55
use crate::backend::c;
66
#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))]
77
use crate::backend::conv::borrowed_fd;
8-
#[cfg(feature = "fs")]
8+
#[cfg(any(target_os = "linux", feature = "fs"))]
99
use crate::backend::conv::c_str;
1010
#[cfg(all(feature = "alloc", feature = "fs", not(target_os = "wasi")))]
1111
use crate::backend::conv::ret_discarded_char_ptr;
@@ -28,7 +28,7 @@ use crate::backend::conv::{ret, ret_c_int};
2828
use crate::fd::BorrowedFd;
2929
#[cfg(target_os = "linux")]
3030
use crate::fd::{AsRawFd, OwnedFd, RawFd};
31-
#[cfg(feature = "fs")]
31+
#[cfg(any(target_os = "linux", feature = "fs"))]
3232
use crate::ffi::CStr;
3333
#[cfg(feature = "fs")]
3434
use crate::fs::Mode;

src/backend/linux_raw/event/epoll.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ pub fn create(flags: CreateFlags) -> io::Result<OwnedFd> {
172172
/// This registers interest in any of the events set in `events` occurring on
173173
/// the file descriptor associated with `data`.
174174
///
175-
/// Note that `close`ing a file descriptor does not necessarily unregister interest
176-
/// which can lead to spurious events being returned from [`wait`]. If a file descriptor
177-
/// is an `Arc<dyn SystemResource>`, then `epoll` can be thought to maintain a
178-
/// `Weak<dyn SystemResource>` to the file descriptor. Check the [faq] for details.
175+
/// Note that `close`ing a file descriptor does not necessarily unregister
176+
/// interest which can lead to spurious events being returned from [`wait`]. If
177+
/// a file descriptor is an `Arc<dyn SystemResource>`, then `epoll` can be
178+
/// thought to maintain a `Weak<dyn SystemResource>` to the file descriptor.
179+
/// Check the [faq] for details.
179180
///
180181
/// # References
181182
///

src/backend/linux_raw/event/syscalls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
77

88
use crate::backend::c;
9+
#[cfg(any(
10+
feature = "alloc",
11+
not(any(target_arch = "aarch64", target_arch = "riscv64"))
12+
))]
13+
use crate::backend::conv::c_int;
914
#[cfg(feature = "alloc")]
1015
use crate::backend::conv::pass_usize;
1116
use crate::backend::conv::{
12-
by_ref, c_int, c_uint, raw_fd, ret, ret_error, ret_owned_fd, ret_usize, slice_mut, zero,
17+
by_ref, c_uint, raw_fd, ret, ret_error, ret_owned_fd, ret_usize, slice_mut, zero,
1318
};
1419
use crate::event::{epoll, EventfdFlags, PollFd};
1520
use crate::fd::{BorrowedFd, OwnedFd};

src/backend/linux_raw/mm/syscalls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use crate::backend::conv::loff_t_from_u64;
1616
use crate::backend::conv::{c_uint, no_fd, pass_usize, ret, ret_owned_fd, ret_void_star};
1717
use crate::fd::{BorrowedFd, OwnedFd};
1818
use crate::io;
19-
use linux_raw_sys::general::MAP_ANONYMOUS;
20-
use linux_raw_sys::general::MREMAP_FIXED;
19+
use linux_raw_sys::general::{MAP_ANONYMOUS, MREMAP_FIXED};
2120

2221
#[inline]
2322
pub(crate) fn madvise(addr: *mut c::c_void, len: usize, advice: Advice) -> io::Result<()> {

src/fs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub use std::os::wasi::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, Open
150150
/// the Unix epoch. Until the next semver bump, these unsigned fields are
151151
/// deprecated, and this trait provides accessors which return their values
152152
/// as signed integers.
153-
#[cfg(all(unix))]
153+
#[cfg(unix)]
154154
pub trait StatExt {
155155
/// Return the value of the `st_atime` field, casted to the correct type.
156156
fn atime(&self) -> i64;

src/net/netdevice.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
//!
33
//! The methods in this module take a socket's file descriptor to communicate
44
//! with the kernel in their ioctl call:
5-
//! - glibc uses an `AF_UNIX`, `AF_INET`, or `AF_INET6` socket.
6-
//! The address family itself does not matter and glibc tries the next address
7-
//! family if socket creation with one fails.
5+
//! - glibc uses an `AF_UNIX`, `AF_INET`, or `AF_INET6` socket. The address
6+
//! family itself does not matter and glibc tries the next address family if
7+
//! socket creation with one fails.
88
//! - Android (bionic) uses an `AF_INET` socket.
99
//! - Both create the socket with `SOCK_DGRAM|SOCK_CLOEXEC` type/flag.
1010
//! - The [man-pages] specify, that the ioctl calls "can be used on any
11-
//! socket's file descriptor regardless of the
12-
//! family or type".
11+
//! socket's file descriptor regardless of the family or type".
1312
//!
1413
//! # References
1514
//! - [Linux]

src/process/procctl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ pub fn get_reaper_status(process: ProcSelector) -> io::Result<ReaperStatus> {
284284
})
285285
}
286286

287+
#[cfg(feature = "alloc")]
287288
const PROC_REAP_GETPIDS: c_int = 5;
288289

289290
bitflags! {

0 commit comments

Comments
 (0)