Skip to content

Commit 1fef152

Browse files
committed
Auto merge of #124879 - workingjubilee:rollup-1k77hyz, r=workingjubilee
Rollup of 4 pull requests Successful merges: - #124470 (std::net: Socket::new_raw now set to SO_NOSIGPIPE on freebsd.) - #124782 (add note about `AlreadyExists` to `create_new`) - #124788 (Convert instances of `target_os = "macos"` to `target_vendor = "apple"`) - #124838 (next_power_of_two: add a doctest to show what happens on 0) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7aa17df + ceb5ec3 commit 1fef152

File tree

8 files changed

+50
-22
lines changed

8 files changed

+50
-22
lines changed

library/core/src/num/uint_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,7 @@ macro_rules! uint_impl {
27642764
/// ```
27652765
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".next_power_of_two(), 2);")]
27662766
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".next_power_of_two(), 4);")]
2767+
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".next_power_of_two(), 1);")]
27672768
/// ```
27682769
#[stable(feature = "rust1", since = "1.0.0")]
27692770
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]

library/std/src/fs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ impl File {
408408
///
409409
/// This function will create a file if it does not exist, or return an error if it does. This
410410
/// way, if the call succeeds, the file returned is guaranteed to be new.
411+
/// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
412+
/// or another error based on the situation. See [`OpenOptions::open`] for a
413+
/// non-exhaustive list of likely errors.
411414
///
412415
/// This option is useful because it is atomic. Otherwise between checking whether a file
413416
/// exists and creating a new one, the file may have been created by another process (a TOCTOU
@@ -416,6 +419,8 @@ impl File {
416419
/// This can also be written using
417420
/// `File::options().read(true).write(true).create_new(true).open(...)`.
418421
///
422+
/// [`AlreadyExists`]: crate::io::ErrorKind::AlreadyExists
423+
///
419424
/// # Examples
420425
///
421426
/// ```no_run
@@ -1071,6 +1076,9 @@ impl OpenOptions {
10711076
///
10721077
/// No file is allowed to exist at the target location, also no (dangling) symlink. In this
10731078
/// way, if the call succeeds, the file returned is guaranteed to be new.
1079+
/// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
1080+
/// or another error based on the situation. See [`OpenOptions::open`] for a
1081+
/// non-exhaustive list of likely errors.
10741082
///
10751083
/// This option is useful because it is atomic. Otherwise between checking
10761084
/// whether a file exists and creating a new one, the file may have been
@@ -1084,6 +1092,7 @@ impl OpenOptions {
10841092
///
10851093
/// [`.create()`]: OpenOptions::create
10861094
/// [`.truncate()`]: OpenOptions::truncate
1095+
/// [`AlreadyExists`]: io::ErrorKind::AlreadyExists
10871096
///
10881097
/// # Examples
10891098
///

library/std/src/os/unix/net/listener.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,25 @@ impl UnixListener {
8181
))]
8282
const backlog: core::ffi::c_int = 128;
8383
#[cfg(any(
84+
// Silently capped to `/proc/sys/net/core/somaxconn`.
8485
target_os = "linux",
86+
// Silently capped to `kern.ipc.soacceptqueue`.
8587
target_os = "freebsd",
88+
// Silently capped to `kern.somaxconn sysctl`.
8689
target_os = "openbsd",
87-
target_os = "macos"
90+
// Silently capped to the default 128.
91+
target_vendor = "apple",
8892
))]
8993
const backlog: core::ffi::c_int = -1;
9094
#[cfg(not(any(
9195
target_os = "windows",
9296
target_os = "redox",
97+
target_os = "espidf",
98+
target_os = "horizon",
9399
target_os = "linux",
94100
target_os = "freebsd",
95101
target_os = "openbsd",
96-
target_os = "macos",
97-
target_os = "espidf",
98-
target_os = "horizon"
102+
target_vendor = "apple",
99103
)))]
100104
const backlog: libc::c_int = libc::SOMAXCONN;
101105

