Constify `CMSG_SPACE` for all the targets

This commit is contained in:
JohnTitor 2021-03-30 15:28:55 +09:00
parent f913fc53a6
commit e187543fdd
8 changed files with 40 additions and 25 deletions

View File

@ -3256,12 +3256,12 @@ f! {
}
}
pub fn CMSG_ALIGN(len: ::size_t) -> ::size_t {
pub {const} fn CMSG_ALIGN(len: ::size_t) -> ::size_t {
(len + ::mem::size_of::<::size_t>() - 1)
& !(::mem::size_of::<::size_t>() - 1)
}
pub 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(::mem::size_of::<cmsghdr>()))
as ::c_uint
}

View File

@ -3366,7 +3366,12 @@ pub const MNT_WAIT: ::c_int = 1;
pub const MNT_NOWAIT: ::c_int = 2;
cfg_if! {
if #[cfg(libc_const_size_of)] {
if #[cfg(libc_const_extern_fn)] {
const fn __DARWIN_ALIGN32(p: usize) -> usize {
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
}
} else if #[cfg(libc_const_size_of)] {
fn __DARWIN_ALIGN32(p: usize) -> usize {
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
@ -3388,7 +3393,7 @@ f! {
let cmsg_len = (*cmsg).cmsg_len as usize;
let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize);
let max = (*mhdr).msg_control as usize
+ (*mhdr).msg_controllen as usize;
+ (*mhdr).msg_controllen as usize;
if next + __DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) > max {
0 as *mut ::cmsghdr
} else {
@ -3401,7 +3406,7 @@ f! {
.offset(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) as isize)
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>())
+ __DARWIN_ALIGN32(length as usize))
as ::c_uint

View File

@ -1020,8 +1020,10 @@ pub const SF_XLINK: ::c_ulong = 0x01000000;
pub const UTIME_OMIT: c_long = -2;
pub const UTIME_NOW: c_long = -1;
fn _CMSG_ALIGN(n: usize) -> usize {
(n + 3) & !3
const_fn! {
{const} fn _CMSG_ALIGN(n: usize) -> usize {
(n + 3) & !3
}
}
f! {
@ -1050,7 +1052,7 @@ f! {
}
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
_CMSG_ALIGN(length as usize)) as ::c_uint
}

View File

@ -1216,8 +1216,10 @@ pub const F_READAHEAD: ::c_int = 15;
pub const F_RDAHEAD: ::c_int = 16;
pub const F_DUP2FD_CLOEXEC: ::c_int = 18;
fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}
}
f! {
@ -1248,7 +1250,7 @@ f! {
}
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
as ::c_uint
}

View File

@ -1748,8 +1748,10 @@ pub const SF_SNAPSHOT: ::c_ulong = 0x00200000;
pub const SF_LOG: ::c_ulong = 0x00400000;
pub const SF_SNAPINVAL: ::c_ulong = 0x00800000;
fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}
}
f! {
@ -1780,7 +1782,7 @@ f! {
}
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
as ::c_uint
}

View File

@ -1397,8 +1397,10 @@ pub const PTRACE_FORK: ::c_int = 0x0002;
pub const WCONTINUED: ::c_int = 8;
fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}
}
f! {
@ -1429,7 +1431,7 @@ f! {
}
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
as ::c_uint
}

View File

@ -2103,12 +2103,14 @@ const _CMSG_HDR_ALIGNMENT: usize = 4;
const _CMSG_DATA_ALIGNMENT: usize = ::mem::size_of::<::c_int>();
fn _CMSG_HDR_ALIGN(p: usize) -> usize {
(p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1)
}
const_fn! {
{const} fn _CMSG_HDR_ALIGN(p: usize) -> usize {
(p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1)
}
fn _CMSG_DATA_ALIGN(p: usize) -> usize {
(p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1)
{const} fn _CMSG_DATA_ALIGN(p: usize) -> usize {
(p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1)
}
}
f! {
@ -2146,7 +2148,7 @@ f! {
}
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
_CMSG_HDR_ALIGN(::mem::size_of::<::cmsghdr>() as usize
+ length as usize) as ::c_uint
}

View File

@ -1040,7 +1040,7 @@ impl ::Clone for fpos_t {
}
f! {
pub fn CMSG_ALIGN(len: usize) -> usize {
pub {const} fn CMSG_ALIGN(len: usize) -> usize {
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
}
@ -1071,7 +1071,7 @@ f! {
.offset(CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize)
}
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::<cmsghdr>()))
as ::c_uint
}