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

Add some comments and minor cleanups #132

Merged
merged 22 commits into from
Dec 2, 2021
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Reduce the scope of the allow(missing_docs) and add more docs.
sunfishcode committed Dec 2, 2021
commit 3d82f69629f7d129620efdede4d3ebb35d09f64b
2 changes: 2 additions & 0 deletions src/imp/libc/io/epoll.rs
Original file line number Diff line number Diff line change
@@ -54,6 +54,8 @@
//! # }
//! ```
#![allow(missing_docs)] // TODO: Write more docs.

use super::super::c;
use super::super::conv::{ret, ret_owned_fd, ret_u32};
use super::super::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};
2 changes: 2 additions & 0 deletions src/imp/libc/io/error.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
//! This type holds an OS error code, which conceptually corresponds to an
//! `errno` value.
#![allow(missing_docs)]

use super::super::c;
use errno::errno;

4 changes: 4 additions & 0 deletions src/imp/libc/io/types.rs
Original file line number Diff line number Diff line change
@@ -429,11 +429,15 @@ pub type Termios = c::termios;
#[cfg(not(target_os = "wasi"))]
pub type Winsize = c::winsize;

/// `tcflag_t`—A type for the flags fields of [`Termios`].
#[cfg(not(target_os = "wasi"))]
pub type Tcflag = c::tcflag_t;

/// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating
/// canonical mode.
#[cfg(not(target_os = "wasi"))]
pub const ICANON: Tcflag = c::ICANON;

/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
pub const PIPE_BUF: usize = c::PIPE_BUF;
33 changes: 33 additions & 0 deletions src/imp/libc/io_lifetimes.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,13 @@ pub(crate) use io_lifetimes::OwnedSocket as OwnedFd;
pub use std::os::windows::io::RawSocket as RawFd;
pub(crate) use winapi::um::winsock2::SOCKET as LibcFd;

/// A version of [`AsRawFd`] for use with Winsock APIs.
///
/// [`AsRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsRawFd.html
pub trait AsRawFd {
/// A version of [`as_raw_fd`] for use with Winsock APIs.
///
/// [`as_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.as_raw_fd
fn as_raw_fd(&self) -> RawFd;
}
#[cfg(feature = "std")]
@@ -20,7 +26,13 @@ impl<T: std::os::windows::io::AsRawSocket> AsRawFd for T {
}
}

/// A version of [`IntoRawFd`] for use with Winsock APIs.
///
/// [`IntoRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.IntoRawFd.html
pub trait IntoRawFd {
/// A version of [`into_raw_fd`] for use with Winsock APIs.
///
/// [`into_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.into_raw_fd
fn into_raw_fd(self) -> RawFd;
}
#[cfg(feature = "std")]
@@ -31,7 +43,13 @@ impl<T: std::os::windows::io::IntoRawSocket> IntoRawFd for T {
}
}

/// A version of [`FromRawFd`] for use with Winsock APIs.
///
/// [`FromRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html
pub trait FromRawFd {
/// A version of [`from_raw_fd`] for use with Winsock APIs.
///
/// [`from_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self;
}
#[cfg(feature = "std")]
@@ -42,6 +60,9 @@ impl<T: std::os::windows::io::FromRawSocket> FromRawFd for T {
}
}

/// A version of [`AsFd`] for use with Winsock APIs.
///
/// [`AsFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsFd.html
pub use io_lifetimes::AsSocket as AsFd;

/// We define `AsFd` as an alias for `AsSocket`, but that doesn't provide
@@ -57,7 +78,13 @@ impl<T: io_lifetimes::AsSocket> AsSocketAsFd for T {
}
}

/// A version of [`IntoFd`] for use with Winsock APIs.
///
/// [`IntoFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html
pub trait IntoFd {
/// A version of [`into_fd`] for use with Winsock APIs.
///
/// [`into_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html#tymethod.into_fd
fn into_fd(self) -> OwnedFd;
}
impl<T: io_lifetimes::IntoSocket> IntoFd for T {
@@ -67,7 +94,13 @@ impl<T: io_lifetimes::IntoSocket> IntoFd for T {
}
}

/// A version of [`FromFd`] for use with Winsock APIs.
///
/// [`FromFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html
pub trait FromFd {
/// A version of [`from_fd`] for use with Winsock APIs.
///
/// [`from_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html#tymethod.from_fd
fn from_fd(fd: OwnedFd) -> Self;
}
impl<T: io_lifetimes::FromSocket> FromFd for T {
4 changes: 3 additions & 1 deletion src/imp/libc/process/mod.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ pub(crate) use c::{
target_os = "dragonfly"
))]
pub(crate) mod cpu_set;
#[cfg(not(target_os = "wasi"))]
pub(crate) use types::RawUname;
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
pub use types::Resource;
#[cfg(any(
@@ -35,5 +37,5 @@ pub(crate) use types::{raw_cpu_set_new, RawCpuSet, CPU_SETSIZE};
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use types::{MembarrierCommand, RawCpuid};
#[cfg(not(target_os = "wasi"))]
pub use types::{RawGid, RawPid, RawUid, RawUname, EXIT_SIGNALED_SIGABRT};
pub use types::{RawGid, RawPid, RawUid, EXIT_SIGNALED_SIGABRT};
pub use types::{EXIT_FAILURE, EXIT_SUCCESS};
6 changes: 5 additions & 1 deletion src/imp/libc/process/types.rs
Original file line number Diff line number Diff line change
@@ -140,17 +140,21 @@ pub const EXIT_FAILURE: c::c_int = c::EXIT_FAILURE;
#[cfg(not(target_os = "wasi"))]
pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT;

