Skip to content
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
7 changes: 0 additions & 7 deletions ci/style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ while IFS= read -r file; do
# wouldn't be correct for something like `all(any(...), ...)`).
perl -pi -0777 -e 's/if #\[cfg\((.*?)\)\]/if cfg_tmp!([$1])/gms' "$file"

# We have some instances of `{const}` that make macros happy but aren't
# valid syntax. Replace this with just the keyword, plus an indicator
# comment on the preceding line (which is where rustfmt puts it. Also
# rust-lang/rustfmt#5464).
perl -pi -e 's/^(\s*)(.*)\{const\}/$1\/\* FMT-CONST \*\/\n$1$2const/g' "$file"

# Format the file. We need to invoke `rustfmt` directly since `cargo fmt`
# can't figure out the module tree with the hacks in place.
failed=false
Expand All @@ -45,7 +39,6 @@ while IFS= read -r file; do
# Restore all changes to the files.
perl -pi -e 's/fn (\w+)_fmt_tmp\(\)/$1!/g' "$file"
perl -pi -0777 -e 's/cfg_tmp!\(\[(.*?)\]\)/#[cfg($1)]/gms' "$file"
perl -pi -0777 -e 's/\/\* FMT-CONST \*\/(?:\n\s*)?(.*?)const/$1\{const\}/gms' "$file"

# Defer emitting the failure until after the files get reset
if [ "$failed" != "false" ]; then
Expand Down
30 changes: 15 additions & 15 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3374,57 +3374,57 @@ f! {
}
}

