Skip to content

Commit 19cfc46

Browse files
authored
Merge pull request RustPython#2516 from RustPython/freebsd
Fix compilation on freebsd
2 parents c63a429 + 6da8b93 commit 19cfc46

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/src/stdlib/errno.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ const ERROR_CODES: &[(&str, i32)] = &[
8888
e!(ENODEV),
8989
e!(EHOSTUNREACH),
9090
e!(cfg(not(windows)), ENOMSG),
91-
e!(cfg(not(any(target_os = "openbsd", windows))), ENODATA),
91+
e!(
92+
cfg(not(any(
93+
target_os = "openbsd",
94+
target_os = "freebsd",
95+
windows
96+
))),
97+
ENODATA
98+
),
9299
e!(cfg(not(windows)), ENOTBLK),
93100
e!(ENOSYS),
94101
e!(EPIPE),
@@ -142,7 +149,14 @@ const ERROR_CODES: &[(&str, i32)] = &[
142149
e!(ENOENT),
143150
e!(EEXIST),
144151
e!(EDQUOT),
145-
e!(cfg(not(any(target_os = "openbsd", windows))), ENOSTR),
152+
e!(
153+
cfg(not(any(
154+
target_os = "openbsd",
155+
target_os = "freebsd",
156+
windows
157+
))),
158+
ENOSTR
159+
),
146160
e!(EFAULT),
147161
e!(EFBIG),
148162
e!(ENOTCONN),
@@ -151,7 +165,14 @@ const ERROR_CODES: &[(&str, i32)] = &[
151165
e!(ECONNABORTED),
152166
e!(ENETUNREACH),
153167
e!(ESTALE),
154-
e!(cfg(not(any(target_os = "openbsd", windows))), ENOSR),
168+
e!(
169+
cfg(not(any(
170+
target_os = "openbsd",
171+
target_os = "freebsd",
172+
windows
173+
))),
174+
ENOSR
175+
),
155176
e!(ENOMEM),
156177
e!(ENOTSOCK),
157178
e!(EMLINK),
@@ -162,7 +183,14 @@ const ERROR_CODES: &[(&str, i32)] = &[
162183
e!(ENAMETOOLONG),
163184
e!(ENOTTY),
164185
e!(ESOCKTNOSUPPORT),
165-
e!(cfg(not(any(target_os = "openbsd", windows))), ETIME),
186+
e!(
187+
cfg(not(any(
188+
target_os = "openbsd",
189+
target_os = "freebsd",
190+
windows
191+
))),
192+
ETIME
193+
),
166194
e!(ETOOMANYREFS),
167195
e!(EMFILE),
168196
e!(cfg(not(windows)), ETXTBSY),

vm/src/stdlib/os.rs

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ mod _os {
791791
{
792792
#[cfg(target_os = "android")]
793793
use std::os::android::fs::MetadataExt;
794+
#[cfg(target_os = "freebsd")]
795+
use std::os::freebsd::fs::MetadataExt;
794796
#[cfg(target_os = "linux")]
795797
use std::os::linux::fs::MetadataExt;
796798
#[cfg(target_os = "macos")]
@@ -1375,11 +1377,14 @@ mod posix {
13751377
pub(super) use std::os::unix::fs::OpenOptionsExt;
13761378
use std::os::unix::io::RawFd;
13771379

1380+
#[cfg(not(any(target_os = "redox", target_os = "freebsd")))]
1381+
#[pyattr]
1382+
use libc::O_DSYNC;
13781383
#[pyattr]
13791384
use libc::{O_CLOEXEC, O_NONBLOCK, WNOHANG};
13801385
#[cfg(not(target_os = "redox"))]
13811386
#[pyattr]
1382-
use libc::{O_DSYNC, O_NDELAY, O_NOCTTY};
1387+
use libc::{O_NDELAY, O_NOCTTY};
13831388

13841389
#[pyattr]
13851390
const EX_OK: i8 = exitcode::OK as i8;
@@ -1506,7 +1511,7 @@ mod posix {
15061511
}
15071512
}
15081513

1509-
#[cfg(target_os = "macos")]
1514+
#[cfg(any(target_os = "macos", target_os = "ios"))]
15101515
fn getgroups() -> nix::Result<Vec<Gid>> {
15111516
use libc::{c_int, gid_t};
15121517
use std::ptr;
@@ -1525,7 +1530,7 @@ mod posix {
15251530
})
15261531
}
15271532

1528-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
1533+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "redox")))]
15291534
use nix::unistd::getgroups;
15301535

15311536
#[cfg(target_os = "redox")]
@@ -2007,26 +2012,9 @@ mod posix {
20072012
}
20082013
}
20092014

