Skip to content

Commit 999e5e1

Browse files
authored
Merge pull request #1891 from xonatius/1870_more_platforms
Use safe_f! consistently across platforms
2 parents c2a184b + 773f556 commit 999e5e1

File tree

14 files changed

+211
-183
lines changed

14 files changed

+211
-183
lines changed

src/fuchsia/mod.rs

+40-39
Original file line numberDiff line numberDiff line change
@@ -3158,42 +3158,6 @@ f! {
31583158
}
31593159
}
31603160

3161-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
3162-
(status & 0xff) == 0x7f
3163-
}
3164-
3165-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
3166-
(status >> 8) & 0xff
3167-
}
3168-
3169-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
3170-
status == 0xffff
3171-
}
3172-
3173-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
3174-
((status & 0x7f) + 1) as i8 >= 2
3175-
}
3176-
3177-
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
3178-
status & 0x7f
3179-
}
3180-
3181-
pub fn WIFEXITED(status: ::c_int) -> bool {
3182-
(status & 0x7f) == 0
3183-
}
3184-
3185-
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
3186-
(status >> 8) & 0xff
3187-
}
3188-
3189-
pub fn WCOREDUMP(status: ::c_int) -> bool {
3190-
(status & 0x80) != 0
3191-
}
3192-
3193-
pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int {
3194-
(cmd << 8) | (type_ & 0x00ff)
3195-
}
3196-
31973161
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
31983162
for slot in cpuset.bits.iter_mut() {
31993163
*slot = 0;
@@ -3291,6 +3255,44 @@ f! {
32913255
}
32923256
}
32933257

3258+
safe_f! {
3259+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
3260+
(status & 0xff) == 0x7f
3261+
}
3262+
3263+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
3264+
(status >> 8) & 0xff
3265+
}
3266+
3267+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
3268+
status == 0xffff
3269+
}
3270+
3271+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
3272+
((status & 0x7f) + 1) as i8 >= 2
3273+
}
3274+
3275+
pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
3276+
status & 0x7f
3277+
}
3278+
3279+
pub {const} fn WIFEXITED(status: ::c_int) -> bool {
3280+
(status & 0x7f) == 0
3281+
}
3282+
3283+
pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
3284+
(status >> 8) & 0xff
3285+
}
3286+
3287+
pub {const} fn WCOREDUMP(status: ::c_int) -> bool {
3288+
(status & 0x80) != 0
3289+
}
3290+
3291+
pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int {
3292+
(cmd << 8) | (type_ & 0x00ff)
3293+
}
3294+
}
3295+
32943296
fn __CMSG_LEN(cmsg: *const cmsghdr) -> ::ssize_t {
32953297
((unsafe { (*cmsg).cmsg_len as ::size_t } + ::mem::size_of::<::c_long>()
32963298
- 1)
@@ -3302,9 +3304,8 @@ fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar {
33023304
}
33033305

33043306
fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
3305-
unsafe {
3306-
(*mhdr).msg_control.offset((*mhdr).msg_controllen as isize)
3307-
}.cast()
3307+
unsafe { (*mhdr).msg_control.offset((*mhdr).msg_controllen as isize) }
3308+
.cast()
33083309
}
33093310

33103311
// EXTERN_FN

src/unix/bsd/apple/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3241,24 +3241,26 @@ f! {
32413241
(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) + length as usize)
32423242
as ::c_uint
32433243
}
3244+
}
32443245

3245-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
3246+
safe_f! {
3247+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
32463248
status >> 8
32473249
}
32483250

3249-
pub fn _WSTATUS(status: ::c_int) -> ::c_int {
3251+
pub {const} fn _WSTATUS(status: ::c_int) -> ::c_int {
32503252
status & 0x7f
32513253
}
32523254

3253-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
3255+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
32543256
_WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) == 0x13
32553257
}
32563258

3257-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
3259+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
32583260
_WSTATUS(status) != _WSTOPPED && _WSTATUS(status) != 0
32593261
}
32603262

3261-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
3263+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
32623264
_WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13
32633265
}
32643266
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,10 @@ f! {
10371037
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
10381038
_CMSG_ALIGN(length as usize)) as ::c_uint
10391039
}
1040+
}
10401041

1041-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
1042+
safe_f! {
1043+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
10421044
(status & 0o177) != 0o177 && (status & 0o177) != 0
10431045
}
10441046
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1195,15 +1195,17 @@ f! {
11951195
::mem::size_of::<sockcred>() + ::mem::size_of::<::gid_t>() * ngrps
11961196
}
11971197

1198-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
1199-
(status & 0o177) != 0o177 && (status & 0o177) != 0 && status != 0x13
1200-
}
1201-
12021198
pub fn uname(buf: *mut ::utsname) -> ::c_int {
12031199
__xuname(256, buf as *mut ::c_void)
12041200
}
12051201
}
12061202

1203+
safe_f! {
1204+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
1205+
(status & 0o177) != 0o177 && (status & 0o177) != 0 && status != 0x13
1206+
}
1207+
}
1208+
12071209
extern "C" {
12081210
pub fn __error() -> *mut ::c_int;
12091211

src/unix/bsd/freebsdlike/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1220,16 +1220,16 @@ pub const TIME_ERROR: ::c_int = 5;
12201220
pub const REG_ENOSYS: ::c_int = -1;
12211221
pub const REG_ILLSEQ: ::c_int = 17;
12221222

1223-
f! {
1224-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
1223+
safe_f! {
1224+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
12251225
status == 0x13
12261226
}
12271227

1228-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
1228+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
12291229
status >> 8
12301230
}
12311231

1232-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
1232+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
12331233
(status & 0o177) == 0o177
12341234
}
12351235
}

src/unix/bsd/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -544,24 +544,26 @@ f! {
544544
*slot = 0;
545545
}
546546
}
547+
}
547548

