about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2022-12-28Rollup merge of #104493 - adamncasey:cgroupzeroperiod, r=m-ou-seMatthias Krüger-2/+2
available_parallelism: Gracefully handle zero value cfs_period_us There seem to be some scenarios where the cgroup cpu quota field `cpu.cfs_period_us` can contain `0`. This field is used to determine the "amount" of parallelism suggested by the function `std::thread::available_parallelism` A zero value of this field cause a panic when `available_parallelism()` is invoked. This issue was detected by the call from binaries built by `cargo test`. I really don't feel like `0` is a good value for `cpu.cfs_period_us`, but I also don't think applications should panic if this value is seen. This panic started happening with rust 1.64.0. This case is gracefully handled by other projects which read this information: [num_cpus](https://github.com/seanmonstar/num_cpus/blob/e437b9d9083d717692e35d917de8674a7987dd06/src/linux.rs#L207-L210), [ninja](https://github.com/ninja-build/ninja/pull/2174/files), [dotnet](https://github.com/dotnet/runtime/blob/c4341d45acca3ea662cd8d71e7d71094450dd045/src/coreclr/pal/src/misc/cgroup.cpp#L481-L483) Before this change, running `cargo test` in environments configured as described above would trigger this panic: ``` $ RUST_BACKTRACE=1 cargo test Finished test [unoptimized + debuginfo] target(s) in 3.55s Running unittests src/main.rs (target/debug/deps/x-9a42e145aca2934d) thread 'main' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:546:70 stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: std::sys::unix::thread::cgroups::quota 4: std::sys::unix::thread::available_parallelism 5: std::thread::available_parallelism 6: test::helpers::concurrency::get_concurrency 7: test::console::run_tests_console 8: test::test_main 9: test::test_main_static 10: x::main at ./src/main.rs:1:1 11: core::ops::function::FnOnce::call_once at /tmp/rust-1.64-1.64.0-1/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: test failed, to rerun pass '--bin x' ``` I've tested this change in an environment which has the bad (questionable?) setup and rebuilding the test executable against a fixed std library fixes the panic.
2022-12-28Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-seMatthias Krüger-4/+5
Move `ReentrantMutex` to `std::sync` If I understand #84187 correctly, `sys_common` should not contain platform-independent code, even if it is private.
2022-12-28Catch panics in destruction of TLS valuesFlorian Bartels-7/+14
`destroy_value` is/can be called from C code (libc). Unwinding from Rust to C code is undefined behavior, which is why unwinding is caught here.
2022-12-28Clarify catch_unwind docs about panic hooksAlbert Larsan-0/+3
Makes it clear from catch_unwind docs that the panic hook will be called before the panic is caught.
2022-12-28delete more `cfg(bootstrap)`Lukas Markeffsky-19/+6
2022-12-28Update bootstrap cfgPietro Albini-51/+4
2022-12-28adjust message on non-unwinding panicRalf Jung-1/+5
2022-12-28Rollup merge of #104708 - ↵fee1-dead-1/+1
jonasspinner:fix-backoff-doc-to-match-implementation, r=compiler-errors Fix backoff doc to match implementation The commit 8dddb2294310ad3e8ce0b2af735a702ad72a9a99 in the crossbeam-channel PR (#93563) changed the backoff strategy to be quadratic instead of exponential. This updates the doc to prevent confusion.
2022-12-28Auto merge of #100539 - joboet:horizon_timeout_clock, r=thomccbors-2/+4
Use correct clock in `park_timeout` on Horizon Horizon does not support using `CLOCK_MONOTONIC` with condition variables, so use the system time instead.
2022-12-27Auto merge of #106193 - compiler-errors:rollup-0l54wka, r=compiler-errorsbors-4/+7
Rollup of 9 pull requests Successful merges: - #103718 (More inference-friendly API for lazy) - #105765 (Detect likely `.` -> `..` typo in method calls) - #105852 (Suggest rewriting a malformed hex literal if we expect a float) - #105965 (Provide local extern function arg names) - #106064 (Partially fix `explicit_outlives_requirements` lint in macros) - #106179 (Fix a formatting error in Iterator::for_each docs) - #106181 (Fix doc comment parsing description in book) - #106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`) - #106189 (Fix UnsafeCell Documentation Spelling Error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-27Rollup merge of #103718 - matklad:infer-lazy, r=dtolnayMichael Goulet-4/+7
More inference-friendly API for lazy The signature for new was ``` fn new<F>(f: F) -> Lazy<T, F> ``` Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck. This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.
2022-12-27Auto merge of #97176 - kraktus:cmd_debug, r=the8472bors-8/+173
More verbose `Debug` implementation of `std::process:Command` Mainly based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200
2022-12-27More verbose `Debug` implementation of `std::process:Command`kraktus-8/+173
based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200 Add env variables and cwd to the shell-like debug output. Also use the alternate syntax to display a more verbose display, while not showing internal fields and hiding fields when they have their default value.
2022-12-23Stop at the first `NULL` argument when iterating `argv`Sebastian Dröge-6/+22
Some C commandline parsers (e.g. GLib and Qt) are replacing already handled arguments in `argv` with `NULL` and move them to the end. That means that `argc` might be bigger than the actual number of non-`NULL` pointers in `argv` at this point. To handle this we simply stop iterating at the first `NULL` argument. `argv` is also guaranteed to be `NULL`-terminated so any non-`NULL` arguments after the first `NULL` can safely be ignored. Fixes https://github.com/rust-lang/rust/issues/105999
2022-12-22std: only use LFS function on glibcmochaaP-12/+12
see #94173 and commit 27011b4185f5341e579d2a02cabd3dc7d7aa7149.
2022-12-20Stabilize path_as_mut_os_strAndres Suarez-4/+2
Closes #105021
2022-12-19Rollup merge of #105801 - zertosh:path_mut_os_str_doc_test, r=dtolnayMatthias Krüger-3/+3
Realistic `Path::as_mut_os_str` doctest With "Implement DerefMut for PathBuf" (#105018) now merged, it's possible to exercise `Path::as_mut_os_str` (#105002) without going through `into_boxed_path`.
2022-12-19Auto merge of #105698 - joboet:unsupported_threads_once, r=thomccbors-18/+103
Use a more efficient `Once` on platforms without threads The current implementation uses an atomic queue and spins rather than panicking when calling `call_once` recursively. Since concurrency is not supported on platforms like WASM, `Once` can be implemented much more efficiently using just a single non-atomic state variable.
2022-12-18Auto merge of #105638 - tavianator:fix-50619-again, r=Mark-Simulacrumbors-38/+47
fs: Fix #50619 (again) and add a regression test Bug #50619 was fixed by adding an end_of_stream flag in #50630. Unfortunately, that fix only applied to the readdir_r() path. When I switched Linux to use readdir() in #92778, I inadvertently reintroduced the bug on that platform. Other platforms that had always used readdir() were presumably never fixed. This patch enables end_of_stream for all platforms, and adds a Linux-specific regression test that should hopefully prevent the bug from being reintroduced again.
2022-12-17Rollup merge of #105458 - Ayush1325:blocking_spawn, r=Mark-SimulacrumMatthias Krüger-6/+77
Allow blocking `Command::output` ### Problem Currently, `Command::output` is internally implemented using `Command::spawn`. This is problematic because some targets (like UEFI) do not actually support multitasking and thus block while the program is executing. This coupling does not make much sense as `Command::output` is supposed to block until the execution is complete anyway and thus does not need to rely on a non-blocking `Child` or any other intermediate. ### Solution This PR moves the implementation of `Command::output` to `std::sys`. This means targets can choose to implement only `Command::output` without having to implement `Command::spawn`. ### Additional Information This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316. Currently, the only target I know about that will benefit from this change is UEFI. This PR can also be used to implement more efficient `Command::output` since the intermediate `Process` is not actually needed anymore, but that is outside the scope of this PR. Since this is not a public API change, I'm not sure if an RFC is needed or not.
2022-12-16Realistic `Path::as_mut_os_str` doctestAndres Suarez-3/+3
2022-12-16Auto merge of #105018 - zertosh:path_buf_deref_mut, r=dtolnaybors-0/+14
Implement DerefMut for PathBuf Without this, there's no way to get a `&mut Path` from `PathBuf` without going through `into_boxed_path`. This is relevant now that #105002 adds `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`.
2022-12-14Rollup merge of #105598 - RalfJung:more-comments, r=the8472Matthias Krüger-3/+4
explain mem::forget(env_lock) in fork/exec I stumbled upon this while doing triage for https://github.com/rust-lang/rust/issues/64718.
2022-12-14Rollup merge of #105399 - mikebenfield:lfs, r=thomccMatthias Krüger-8/+31
Use more LFS functions. On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts. This is relevant to #94173. With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe #94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
2022-12-14fs/tests: Fail fast on duplicate errors rather than looping indefinitelyTavian Barnes-2/+2
2022-12-14fs/tests: Explicitly kill the zombie rather than sleeping until it diesTavian Barnes-7/+9
2022-12-14std: use a more efficient `Once` on platforms without threadsjoboet-18/+103
2022-12-13Add #[inline] marker to OnceCell/LazyCell/OnceLock/LazyLockTrevor Gross-1/+21
2022-12-12fs: Fix #50619 (again) and add a regression testTavian Barnes-38/+45
Bug #50619 was fixed by adding an end_of_stream flag in #50630. Unfortunately, that fix only applied to the readdir_r() path. When I switched Linux to use readdir() in #92778, I inadvertently reintroduced the bug on that platform. Other platforms that had always used readdir() were presumably never fixed. This patch enables end_of_stream for all platforms, and adds a Linux-specific regression test that should hopefully prevent the bug from being reintroduced again.
2022-12-12explain mem::forget(env_lock) in fork/execRalf Jung-3/+4
2022-12-12kmc-solid: Synchronize with the read when sending a joining task ID to a joineeTomoaki Kawada-1/+8
2022-12-12kmc-solid: Synchronize the first update of `ThreadInner::lifecycle` with the ↵Tomoaki Kawada-8/+8
second one on detach The first update (swap RMW operation) must happen-before the second update so that the latter can release `ThreadInner` safely.
2022-12-11Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplettMatthias Krüger-1/+8
Better documentation for env::home_dir()'s broken behaviour This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684
2022-12-11Remove some `cfg(not(bootstrap))`Jules Bertholet-7/+3
2022-12-11Use rint instead of roundevenJules Bertholet-2/+2
Use rint intrinsic instead of roundeven to impement `round_ties_even`. They do the same thing when rounding mode is default, which Rust assumes. And `rint` has better platform support. Keeps `roundeven` around in `core::intrinsics`, it's doing no harm there.
2022-12-11Add tracking issueJules Bertholet-2/+2
2022-12-11Add `round_ties_even` to `f32` and `f64`Jules Bertholet-0/+97
2022-12-11Implement blocking outputAyush Singh-6/+61
This allows decoupling `Command::spawn` and `Command::output`. This is useful for targets which do support launching programs in blocking mode but do not support multitasking (Eg: UEFI). This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-11Rollup merge of #105460 - mkroening:compiler-builtins-0.1.85, r=Mark-SimulacrumMatthias Krüger-1/+1
Bump compiler-builtins to 0.1.85 This makes minimal floating point symbols available on `x86_64-unknown-none`. See https://github.com/rust-lang/compiler-builtins/issues/509 and https://github.com/rust-lang/compiler-builtins/pull/510.
2022-12-11Rollup merge of #103146 - joboet:cleanup_pthread_condvar, r=Mark-SimulacrumMatthias Krüger-66/+34
Cleanup timeouts in pthread condvar
2022-12-10Rollup merge of #105239 - gh2o:no-heap-alloc-on-thread-start, r=cuviperMatthias Krüger-12/+7
Avoid heap allocation when truncating thread names Ensure that heap allocation does not occur in a thread until `std::thread` is ready. This fixes issues with custom allocators that call `std::thread::current()`, since doing so prematurely initializes `THREAD_INFO` and causes the following `thread_info::set()` to fail.
2022-12-10Rollup merge of #104901 - krtab:filetype_compare, r=the8472Matthias Krüger-2/+34
Implement masking in FileType comparison on Unix Fixes: https://github.com/rust-lang/rust/issues/104900
2022-12-10Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-seMatthias Krüger-12/+119
Reimplement std's thread parker on top of events on SGX Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used. SGX enclaves have a per-thread event state, which allows waiting for and setting specific bits. This is already used by the current mutex implementation. The thread parker can however be much more efficient, as it only needs to store the `TCS` address of one thread. This address is stored in a state variable, which can also be set to indicate the thread was already notified. `park_timeout` does not guard against spurious wakeups like the current condition variable does. This is allowed by the API of `Parker`, and I think it is better to let users handle these wakeups themselves as the guarding is quite expensive and might not be necessary. `@jethrogb` as you wrote the initial SGX support for `std`, I assume you are the target maintainer? Could you help me test this, please? Lacking a x86_64 chip, I can't run SGX.
2022-12-09Replace hand-made masking by call to masked() method in FileTypeArthur Carcano-1/+1
2022-12-08Bump compiler-builtins to 0.1.85Martin Kröning-1/+1
2022-12-08Add read_to_end for AnonPipeAyush Singh-1/+17
Add `read_to_end` method for `sys::{target}::pipe::AnonPipe`. This allows having a more optimized version of `read_to_end` for ChildStdout. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-08Rollup merge of #105120 - solid-rs:patch/kmc-solid/maintainance, r=thomccMatthias Krüger-23/+38
kmc-solid: `std::sys` code maintenance Includes a set of changes to fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets and make some other improvements. - Address `fuzzy_provenance_casts` by using `expose_addr` and `from_exposed_addr` for pointer-integer casts - Add a stub implementation of `is_terminal` (#98070) - Address `unused_imports` and `unused_unsafe` - Stop doing `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`
2022-12-07Avoid heap allocation when truncating thread namesGavin Li-12/+7
Ensure that heap allocation does not occur in a thread until std::thread is ready. This fixes issues with custom allocators that call std::thread::current(), since doing so prematurely initializes THREAD_INFO and causes the following thread_info::set() to fail.
2022-12-07Use more LFS functions.Michael Benfield-8/+31
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts. This is relevant to #94173. With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe #94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
2022-12-07Auto merge of #103459 - ChrisDenton:propagate-nulls, r=thomccbors-14/+20
Pass on null handle values to child process Fixes #101645 In Windows, stdio handles are (semantically speaking) `Option<Handle>` where `Handle` is a non-zero value. When spawning a process with `Stdio::Inherit`, Rust currently turns zero values into `-1` values. This has the unfortunate effect of breaking console subprocesses (which typically need stdio) that are spawned from gui applications (that lack stdio by default) because the console process won't be assigned handles from the newly created console (as they usually would in that situation). Worse, `-1` is actually [a valid handle](https://doc.rust-lang.org/std/os/windows/io/struct.OwnedHandle.html) which means "the current process". So if a console process, for example, waits on stdin and it has a `-1` value then the process will end up waiting on itself. This PR fixes it by propagating the nulls instead of converting them to `-1`. While I think the current behaviour is a mistake, changing it (however justified) is an API change so I think this PR should at least have some input from t-libs-api. So choosing at random... r? `@joshtriplett`