2010-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
2011-
type ModeT = u32;
2012-
2013-
#[cfg(target_os = "redox")]
2014-
type ModeT = i32;
2015-
2016-
#[cfg(target_os = "macos")]
2017-
type ModeT = u16;
2018-
2019-
#[cfg(any(
2020-
target_os = "macos",
2021-
target_os = "linux",
2022-
target_os = "openbsd",
2023-
target_os = "redox",
2024-
target_os = "android",
2025-
))]
20262015
#[pyfunction]
2027-
fn umask(mask: ModeT, _vm: &VirtualMachine) -> PyResult<ModeT> {
2028-
let ret_mask = unsafe { libc::umask(mask) };
2029-
Ok(ret_mask)
2016+
fn umask(mask: libc::mode_t) -> libc::mode_t {
2017+
unsafe { libc::umask(mask) }
20302018
}
20312019

20322020
#[pyattr]
@@ -2069,12 +2057,7 @@ mod posix {
20692057
}
20702058

20712059
// cfg from nix
2072-
#[cfg(any(
2073-
target_os = "android",
2074-
target_os = "freebsd",
2075-
target_os = "linux",
2076-
target_os = "openbsd"
2077-
))]
2060+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "openbsd"))]
20782061
#[pyfunction]
20792062
fn getresuid(vm: &VirtualMachine) -> PyResult<(u32, u32, u32)> {
20802063
let mut ruid = 0;
@@ -2089,12 +2072,7 @@ mod posix {
20892072
}
20902073

20912074
// cfg from nix
2092-
#[cfg(any(
2093-
target_os = "android",
2094-
target_os = "freebsd",
2095-
target_os = "linux",
2096-
target_os = "openbsd"
2097-
))]
2075+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "openbsd"))]
20982076
#[pyfunction]
20992077
fn getresgid(vm: &VirtualMachine) -> PyResult<(u32, u32, u32)> {
21002078
let mut rgid = 0;
@@ -2126,12 +2104,7 @@ mod posix {
21262104
}
21272105

21282106
// cfg from nix
2129-
#[cfg(any(
2130-
target_os = "android",
2131-
target_os = "freebsd",
2132-
target_os = "linux",
2133-
target_os = "openbsd"
2134-
))]
2107+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "openbsd"))]
21352108
#[pyfunction]
21362109
fn setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<()> {
21372110
let ret = unsafe { libc::setregid(rgid, egid) };
@@ -2157,12 +2130,7 @@ mod posix {
21572130
}
21582131

21592132
// cfg from nix
2160-
#[cfg(any(
2161-
target_os = "android",
2162-
target_os = "freebsd",
2163-
target_os = "linux",
2164-
target_os = "openbsd"
2165-
))]
2133+
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))]
21662134
#[pyfunction]
21672135
fn setgroups(group_ids: PyIterable<u32>, vm: &VirtualMachine) -> PyResult<()> {
21682136
let gids = group_ids
@@ -2540,10 +2508,21 @@ mod posix {
25402508
type PriorityWhichType = libc::c_int;
25412509
}
25422510
}
2511+
cfg_if::cfg_if! {
2512+
if #[cfg(target_os = "freebsd")] {
2513+
type PriorityWhoType = i32;
2514+
} else {
2515+
type PriorityWhoType = u32;
2516+
}
2517+
}
25432518

25442519
#[cfg(not(target_os = "windows"))]
25452520
#[pyfunction]
2546-
fn getpriority(which: PriorityWhichType, who: u32, vm: &VirtualMachine) -> PyResult {
2521+
fn getpriority(
2522+
which: PriorityWhichType,
2523+
who: PriorityWhoType,
2524+
vm: &VirtualMachine,
2525+
) -> PyResult {
25472526
Errno::clear();
25482527
let retval = unsafe { libc::getpriority(which, who) };
25492528
if errno() != 0 {
@@ -2557,7 +2536,7 @@ mod posix {
25572536
#[pyfunction]
25582537
fn setpriority(
25592538
which: PriorityWhichType,
2560-
who: u32,
2539+
who: PriorityWhoType,
25612540
priority: i32,
25622541
vm: &VirtualMachine,
25632542
) -> PyResult<()> {

vm/src/stdlib/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
219219
"SIGSYS" => ctx.new_int(libc::SIGSYS as u8),
220220
});
221221

222-
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
222+
#[cfg(not(any(target_os = "macos", target_os = "openbsd", target_os = "freebsd")))]
223223
{
224224
extend_module!(vm, module, {
225225
"SIGPWR" => ctx.new_int(libc::SIGPWR as u8),

vm/src/stdlib/socket.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,15 +1126,19 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
11261126
"SO_OOBINLINE" => ctx.new_int(c::SO_OOBINLINE),
11271127
"SO_ERROR" => ctx.new_int(c::SO_ERROR),
11281128
"TCP_NODELAY" => ctx.new_int(c::TCP_NODELAY),
1129+
"NI_NAMEREQD" => ctx.new_int(c::NI_NAMEREQD),
1130+
"NI_NOFQDN" => ctx.new_int(c::NI_NOFQDN),
1131+
"NI_NUMERICHOST" => ctx.new_int(c::NI_NUMERICHOST),
1132+
"NI_NUMERICSERV" => ctx.new_int(c::NI_NUMERICSERV),
1133+
});
1134+
1135+
#[cfg(not(target_os = "freebsd"))]
1136+
extend_module!(vm, module, {
11291137
"AI_PASSIVE" => ctx.new_int(c::AI_PASSIVE),
11301138
"AI_NUMERICHOST" => ctx.new_int(c::AI_NUMERICHOST),
11311139
"AI_ALL" => ctx.new_int(c::AI_ALL),
11321140
"AI_ADDRCONFIG" => ctx.new_int(c::AI_ADDRCONFIG),
11331141
"AI_NUMERICSERV" => ctx.new_int(c::AI_NUMERICSERV),
1134-
"NI_NAMEREQD" => ctx.new_int(c::NI_NAMEREQD),
1135-
"NI_NOFQDN" => ctx.new_int(c::NI_NOFQDN),
1136-
"NI_NUMERICHOST" => ctx.new_int(c::NI_NUMERICHOST),
1137-
"NI_NUMERICSERV" => ctx.new_int(c::NI_NUMERICSERV),
11381142
});
11391143

11401144
#[cfg(not(windows))]

0 commit comments

Comments
 (0)