Skip to content

Commit f2e7721

Browse files
committed
Auto merge of #2132 - JohnTitor:cmsg-space, r=Amanieu
Constify `CMSG_SPACE` for all the targets `CMSG_SPACE` is a const fn for Linux but it isn't for other targets. This constifies it on all the targets for consistency. Fixes #2087
2 parents 8df930f + e187543 commit f2e7721

File tree

8 files changed

+40
-25
lines changed

8 files changed

+40
-25
lines changed

src/fuchsia/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,12 +3256,12 @@ f! {
32563256
}
32573257
}
32583258

3259-
pub fn CMSG_ALIGN(len: ::size_t) -> ::size_t {
3259+
pub {const} fn CMSG_ALIGN(len: ::size_t) -> ::size_t {
32603260
(len + ::mem::size_of::<::size_t>() - 1)
32613261
& !(::mem::size_of::<::size_t>() - 1)
32623262
}
32633263

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

src/unix/bsd/apple/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3366,7 +3366,12 @@ pub const MNT_WAIT: ::c_int = 1;
33663366
pub const MNT_NOWAIT: ::c_int = 2;
33673367

33683368
cfg_if! {
3369-
if #[cfg(libc_const_size_of)] {
3369+
if #[cfg(libc_const_extern_fn)] {
3370+
const fn __DARWIN_ALIGN32(p: usize) -> usize {
3371+
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
3372+
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
3373+
}
3374+
} else if #[cfg(libc_const_size_of)] {
33703375
fn __DARWIN_ALIGN32(p: usize) -> usize {
33713376
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
33723377
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
@@ -3388,7 +3393,7 @@ f! {
33883393
let cmsg_len = (*cmsg).cmsg_len as usize;
33893394
let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize);
33903395
let max = (*mhdr).msg_control as usize
3391-
+ (*mhdr).msg_controllen as usize;
3396+
+ (*mhdr).msg_controllen as usize;
33923397
if next + __DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) > max {
33933398
0 as *mut ::cmsghdr
33943399
} else {
@@ -3401,7 +3406,7 @@ f! {
34013406
.offset(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) as isize)
34023407
}
34033408

3404-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
3409+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
34053410
(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>())
34063411
+ __DARWIN_ALIGN32(length as usize))
34073412
as ::c_uint

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,10 @@ pub const SF_XLINK: ::c_ulong = 0x01000000;
10201020
pub const UTIME_OMIT: c_long = -2;
10211021
pub const UTIME_NOW: c_long = -1;
10221022

1023-
fn _CMSG_ALIGN(n: usize) -> usize {
1024-
(n + 3) & !3
1023+
const_fn! {
1024+
{const} fn _CMSG_ALIGN(n: usize) -> usize {
1025+
(n + 3) & !3
1026+
}
10251027
}
10261028

10271029
f! {
@@ -1050,7 +1052,7 @@ f! {
10501052
}
10511053
}
10521054

1053-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
1055+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
10541056
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
10551057
_CMSG_ALIGN(length as usize)) as ::c_uint
10561058
}

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,10 @@ pub const F_READAHEAD: ::c_int = 15;
12161216
pub const F_RDAHEAD: ::c_int = 16;
12171217
pub const F_DUP2FD_CLOEXEC: ::c_int = 18;
12181218

1219-
fn _ALIGN(p: usize) -> usize {
1220-
(p + _ALIGNBYTES) & !_ALIGNBYTES
1219+
const_fn! {
1220+
{const} fn _ALIGN(p: usize) -> usize {
1221+
(p + _ALIGNBYTES) & !_ALIGNBYTES
1222+
}
12211223
}
12221224

12231225
f! {
@@ -1248,7 +1250,7 @@ f! {
12481250
}
12491251
}
12501252

1251-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
1253+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
12521254
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
12531255
as ::c_uint
12541256
}

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,8 +1748,10 @@ pub const SF_SNAPSHOT: ::c_ulong = 0x00200000;
17481748
pub const SF_LOG: ::c_ulong = 0x00400000;
17491749
pub const SF_SNAPINVAL: ::c_ulong = 0x00800000;
17501750

1751-
fn _ALIGN(p: usize) -> usize {
1752-
(p + _ALIGNBYTES) & !_ALIGNBYTES
1751+
const_fn! {
1752+
{const} fn _ALIGN(p: usize) -> usize {
1753+
(p + _ALIGNBYTES) & !_ALIGNBYTES
1754+
}
17531755
}
17541756

17551757
f! {
@@ -1780,7 +1782,7 @@ f! {
17801782
}
17811783
}
17821784

1783-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
1785+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
17841786
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
17851787
as ::c_uint
17861788
}

src/unix/bsd/netbsdlike/openbsd/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,10 @@ pub const PTRACE_FORK: ::c_int = 0x0002;
13971397

13981398
pub const WCONTINUED: ::c_int = 8;
13991399

1400-
fn _ALIGN(p: usize) -> usize {
1401-
(p + _ALIGNBYTES) & !_ALIGNBYTES
1400+
const_fn! {
1401+
{const} fn _ALIGN(p: usize) -> usize {
1402+
(p + _ALIGNBYTES) & !_ALIGNBYTES
1403+
}
14021404
}
14031405

14041406
f! {
@@ -1429,7 +1431,7 @@ f! {
14291431
}
14301432
}
14311433

1432-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
1434+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
14331435
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
14341436
as ::c_uint
14351437
}

src/unix/solarish/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,12 +2103,14 @@ const _CMSG_HDR_ALIGNMENT: usize = 4;
21032103

21042104
const _CMSG_DATA_ALIGNMENT: usize = ::mem::size_of::<::c_int>();
21052105

2106-
fn _CMSG_HDR_ALIGN(p: usize) -> usize {
2107-
(p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1)
2108-
}
2106+
const_fn! {
2107+
{const} fn _CMSG_HDR_ALIGN(p: usize) -> usize {
2108+
(p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1)
2109+
}
21092110

2110-
fn _CMSG_DATA_ALIGN(p: usize) -> usize {
2111-
(p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1)
2111+
{const} fn _CMSG_DATA_ALIGN(p: usize) -> usize {
2112+
(p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1)
2113+
}
21122114
}
21132115

21142116
f! {
@@ -2146,7 +2148,7 @@ f! {
21462148
}
21472149
}
21482150

2149-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
2151+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
21502152
_CMSG_HDR_ALIGN(::mem::size_of::<::cmsghdr>() as usize
21512153
+ length as usize) as ::c_uint
21522154
}

src/vxworks/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ impl ::Clone for fpos_t {
10401040
}
10411041

10421042
f! {
1043-
pub fn CMSG_ALIGN(len: usize) -> usize {
1043+
pub {const} fn CMSG_ALIGN(len: usize) -> usize {
10441044
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
10451045
}
10461046

@@ -1071,7 +1071,7 @@ f! {
10711071
.offset(CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize)
10721072
}
10731073

1074-
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
1074+
pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
10751075
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::<cmsghdr>()))
10761076
as ::c_uint
10771077
}

0 commit comments

Comments
 (0)