548-
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
549+
safe_f! {
550+
pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
549551
status & 0o177
550552
}
551553

552-
pub fn WIFEXITED(status: ::c_int) -> bool {
554+
pub {const} fn WIFEXITED(status: ::c_int) -> bool {
553555
(status & 0o177) == 0
554556
}
555557

556-
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
558+
pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
557559
status >> 8
558560
}
559561

560-
pub fn WCOREDUMP(status: ::c_int) -> bool {
562+
pub {const} fn WCOREDUMP(status: ::c_int) -> bool {
561563
(status & 0o200) != 0
562564
}
563565

564-
pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int {
566+
pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int {
565567
(cmd << 8) | (type_ & 0x00ff)
566568
}
567569
}

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

+18-16
Original file line numberDiff line numberDiff line change
@@ -1699,29 +1699,13 @@ f! {
16991699
as ::c_uint
17001700
}
17011701

1702-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
1703-
status >> 8
1704-
}
1705-
1706-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
1707-
(status & 0o177) != 0o177 && (status & 0o177) != 0
1708-
}
1709-
1710-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
1711-
(status & 0o177) == 0o177
1712-
}
1713-
17141702
// dirfd() is a macro on netbsd to access
17151703
// the first field of the struct where dirp points to:
17161704
// http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36
17171705
pub fn dirfd(dirp: *mut ::DIR) -> ::c_int {
17181706
*(dirp as *const ::c_int)
17191707
}
17201708

1721-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
1722-
status == 0xffff
1723-
}
1724-
17251709
pub fn SOCKCREDSIZE(ngrps: usize) -> usize {
17261710
let ngrps = if ngrps > 0 {
17271711
ngrps - 1
@@ -1732,6 +1716,24 @@ f! {
17321716
}
17331717
}
17341718

1719+
safe_f! {
1720+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
1721+
status >> 8
1722+
}
1723+
1724+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
1725+
(status & 0o177) != 0o177 && (status & 0o177) != 0
1726+
}
1727+
1728+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
1729+
(status & 0o177) == 0o177
1730+
}
1731+
1732+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
1733+
status == 0xffff
1734+
}
1735+
}
1736+
17351737
extern "C" {
17361738
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
17371739
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ fn _ALIGN(p: usize) -> usize {
13401340
}
13411341

13421342
f! {
1343-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
1343+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
13441344
status & 0o177777 == 0o177777
13451345
}
13461346

@@ -1375,16 +1375,18 @@ f! {
13751375
(_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize))
13761376
as ::c_uint
13771377
}
1378+
}
13781379

1379-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
1380+
safe_f! {
1381+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
13801382
status >> 8
13811383
}
13821384

1383-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
1385+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
13841386
(status & 0o177) != 0o177 && (status & 0o177) != 0
13851387
}
13861388

1387-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
1389+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
13881390
(status & 0xff) == 0o177
13891391
}
13901392
}

src/unix/haiku/mod.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1254,37 +1254,39 @@ f! {
12541254
*slot = 0;
12551255
}
12561256
}
1257+
}
12571258

1258-
pub fn WIFEXITED(status: ::c_int) -> bool {
1259+
safe_f! {
1260+
pub {const} fn WIFEXITED(status: ::c_int) -> bool {
12591261
(status & !0xff) == 0
12601262
}
12611263

1262-
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
1264+
pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
12631265
status & 0xff
12641266
}
12651267

1266-
pub fn WIFSIGNALED(status: ::c_int) -> bool {
1268+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
12671269
((status >> 8) & 0xff) != 0
12681270
}
12691271

1270-
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
1272+
pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
12711273
(status >> 8) & 0xff
12721274
}
12731275

1274-
pub fn WIFSTOPPED(status: ::c_int) -> bool {
1276+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
12751277
((status >> 16) & 0xff) != 0
12761278
}
12771279

1278-
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
1280+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
12791281
(status >> 16) & 0xff
12801282
}
12811283

12821284
// actually WIFCORED, but this is used everywhere else
1283-
pub fn WCOREDUMP(status: ::c_int) -> bool {
1285+
pub {const} fn WCOREDUMP(status: ::c_int) -> bool {
12841286
(status & 0x10000) != 0
12851287
}
12861288

1287-
pub fn WIFCONTINUED(status: ::c_int) -> bool {
1289+
pub {const} fn WIFCONTINUED(status: ::c_int) -> bool {
12881290
(status & 0x20000) != 0
12891291
}
12901292
}
@@ -1293,7 +1295,11 @@ extern "C" {
12931295
pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
12941296
pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
12951297
pub fn getpriority(which: ::c_int, who: id_t) -> ::c_int;
1296-
pub fn setpriority(which: ::c_int, who: id_t, priority: ::c_int) -> ::c_int;
1298+
pub fn setpriority(
1299+
which: ::c_int,
1300+
who: id_t,
1301+
priority: ::c_int,
1302+
) -> ::c_int;
12971303

12981304
pub fn utimensat(
12991305
fd: ::c_int,

src/unix/hermit/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -943,16 +943,16 @@ pub const PRIO_PROCESS: ::c_int = 0;
943943
pub const PRIO_PGRP: ::c_int = 1;
944944
pub const PRIO_USER: ::c_int = 2;
945945

946-
f! {
947-
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
946+
safe_f! {
947+
pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
948948
(status >> 8) & 0xff
949949
}
950950

951-
pub fn WIFEXITED(status: ::c_int) -> bool {
951+
pub {const} fn WIFEXITED(status: ::c_int) -> bool {
952952
(status & 0xff) == 0
953953
}
954954

955-
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
955+
pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
956956
status & 0x7f
957957
}
958958
}

0 commit comments

Comments
 (0)