pub {const} fn CMSG_ALIGN(len: size_t) -> size_t {
pub const fn CMSG_ALIGN(len: size_t) -> size_t {
(len + size_of::<size_t>() - 1) & !(size_of::<size_t>() - 1)
}

pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint {
pub const fn CMSG_SPACE(len: c_uint) -> c_uint {
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
}

pub {const} fn CMSG_LEN(len: c_uint) -> c_uint {
pub const fn CMSG_LEN(len: c_uint) -> c_uint {
(CMSG_ALIGN(size_of::<cmsghdr>()) + len as size_t) as c_uint
}
}

safe_f! {
pub {const} fn WIFSTOPPED(status: c_int) -> bool {
pub const fn WIFSTOPPED(status: c_int) -> bool {
(status & 0xff) == 0x7f
}

pub {const} fn WSTOPSIG(status: c_int) -> c_int {
pub const fn WSTOPSIG(status: c_int) -> c_int {
(status >> 8) & 0xff
}

pub {const} fn WIFCONTINUED(status: c_int) -> bool {
pub const fn WIFCONTINUED(status: c_int) -> bool {
status == 0xffff
}

pub {const} fn WIFSIGNALED(status: c_int) -> bool {
pub const fn WIFSIGNALED(status: c_int) -> bool {
((status & 0x7f) + 1) as i8 >= 2
}

pub {const} fn WTERMSIG(status: c_int) -> c_int {
pub const fn WTERMSIG(status: c_int) -> c_int {
status & 0x7f
}

pub {const} fn WIFEXITED(status: c_int) -> bool {
pub const fn WIFEXITED(status: c_int) -> bool {
(status & 0x7f) == 0
}

pub {const} fn WEXITSTATUS(status: c_int) -> c_int {
pub const fn WEXITSTATUS(status: c_int) -> c_int {
(status >> 8) & 0xff
}

pub {const} fn WCOREDUMP(status: c_int) -> bool {
pub const fn WCOREDUMP(status: c_int) -> bool {
(status & 0x80) != 0
}

pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int {
pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int {
(cmd << 8) | (type_ & 0x00ff)
}

pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
let major = major as crate::dev_t;
let minor = minor as crate::dev_t;
let mut dev = 0;
Expand All @@ -3435,14 +3435,14 @@ safe_f! {
dev
}

pub {const} fn major(dev: crate::dev_t) -> c_uint {
pub const fn major(dev: crate::dev_t) -> c_uint {
let mut major = 0;
major |= (dev & 0x00000000000fff00) >> 8;
major |= (dev & 0xfffff00000000000) >> 32;
major as c_uint
}

pub {const} fn minor(dev: crate::dev_t) -> c_uint {
pub const fn minor(dev: crate::dev_t) -> c_uint {
let mut minor = 0;
minor |= (dev & 0x00000000000000ff) >> 0;
minor |= (dev & 0x00000ffffff00000) >> 12;
Expand Down
36 changes: 14 additions & 22 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,42 +296,34 @@ macro_rules! c_enum {
macro_rules! f {
($(
$(#[$attr:meta])*
pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty
// Less than ideal hack to match either `fn` or `const fn`.
pub $(fn $i:ident)? $(const fn $const_i:ident)?
($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty
$body:block
)*) => ($(
)+) => {$(
#[inline]
$(#[$attr])*
pub $($constness)? unsafe extern "C" fn $i($($arg: $argty),*) -> $ret
pub $(unsafe extern "C" fn $i)? $(const unsafe extern "C" fn $const_i)?
($($arg: $argty),*) -> $ret
$body
)*)
)+};
}

/// Define a safe function.
macro_rules! safe_f {
($(
$(#[$attr:meta])*
pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty
// Less than ideal hack to match either `fn` or `const fn`.
pub $(fn $i:ident)? $(const fn $const_i:ident)?
($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty
$body:block
)*) => ($(
#[inline]
$(#[$attr])*
pub $($constness)? extern "C" fn $i($($arg: $argty),*) -> $ret
$body
)*)
}

/// Define a nonpublic function.
macro_rules! const_fn {
($(
$(#[$attr:meta])*
$({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty
$body:block
)*) => ($(
)+) => {$(
#[inline]
$(#[$attr])*
$($constness)? fn $i($($arg: $argty),*) -> $ret
pub $(extern "C" fn $i)? $(const extern "C" fn $const_i)?
($($arg: $argty),*) -> $ret
$body
)*)
)+};
}

macro_rules! __item {
Expand Down
26 changes: 13 additions & 13 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,11 +2457,11 @@ f! {
(cmsg as *mut c_uchar).offset(size_of::<cmsghdr>() as isize)
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
pub const fn CMSG_LEN(length: c_uint) -> c_uint {
size_of::<cmsghdr>() as c_uint + length
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
pub const fn CMSG_SPACE(length: c_uint) -> c_uint {
size_of::<cmsghdr>() as c_uint + length
}

Expand Down Expand Up @@ -2493,62 +2493,62 @@ f! {
}

safe_f! {
pub {const} fn WIFSTOPPED(status: c_int) -> bool {
pub const fn WIFSTOPPED(status: c_int) -> bool {
(status & _W_STOPPED) != 0
}

pub {const} fn WSTOPSIG(status: c_int) -> c_int {
pub const fn WSTOPSIG(status: c_int) -> c_int {
if WIFSTOPPED(status) {
(((status as c_uint) >> 8) & 0xff) as c_int
} else {
-1
}
}

pub {const} fn WIFEXITED(status: c_int) -> bool {
pub const fn WIFEXITED(status: c_int) -> bool {
(status & 0xFF) == 0
}

pub {const} fn WEXITSTATUS(status: c_int) -> c_int {
pub const fn WEXITSTATUS(status: c_int) -> c_int {
if WIFEXITED(status) {
(((status as c_uint) >> 8) & 0xff) as c_int
} else {
-1
}
}

pub {const} fn WIFSIGNALED(status: c_int) -> bool {
pub const fn WIFSIGNALED(status: c_int) -> bool {
!WIFEXITED(status) && !WIFSTOPPED(status)
}

pub {const} fn WTERMSIG(status: c_int) -> c_int {
pub const fn WTERMSIG(status: c_int) -> c_int {
if WIFSIGNALED(status) {
(((status as c_uint) >> 16) & 0xff) as c_int
} else {
-1
}
}

pub {const} fn WIFCONTINUED(status: c_int) -> bool {
pub const fn WIFCONTINUED(status: c_int) -> bool {
(status & WCONTINUED) != 0
}

// AIX doesn't have native WCOREDUMP.
pub {const} fn WCOREDUMP(_status: c_int) -> bool {
pub const fn WCOREDUMP(_status: c_int) -> bool {
false
}

pub {const} fn major(dev: crate::dev_t) -> c_uint {
pub const fn major(dev: crate::dev_t) -> c_uint {
let x = dev >> 16;
x as c_uint
}

pub {const} fn minor(dev: crate::dev_t) -> c_uint {
pub const fn minor(dev: crate::dev_t) -> c_uint {
let y = dev & 0xFFFF;
y as c_uint
}

pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
let major = major as crate::dev_t;
let minor = minor as crate::dev_t;
let mut dev = 0;
Expand Down
22 changes: 11 additions & 11 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5022,49 +5022,49 @@ f! {
(cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(size_of::<cmsghdr>()))
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
pub const fn CMSG_SPACE(length: c_uint) -> c_uint {
(__DARWIN_ALIGN32(size_of::<cmsghdr>()) + __DARWIN_ALIGN32(length as usize)) as c_uint
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
pub const fn CMSG_LEN(length: c_uint) -> c_uint {
(__DARWIN_ALIGN32(size_of::<cmsghdr>()) + length as usize) as c_uint
}

pub {const} fn VM_MAKE_TAG(id: u8) -> u32 {
pub const fn VM_MAKE_TAG(id: u8) -> u32 {
(id as u32) << 24u32
}
}

safe_f! {
pub {const} fn WSTOPSIG(status: c_int) -> c_int {
pub const fn WSTOPSIG(status: c_int) -> c_int {
status >> 8
}

pub {const} fn _WSTATUS(status: c_int) -> c_int {
pub const fn _WSTATUS(status: c_int) -> c_int {
status & 0x7f
}

pub {const} fn WIFCONTINUED(status: c_int) -> bool {
pub const fn WIFCONTINUED(status: c_int) -> bool {
_WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) == 0x13
}

pub {const} fn WIFSIGNALED(status: c_int) -> bool {
pub const fn WIFSIGNALED(status: c_int) -> bool {
_WSTATUS(status) != _WSTOPPED && _WSTATUS(status) != 0
}

pub {const} fn WIFSTOPPED(status: c_int) -> bool {
pub const fn WIFSTOPPED(status: c_int) -> bool {
_WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13
}

pub {const} fn makedev(major: i32, minor: i32) -> dev_t {
pub const fn makedev(major: i32, minor: i32) -> dev_t {
(major << 24) | minor
}

pub {const} fn major(dev: dev_t) -> i32 {
pub const fn major(dev: dev_t) -> i32 {
(dev >> 24) & 0xff
}

pub {const} fn minor(dev: dev_t) -> i32 {
pub const fn minor(dev: dev_t) -> i32 {
dev & 0xffffff
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,18 +1421,16 @@ pub const RTAX_MPLS2: c_int = 9;
pub const RTAX_MPLS3: c_int = 10;
pub const RTAX_MAX: c_int = 11;

const_fn! {
{const} fn _CMSG_ALIGN(n: usize) -> usize {
(n + (size_of::<c_long>() - 1)) & !(size_of::<c_long>() - 1)
}
const fn _CMSG_ALIGN(n: usize) -> usize {
(n + (size_of::<c_long>() - 1)) & !(size_of::<c_long>() - 1)
}

f! {
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
pub const fn CMSG_LEN(length: c_uint) -> c_uint {
(_CMSG_ALIGN(size_of::<cmsghdr>()) + length as usize) as c_uint
}

Expand All @@ -1448,7 +1446,7 @@ f! {
}
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
pub const fn CMSG_SPACE(length: c_uint) -> c_uint {
(_CMSG_ALIGN(size_of::<cmsghdr>()) + _CMSG_ALIGN(length as usize)) as c_uint
}

Expand Down Expand Up @@ -1477,11 +1475,11 @@ f! {
}

safe_f! {
pub {const} fn WIFSIGNALED(status: c_int) -> bool {
pub const fn WIFSIGNALED(status: c_int) -> bool {
(status & 0o177) != 0o177 && (status & 0o177) != 0
}

pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
let major = major as crate::dev_t;
let minor = minor as crate::dev_t;
let mut dev = 0;
Expand All @@ -1490,11 +1488,11 @@ safe_f! {
dev
}

pub {const} fn major(dev: crate::dev_t) -> c_int {
pub const fn major(dev: crate::dev_t) -> c_int {
((dev >> 8) & 0xff) as c_int
}

pub {const} fn minor(dev: crate::dev_t) -> c_int {
pub const fn minor(dev: crate::dev_t) -> c_int {
(dev & 0xffff00ff) as c_int
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,17 @@ pub const MINCORE_SUPER: c_int = 0x20;
pub const SPECNAMELEN: c_int = 63;

safe_f! {
pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
let major = major as crate::dev_t;
let minor = minor as crate::dev_t;
(major << 8) | minor
}

pub {const} fn major(dev: crate::dev_t) -> c_int {
pub const fn major(dev: crate::dev_t) -> c_int {
((dev >> 8) & 0xff) as c_int
}

pub {const} fn minor(dev: crate::dev_t) -> c_int {
pub const fn minor(dev: crate::dev_t) -> c_int {
(dev & 0xffff00ff) as c_int
}
}
Expand Down
Loading
Loading