library/std/src/sys/pal/unix/alloc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ unsafe impl GlobalAlloc for System {
1313
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
1414
libc::malloc(layout.size()) as *mut u8
1515
} else {
16-
#[cfg(target_os = "macos")]
16+
// `posix_memalign` returns a non-aligned value if supplied a very
17+
// large alignment on older versions of Apple's platforms (unknown
18+
// exactly which version range, but the issue is definitely
19+
// present in macOS 10.14 and iOS 13.3).
20+
//
21+
// <https://github.com/rust-lang/rust/issues/30170>
22+
#[cfg(target_vendor = "apple")]
1723
{
1824
if layout.align() > (1 << 31) {
1925
return ptr::null_mut();

library/std/src/sys/pal/unix/fd.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ pub struct FileDesc(OwnedFd);
3333
// with the man page quoting that if the count of bytes to read is
3434
// greater than `SSIZE_MAX` the result is "unspecified".
3535
//
36-
// On macOS, however, apparently the 64-bit libc is either buggy or
36+
// On Apple targets however, apparently the 64-bit libc is either buggy or
3737
// intentionally showing odd behavior by rejecting any read with a size
3838
// larger than or equal to INT_MAX. To handle both of these the read
3939
// size is capped on both platforms.
40-
#[cfg(target_os = "macos")]
41-
const READ_LIMIT: usize = libc::c_int::MAX as usize - 1;
42-
#[cfg(not(target_os = "macos"))]
43-
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
40+
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
41+
libc::c_int::MAX as usize - 1
42+
} else {
43+
libc::ssize_t::MAX as usize
44+
};
4445

4546
#[cfg(any(
4647
target_os = "dragonfly",

library/std/src/sys/pal/unix/fs.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1493,11 +1493,11 @@ impl fmt::Debug for File {
14931493
readlink(&p).ok()
14941494
}
14951495

1496-
#[cfg(target_os = "macos")]
1496+
#[cfg(target_vendor = "apple")]
14971497
fn get_path(fd: c_int) -> Option<PathBuf> {
14981498
// FIXME: The use of PATH_MAX is generally not encouraged, but it
1499-
// is inevitable in this case because macOS defines `fcntl` with
1500-
// `F_GETPATH` in terms of `MAXPATHLEN`, and there are no
1499+
// is inevitable in this case because Apple targets define `fcntl`
1500+
// with `F_GETPATH` in terms of `MAXPATHLEN`, and there are no
15011501
// alternatives. If a better method is invented, it should be used
15021502
// instead.
15031503
let mut buf = vec![0; libc::PATH_MAX as usize];
@@ -1538,12 +1538,12 @@ impl fmt::Debug for File {
15381538

15391539
#[cfg(not(any(
15401540
target_os = "linux",
1541-
target_os = "macos",
15421541
target_os = "vxworks",
15431542
all(target_os = "freebsd", target_arch = "x86_64"),
15441543
target_os = "netbsd",
15451544
target_os = "illumos",
1546-
target_os = "solaris"
1545+
target_os = "solaris",
1546+
target_vendor = "apple",
15471547
)))]
15481548
fn get_path(_fd: c_int) -> Option<PathBuf> {
15491549
// FIXME(#24570): implement this for other Unix platforms
@@ -1552,12 +1552,12 @@ impl fmt::Debug for File {
15521552

15531553
#[cfg(any(
15541554
target_os = "linux",
1555-
target_os = "macos",
15561555
target_os = "freebsd",
15571556
target_os = "hurd",
15581557
target_os = "netbsd",
15591558
target_os = "openbsd",
1560-
target_os = "vxworks"
1559+
target_os = "vxworks",
1560+
target_vendor = "apple",
15611561
))]
15621562
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
15631563
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
@@ -1574,12 +1574,12 @@ impl fmt::Debug for File {
15741574

15751575
#[cfg(not(any(
15761576
target_os = "linux",
1577-
target_os = "macos",
15781577
target_os = "freebsd",
15791578
target_os = "hurd",
15801579
target_os = "netbsd",
15811580
target_os = "openbsd",
1582-
target_os = "vxworks"
1581+
target_os = "vxworks",
1582+
target_vendor = "apple",
15831583
)))]
15841584
fn get_mode(_fd: c_int) -> Option<(bool, bool)> {
15851585
// FIXME(#24570): implement this for other Unix platforms

library/std/src/sys/pal/unix/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
6363
args::init(argc, argv);
6464

6565
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread
66-
// already exists, we have to call it ourselves. We only do this on macos
66+
// already exists, we have to call it ourselves. We only do this on Apple targets
6767
// because some unix-like operating systems such as Linux share process-id and
6868
// thread-id for the main thread and so renaming the main thread will rename the
6969
// process and we only want to enable this on platforms we've tested.
70-
if cfg!(target_os = "macos") {
70+
if cfg!(target_vendor = "apple") {
7171
thread::Thread::set_name(&c"main");
7272
}
7373

library/std/src/sys/pal/unix/net.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ impl Socket {
8686
// flag to atomically create the socket and set it as
8787
// CLOEXEC. On Linux this was added in 2.6.27.
8888
let fd = cvt(libc::socket(fam, ty | libc::SOCK_CLOEXEC, 0))?;
89-
Ok(Socket(FileDesc::from_raw_fd(fd)))
89+
let socket = Socket(FileDesc::from_raw_fd(fd));
90+
91+
// DragonFlyBSD, FreeBSD and NetBSD use `SO_NOSIGPIPE` as a `setsockopt`
92+
// flag to disable `SIGPIPE` emission on socket.
93+
#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "dragonfly"))]
94+
setsockopt(&socket, libc::SOL_SOCKET, libc::SO_NOSIGPIPE, 1)?;
95+
96+
Ok(socket)
9097
} else {
9198
let fd = cvt(libc::socket(fam, ty, 0))?;
9299
let fd = FileDesc::from_raw_fd(fd);

0 commit comments

Comments
 (0)