/// A process identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawPid = c::pid_t;
/// A group identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawGid = c::gid_t;
/// A user identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawUid = c::uid_t;
/// A CPU identifier as a raw integer.
#[cfg(any(target_os = "android", target_os = "linux"))]
pub type RawCpuid = u32;

#[cfg(not(target_os = "wasi"))]
pub type RawUname = c::utsname;
pub(crate) type RawUname = c::utsname;

#[cfg(any(
target_os = "linux",
7 changes: 5 additions & 2 deletions src/imp/libc/rand/types.rs
Original file line number Diff line number Diff line change
@@ -5,10 +5,13 @@ use bitflags::bitflags;

#[cfg(target_os = "linux")]
bitflags! {
/// `GRND_*` flags for use with [`getrandom`].
///
/// [`getrandom`]: crate::rand::getrandom
pub struct GetRandomFlags: u32 {
/// GRND_RANDOM
/// `GRND_RANDOM`
const RANDOM = c::GRND_RANDOM;
/// GRND_NONBLOCK
/// `GRND_NONBLOCK`
const NONBLOCK = c::GRND_NONBLOCK;
}
}
1 change: 1 addition & 0 deletions src/imp/linux_raw/io/epoll.rs
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
//! ```
#![allow(unsafe_code)]
#![allow(missing_docs)] // TODO: Write more docs.

use super::super::c;
use crate::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};
1 change: 1 addition & 0 deletions src/imp/linux_raw/io/error.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
//! Linux uses error codes in `-4095..0`; we use rustc attributes to describe
//! this restricted range of values.
#![allow(unsafe_code)]
#![allow(missing_docs)]
#![cfg_attr(not(rustc_attrs), allow(unused_unsafe))]

use super::super::c;
4 changes: 4 additions & 0 deletions src/imp/linux_raw/io/types.rs
Original file line number Diff line number Diff line change
@@ -249,8 +249,12 @@ pub type Termios = linux_raw_sys::general::termios;
/// [`ioctl_tiocgwinsz`]: crate::io::ioctl_tiocgwinsz
pub type Winsize = linux_raw_sys::general::winsize;

/// `tcflag_t`—A type for the flags fields of [`Termios`].
pub type Tcflag = linux_raw_sys::general::tcflag_t;

/// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating
/// canonical mode.
pub const ICANON: c::c_uint = linux_raw_sys::general::ICANON;

/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic.
pub const PIPE_BUF: usize = linux_raw_sys::general::PIPE_BUF as usize;
4 changes: 2 additions & 2 deletions src/imp/linux_raw/process/mod.rs
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ pub(crate) mod cpu_set;
pub(crate) use auxv::init;
pub(crate) use auxv::{exe_phdrs, linux_execfn, linux_hwcap, page_size};
pub(super) use auxv::{exe_phdrs_slice, sysinfo_ehdr};
pub(crate) use types::{raw_cpu_set_new, RawCpuSet, CPU_SETSIZE};
pub(crate) use types::{raw_cpu_set_new, RawCpuSet, RawUname, CPU_SETSIZE};
pub use types::{
MembarrierCommand, RawCpuid, RawGid, RawPid, RawUid, RawUname, Resource, EXIT_FAILURE,
MembarrierCommand, RawCpuid, RawGid, RawPid, RawUid, Resource, EXIT_FAILURE,
EXIT_SIGNALED_SIGABRT, EXIT_SUCCESS,
};
pub(crate) use wait::{
9 changes: 8 additions & 1 deletion src/imp/linux_raw/process/types.rs
Original file line number Diff line number Diff line change
@@ -74,16 +74,23 @@ pub enum Resource {
Rttime = linux_raw_sys::general::RLIMIT_RTTIME,
}

/// `EXIT_SUCCESS`
pub const EXIT_SUCCESS: c::c_int = 0;
/// `EXIT_FAILURE`
pub const EXIT_FAILURE: c::c_int = 1;
/// The status value of a child terminated with `SIGABRT`.
pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + linux_raw_sys::general::SIGABRT as i32;

/// A process identifier as a raw integer.
pub type RawPid = u32;
/// A group identifier as a raw integer.
pub type RawGid = u32;
/// A user identifier as a raw integer.
pub type RawUid = u32;
/// A CPU identifier as a raw integer.
pub type RawCpuid = u32;

pub type RawUname = linux_raw_sys::general::new_utsname;
pub(crate) type RawUname = linux_raw_sys::general::new_utsname;

#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
7 changes: 5 additions & 2 deletions src/imp/linux_raw/rand/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use bitflags::bitflags;

bitflags! {
/// `GRND_*` flags for use with [`getrandom`].
///
/// [`getrandom`]: crate::rand::getrandom
pub struct GetRandomFlags: u32 {
/// GRND_RANDOM
/// `GRND_RANDOM`
const RANDOM = linux_raw_sys::v5_4::general::GRND_RANDOM;
/// GRND_NONBLOCK
/// `GRND_NONBLOCK`
const NONBLOCK = linux_raw_sys::v5_4::general::GRND_NONBLOCK;
}
}
3 changes: 3 additions & 0 deletions src/imp/linux_raw/time/types.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ use super::super::fd::BorrowedFd;
/// `struct timespec`
pub type Timespec = linux_raw_sys::general::__kernel_timespec;

/// A type for the `tv_sec` field of [`Timespec`].
pub type Secs = linux_raw_sys::general::__kernel_time64_t;

/// A type for the `tv_nsec` field of [`Timespec`].
pub type Nsecs = i64;

/// `CLOCK_*` constants for use with [`clock_gettime`].
2 changes: 0 additions & 2 deletions src/imp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! The "imp"-lementation module. This selects the backend to use.
#![allow(missing_docs)]

#[cfg(libc)]
mod libc;
#[cfg(linux_raw)]