about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-08-21formatGeoffry Song-9/+2
2024-08-21Clean up cfg-gating of ProcessPrng externGeoffry Song-13/+16
2024-08-21Rollup merge of #129232 - ivmarkov:master, r=workingjubileeMatthias Krüger-6/+24
Fix `thread::sleep` Duration-handling for ESP-IDF Addresses the ESP-IDF specific aspect of https://github.com/rust-lang/rust/issues/129212 #### A short summary of the problems addressed by this PR: ================================================ 1. **Problem 1** - the current implementation of `std::thread::sleep` does not properly round up the passed `Duration` As per the documentation of `std::thread::sleep`, the implementation should sleep _at least_ for the provided duration, but not less. Since the minimum supported resolution of the `usleep` syscall which is used with ESP-IDF is one microsecond, this means that we need to round-up any sub-microsecond nanos to one microsecond. Moreover, in the edge case where the user had passed a duration of < 1000 nanos (i.e. less than one microsecond), the current implementation will _not_ sleep _at all_. This is addressed by this PR. 2. **Problem 2** - the implementation of `usleep` on the ESP-IDF can overflow if the passed number of microseconds is >= `u32::MAX - 1_000_000` This is also addressed by this PR. Extra details for Problem 2: `u32::MAX - 1_000_000` is chosen to accommodate for the longest possible systick on the ESP IDF which is 1000ms. The systick duration is selected when compiling the ESP IDF FreeRTOS task scheduler itself, so we can't know it from within `STD`. The default systick duration is 10ms, and might be lowered down to 1ms. (Making it longer I have never seen, but in theory it can go up to a 1000ms max, even if obviously a one second systick is unrealistic - but we are paranoid in the PR.) While the overflow is reported upstream in the ESP IDF repo[^1], I still believe we should workaround it in the Rust wrappers as well, because it might take time until it is fixed, and they might not fix it for all released ESP IDF versions. For big durations, rather than calling `usleep` repeatedly on the ESP-IDF in chunks of `u32::MAX - 1_000_000`us, it might make sense to call instead with 1_000_000us (one second) as this is the max period that seems to be agreed upon as a safe max period in the `usleep` POSIX spec. On the other hand, that might introduce less precision (as we need to call more times `usleep` in a loop) and, we would be fighting a theoretical problem only, as I have big doubts the ESP IDF will stop supporting durations higher than 1_000_000us - ever - because of backwards compatibility with code which already calls `usleep` on the ESP IDF with bigger durations. [^1]: https://github.com/espressif/esp-idf/issues/14390
2024-08-20Avoid extra `cast()`s after `CStr::as_ptr()`Josh Stone-2/+2
These used to be `&str` literals that did need a pointer cast, but that became a no-op after switching to `c""` literals in #118566.
2024-08-18Rollup merge of #128902 - evanj:evan.jones/env-var-doc, r=workingjubileeTrevor Gross-6/+5
doc: std::env::var: Returns None for names with '=' or NUL byte The documentation incorrectly stated that std::env::var could return an error for variable names containing '=' or the NUL byte. Copy the correct documentation from var_os. var_os was fixed in Commit 8a7a665, Pull Request #109894, which closed Issue #109893. This documentation was incorrectly added in commit f2c0f292, which replaced a panic in var_os by returning None, but documented the change as "May error if ...". Reference the specific error values and link to them.
2024-08-18code review improvementsEvan Jones-9/+5
2024-08-18Fix for issue #129212 for the ESP-IDFivmarkov-6/+24
2024-08-17Auto merge of #126877 - GrigorenkoPV:clone_to_uninit, r=dtolnaybors-0/+100
CloneToUninit impls As per #126799. Also implements it for `Wtf8` and both versions of `os_str::Slice`. Maybe it is worth to slap `#[inline]` on some of those impls. r? `@dtolnay`
2024-08-16Stabilize std::thread::Builder::spawn_uncheckedDavid Tolnay-2/+1
2024-08-16Refer to other docsMaarten-23/+3
2024-08-15Add unordered list with possible values for each constMaarten-64/+125
2024-08-15proposal to expand (a subset of) linux specific socket capabilities.David Carlier-10/+8
to stabilise the quickack part for now, tcp_deferaccept had been added at a later stage.
2024-08-15Format std::env::consts docstringsMaarten-37/+37
This clarifies possible outputs the constants might be.
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-2/+9
2024-08-14CommandExt::before_exec: deprecate safety in edition 2024Ralf Jung-3/+11
2024-08-14Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgrbors-2/+14
Rollup of 7 pull requests Successful merges: - #122884 (Optimize integer `pow` by removing the exit branch) - #127857 (Allow to customize `// TODO:` comment for deprecated safe autofix) - #129034 (Add `#[must_use]` attribute to `Coroutine` trait) - #129049 (compiletest: Don't panic on unknown JSON-like output lines) - #129050 (Emit a warning instead of an error if `--generate-link-to-definition` is used with other output formats than HTML) - #129056 (Fix one usage of target triple in bootstrap) - #129058 (Add mw back to review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-14Rollup merge of #128873 - ChrisDenton:windows-targets, r=Mark-SimulacrumMatthias Krüger-41/+1
Add windows-targets crate to std's sysroot With this PR, when backtrace is used as a crate from crates.io it will (once updated) use the real [windows-targets](https://crates.io/crates/windows-targets) crate. But when used from std it'll use std's replacement version. This allows sharing our customized `windows_tagets::link!` macro between std proper and the backtrace crate when used as part of std, ensuring a consistent linking story. This will be especially important once we move to using [`raw-dylib`](https://doc.rust-lang.org/reference/items/external-blocks.html#dylib-versus-raw-dylib) by default.
2024-08-13Make `std::os::darwin` publicMads Marquart-15/+37
This includes `std::os::darwin::fs`, which is re-exported under `std::os::macos::fs` and `std::os::ios::fs`. `std::os::darwin::raw` is not exposed, which means that `MetadataExt::as_raw_stat` isn't available on tvOS, visionOS and watchOS.
2024-08-13Rollup merge of #127857 - tbu-:pr_deprecated_safe_todo, r=petrochenkovMatthias Krüger-2/+14
Allow to customize `// TODO:` comment for deprecated safe autofix Relevant for the deprecation of `CommandExt::before_exit` in #125970. Tracking: - #124866
2024-08-13Auto merge of #129046 - matthiaskrgr:rollup-9x4xgak, r=matthiaskrgrbors-181/+144
Rollup of 7 pull requests Successful merges: - #128643 (Refactor `powerpc64` call ABI handling) - #128655 (std: refactor UNIX random data generation) - #128745 (Remove unused lifetime parameter from spawn_unchecked) - #128841 (bootstrap: don't use rustflags for `--rustc-args`) - #128983 (Slightly refactor `TargetSelection` in bootstrap) - #129026 (CFI: Move CFI ui tests to cfi directory) - #129040 (Fix blessing of rmake tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-13Rollup merge of #128745 - dtolnay:spawnunchecked, r=workingjubileeMatthias Krüger-8/+7
Remove unused lifetime parameter from spawn_unchecked Amanieu caught this when reviewing the stabilization proposal in https://github.com/rust-lang/rust/issues/55132. The `'a` lifetime here is useless. The signature is asking the caller of `spawn_unchecked` to "give me any lifetime that is shorter than your F's and T's lifetime", which they can always to with no effect, because arbitrarily short lifetimes exist.
2024-08-13Rollup merge of #128655 - joboet:play_with_the_dice, r=ChrisDentonMatthias Krüger-173/+137
std: refactor UNIX random data generation This PR makes a number of changes to the UNIX randomness implementation: * Use `io::Error` for centralized error handling * Move the file-fallback logic out of the `getrandom`-specific module * Stop redefining the syscalls on macOS and DragonFly, they have appeared in `libc` * Add a `OnceLock` to cache the random device file descriptor
2024-08-13`#[deprecated_safe_2024]`: Also use the `// TODO:` hint in the compiler errorTobias Bucher-2/+2
This doesn't work for translated compiler error messages.
2024-08-13Allow to customize `// TODO:` comment for deprecated safe autofixTobias Bucher-2/+14
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
2024-08-12trying common codepath for every unixesDavid Carlier-29/+0
2024-08-12std::fs: get_mode implementation for haiku.David Carlier-0/+2
2024-08-12Rollup merge of #128632 - joboet:dont_overwrite_style, r=AmanieuGuillaume Gomez-11/+15
std: do not overwrite style in `get_backtrace_style` If another thread calls `set_backtrace_style` while a `get_backtrace_style` is reading the environment variables, `get_backtrace_style` will overwrite the value. Use an atomic CAS to avoid this.
2024-08-12std: use `/scheme/rand` on Redoxjoboet-1/+1
2024-08-12std: do not overwrite style in `get_backtrace_style`joboet-11/+15
If another thread calls `set_backtrace_style` while a `get_backtrace_style` is reading the environment variables, `get_backtrace_style` will overwrite the value. Use an atomic CAS to avoid this.
2024-08-10Update std and compilerNadrieril-1/+1
2024-08-09doc: std::env::var: Returns None for names with '=' or NUL byteEvan Jones-5/+8
The documentation incorrectly stated that std::env::var could return an error for variable names containing '=' or the NUL byte. Copy the correct documentation from var_os. var_os was fixed in Commit 8a7a665, Pull Request #109894, which closed Issue #109893. This documentation was incorrectly added in commit f2c0f292, which replaced a panic in var_os by returning None, but documented the change as "May error if ...". Reference the specific error values and link to them.
2024-08-09Rollup merge of #128859 - MinxuanZ:mips-sig, r=AmanieuMatthias Krüger-0/+13
Fix the name of signal 19 in library/std/src/sys/pal/unix/process/process_unix/tests.rs for mips/sparc linux relate to #128816
2024-08-09Rollup merge of #128817 - biabbas:vxworks_update, r=tgross35Matthias Krüger-23/+13
VxWorks code refactored 1. Extern TaskNameSet as minimum supported version of os is VxWorks 7 which would have taskNameSet 2. Vx_TASK_NAME_LEN is 31 on VxWorks7, defined variable res. 3. Add unsafe blocks on Non::Zero usage in available_parallelism() 4. Update vxworks docs. r? `@tgross35` cc `@devnexen`
2024-08-09Add windows-targets crate to std's sysrootChris Denton-41/+1
2024-08-09VxWorks: Add safety comment for vxCpuEnabledGetB I Mohammed Abbas-1/+1
Co-authored-by: Trevor Gross <t.gross35@gmail.com>
2024-08-09delete spacemonstercatss-2/+2
2024-08-09fix formatmonstercatss-4/+6
2024-08-09[SPARC] fix the name of signal 19 in sparc archMin-1/+9
2024-08-09[MIPS] fix the name of signal 19 in mipsMin-0/+3
2024-08-09Rollup merge of #128818 - RalfJung:std-miri-floats, r=tgross35Matthias Krüger-5/+5
std float tests: special-case Miri in feature detection Quick work-around to fix miri-test-libstd failures. r? ``@tgross35``
2024-08-09Rollup merge of #128640 - RalfJung:rwlock-macos-miri, r=joboetMatthias Krüger-0/+4
rwlock: disable 'frob' test in Miri on macOS Due to https://github.com/rust-lang/rust/issues/121950, Miri will sometimes complain about this test on macOS. Better disable the test, as otherwise it can fail for unrelated PRs. r? ``@joboet``
2024-08-08std float tests: special-case Miri in feature detectionRalf Jung-5/+5
also fix some cfg logic
2024-08-08Vxworks: Extern taskNameSet and fix build errorsB I Mohammed Abbas-20/+8
2024-08-08rwlock: disable 'frob' test in Miri on macOSRalf Jung-0/+4
2024-08-08Fix VxWorks available parallelism: Move nonzero::uncheked into unsafe blockB I Mohammed Abbas-3/+5
2024-08-07Add tracking issue to core-pattern-typeltdk-1/+1
2024-08-06Rollup merge of #128766 - Monadic-Cat:patch-1, r=tgross35Trevor Gross-1/+1
Trivial grammar fix in const keyword docs This PR makes a trivial fix to the wording of a sentence in the `const` keyword docs. > `const` items looks remarkably similar to `static` items, [...] Either this should be written as > A `const` items looks remarkably similar to a `static` item, [...] or "looks" should be changed to "look". I have selected the smaller diff.
2024-08-06Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnayTrevor Gross-94/+3469
Add `f16` and `f128` math functions This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-06Trivial grammar fix in const keyword docsMonadic Cat-1/+1
> `const` items looks remarkably similar to `static` items, [...] Either this should be written as > A `const` items looks remarkably similar to a `static` item, or "looks" should be changed to "look". I have selected the smaller diff.
2024-08-07Rollup merge of #128751 - devnexen:vxworks_set_thread_name, r=tgross35Matthias Krüger-3/+30
std::thread: set_name implementation proposal for vxWorks.