Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch low-hanging fruit semver removals for libc and linux-raw-sys #1063

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/backend/libc/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use crate::backend::c;
use crate::backend::conv::ret_u32;
use crate::backend::conv::{ret, ret_owned_fd};
use crate::fd::{AsFd, AsRawFd, OwnedFd};
use crate::ffi;
use crate::io;
use crate::utils::as_mut_ptr;
#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -262,7 +263,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
/// success, this returns the number of written elements.
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
// behaves.
unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/libc/event/poll_fd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::backend::c;
use crate::backend::conv::borrowed_fd;
use crate::backend::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
use crate::ffi;
use bitflags::bitflags;
use core::marker::PhantomData;
#[cfg(windows)]
Expand All @@ -15,7 +16,7 @@ bitflags! {
/// [`poll`]: crate::event::poll
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct PollFlags: c::c_short {
pub struct PollFlags: ffi::c_short {
/// `POLLIN`
const IN = c::POLLIN;
/// `POLLPRI`
Expand Down
13 changes: 7 additions & 6 deletions src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
Expand All @@ -8,7 +9,7 @@ bitflags! {
/// [`accessat`]: fn.accessat.html
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Access: c::c_int {
pub struct Access: ffi::c_int {
/// `R_OK`
const READ_OK = c::R_OK;

Expand Down Expand Up @@ -370,7 +371,7 @@ bitflags! {
/// [`fcopyfile`]: crate::fs::fcopyfile
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CopyfileFlags: c::c_uint {
pub struct CopyfileFlags: ffi::c_uint {
/// `COPYFILE_ACL`
const ACL = copyfile::ACL;

Expand Down Expand Up @@ -435,7 +436,7 @@ bitflags! {
/// [`renameat_with`]: crate::fs::renameat_with
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct RenameFlags: c::c_uint {
pub struct RenameFlags: ffi::c_uint {
/// `RENAME_EXCHANGE`
const EXCHANGE = bitcast!(c::RENAME_EXCHANGE);

Expand Down Expand Up @@ -590,7 +591,7 @@ bitflags! {
/// [`memfd_create`]: crate::fs::memfd_create
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MemfdFlags: c::c_uint {
pub struct MemfdFlags: ffi::c_uint {
/// `MFD_CLOEXEC`
const CLOEXEC = c::MFD_CLOEXEC;

Expand Down Expand Up @@ -1110,15 +1111,15 @@ pub type RawMode = c::mode_t;

/// `mode_t`
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
pub type RawMode = c::c_uint;
pub type RawMode = ffi::c_uint;

/// `dev_t`
#[cfg(not(all(target_os = "android", target_pointer_width = "32")))]
pub type Dev = c::dev_t;

/// `dev_t`
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
pub type Dev = c::c_ulonglong;
pub type Dev = ffi::c_ulonglong;

/// `__fsword_t`
#[cfg(all(
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/pipe/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(linux_kernel)]
use core::marker::PhantomData;
#[cfg(not(any(apple, target_os = "wasi")))]
use {crate::backend::c, bitflags::bitflags};
use {crate::backend::c, crate::ffi, bitflags::bitflags};

#[cfg(not(any(apple, target_os = "wasi")))]
bitflags! {
Expand Down Expand Up @@ -38,7 +38,7 @@ bitflags! {
/// [`tee`].
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SpliceFlags: c::c_uint {
pub struct SpliceFlags: ffi::c_uint {
/// `SPLICE_F_MOVE`
const MOVE = c::SPLICE_F_MOVE;
/// `SPLICE_F_NONBLOCK`
Expand Down
1 change: 1 addition & 0 deletions src/backend/libc/termios/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod syscalls;
pub(crate) mod types;
13 changes: 13 additions & 0 deletions src/backend/libc/termios/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(not(target_os = "redox"))]
use crate::ffi;

// We don't want to use tcflag_t directly so we don't expose libc
// publicly. Redox uses u32, apple uses c_ulong, everything else
// seems to use c_uint.

#[cfg(apple)]
pub type tcflag_t = ffi::c_ulong;
#[cfg(target_os = "redox")]
pub type tcflag_t = u32;
#[cfg(not(any(apple, target_os = "redox")))]
pub type tcflag_t = ffi::c_uint;
8 changes: 5 additions & 3 deletions src/backend/linux_raw/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@

#![allow(unsafe_code)]

use crate::backend::c;
use crate::backend::event::syscalls;
use crate::fd::{AsFd, AsRawFd, OwnedFd};
use crate::ffi;
use crate::io;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand All @@ -86,7 +86,7 @@ bitflags! {
/// `EPOLL_*` for use with [`new`].
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CreateFlags: c::c_uint {
pub struct CreateFlags: ffi::c_uint {
/// `EPOLL_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::EPOLL_CLOEXEC;

Expand Down Expand Up @@ -242,7 +242,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[inline]
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
// behaves.
unsafe {
Expand Down Expand Up @@ -463,6 +463,8 @@ impl<'a> IntoIterator for &'a EventVec {

#[test]
fn test_epoll_layouts() {
use crate::backend::c;

check_renamed_type!(Event, epoll_event);
check_renamed_type!(Event, epoll_event);
check_renamed_struct_renamed_field!(Event, epoll_event, flags, events);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/event/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -7,7 +7,7 @@ bitflags! {
/// [`eventfd`]: crate::event::eventfd
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct EventfdFlags: c::c_uint {
pub struct EventfdFlags: ffi::c_uint {
/// `EFD_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::EFD_CLOEXEC;
/// `EFD_NONBLOCK`
Expand Down
6 changes: 3 additions & 3 deletions src/backend/linux_raw/fs/inotify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! inotify support for working with inotifies

use crate::backend::c;
use crate::backend::fs::syscalls;
use crate::fd::{BorrowedFd, OwnedFd};
use crate::ffi;
use crate::io;
use bitflags::bitflags;

Expand All @@ -12,7 +12,7 @@ bitflags! {
/// [`inotify_init`]: crate::fs::inotify::inotify_init
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CreateFlags: c::c_uint {
pub struct CreateFlags: ffi::c_uint {
/// `IN_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
/// `IN_NONBLOCK`
Expand All @@ -29,7 +29,7 @@ bitflags! {
/// [`inotify_add_watch`]: crate::fs::inotify::inotify_add_watch
#[repr(transparent)]
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct WatchFlags: c::c_uint {
pub struct WatchFlags: ffi::c_uint {
/// `IN_ACCESS`
const ACCESS = linux_raw_sys::general::IN_ACCESS;
/// `IN_ATTRIB`
Expand Down
14 changes: 7 additions & 7 deletions src/backend/linux_raw/fs/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -7,7 +7,7 @@ bitflags! {
/// [`accessat`]: fn.accessat.html
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Access: c::c_uint {
pub struct Access: ffi::c_uint {
/// `R_OK`
const READ_OK = linux_raw_sys::general::R_OK;

Expand All @@ -33,7 +33,7 @@ bitflags! {
/// [`statat`]: crate::fs::statat
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct AtFlags: c::c_uint {
pub struct AtFlags: ffi::c_uint {
/// `AT_SYMLINK_NOFOLLOW`
const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;

Expand Down Expand Up @@ -172,7 +172,7 @@ bitflags! {
/// [`openat`]: crate::fs::openat
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct OFlags: c::c_uint {
pub struct OFlags: ffi::c_uint {
/// `O_ACCMODE`
const ACCMODE = linux_raw_sys::general::O_ACCMODE;

Expand Down Expand Up @@ -291,7 +291,7 @@ bitflags! {
/// [`renameat_with`]: crate::fs::renameat_with
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct RenameFlags: c::c_uint {
pub struct RenameFlags: ffi::c_uint {
/// `RENAME_EXCHANGE`
const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;

Expand Down Expand Up @@ -418,7 +418,7 @@ bitflags! {
/// [`memfd_create`]: crate::fs::memfd_create
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MemfdFlags: c::c_uint {
pub struct MemfdFlags: ffi::c_uint {
/// `MFD_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;

Expand Down Expand Up @@ -724,7 +724,7 @@ pub type RawMode = linux_raw_sys::general::__kernel_mode_t;
target_arch = "arm",
))]
// Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`.
pub type RawMode = c::c_uint;
pub type RawMode = ffi::c_uint;

/// `dev_t`
// Within the kernel the dev_t is 32-bit, but userspace uses a 64-bit field.
Expand Down
8 changes: 4 additions & 4 deletions src/backend/linux_raw/io/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -8,7 +8,7 @@ bitflags! {
/// [`fcntl_setfd`]: crate::io::fcntl_setfd
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FdFlags: c::c_uint {
pub struct FdFlags: ffi::c_uint {
/// `FD_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC;

Expand All @@ -24,7 +24,7 @@ bitflags! {
/// [`pwritev2`]: crate::io::pwritev
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ReadWriteFlags: c::c_uint {
pub struct ReadWriteFlags: ffi::c_uint {
/// `RWF_DSYNC` (since Linux 4.7)
const DSYNC = linux_raw_sys::general::RWF_DSYNC;
/// `RWF_HIPRI` (since Linux 4.6)
Expand All @@ -47,7 +47,7 @@ bitflags! {
/// [`dup2`]: crate::io::dup2
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct DupFlags: c::c_uint {
pub struct DupFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;

Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/mm/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand Down Expand Up @@ -252,7 +252,7 @@ bitflags! {
/// [`userfaultfd`]: crate::mm::userfaultfd
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct UserfaultfdFlags: c::c_uint {
pub struct UserfaultfdFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
/// `O_NONBLOCK`
Expand Down
9 changes: 5 additions & 4 deletions src/backend/linux_raw/pipe/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;
use core::marker::PhantomData;

Expand All @@ -8,7 +9,7 @@ bitflags! {
/// [`pipe_with`]: crate::pipe::pipe_with
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct PipeFlags: c::c_uint {
pub struct PipeFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
/// `O_DIRECT`
Expand All @@ -26,7 +27,7 @@ bitflags! {
/// [`tee`].
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SpliceFlags: c::c_uint {
pub struct SpliceFlags: ffi::c_uint {
/// `SPLICE_F_MOVE`
const MOVE = linux_raw_sys::general::SPLICE_F_MOVE;
/// `SPLICE_F_NONBLOCK`
Expand Down Expand Up @@ -60,7 +61,7 @@ impl<'a> IoSliceRaw<'a> {
pub fn from_slice(buf: &'a [u8]) -> Self {
IoSliceRaw {
_buf: c::iovec {
iov_base: (buf.as_ptr() as *mut u8).cast::<c::c_void>(),
iov_base: (buf.as_ptr() as *mut u8).cast::<ffi::c_void>(),
iov_len: buf.len() as _,
},
_lifetime: PhantomData,
Expand All @@ -71,7 +72,7 @@ impl<'a> IoSliceRaw<'a> {
pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
IoSliceRaw {
_buf: c::iovec {
iov_base: buf.as_mut_ptr().cast::<c::c_void>(),
iov_base: buf.as_mut_ptr().cast::<ffi::c_void>(),
iov_len: buf.len() as _,
},
_lifetime: PhantomData,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/shm/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -7,7 +7,7 @@ bitflags! {
/// [`shm_open`]: crate:shm::shm_open
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ShmOFlags: c::c_uint {
pub struct ShmOFlags: ffi::c_uint {
/// `O_CREAT`
#[doc(alias = "CREAT")]
const CREATE = linux_raw_sys::general::O_CREAT;
Expand Down
1 change: 1 addition & 0 deletions src/backend/linux_raw/termios/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod syscalls;
pub(crate) mod types;
9 changes: 9 additions & 0 deletions src/backend/linux_raw/termios/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::ffi;

// We don't want to use tcflag_t directly so we don't expose linux_raw_sys
// publicly. It appears to be c_ulong on SPARC and c_uint everywhere else.

#[cfg(target_arch = "sparc")]
pub type tcflag_t = ffi::c_ulong;
#[cfg(not(target_arch = "sparc"))]
pub type tcflag_t = ffi::c_uint;
Loading
Loading