summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2020-11-15Pin the ReentrantMutexes in sys::io::stdio.Mara Bos-25/+30
The code before this change misused the ReentrantMutexes, by calling init() on them and moving them afterwards. Now that ReentrantMutex requires Pin for init(), this mistake is no longer easy to make.
2020-11-15Return a Pin from SyncOnceCell::get_or_init_pin.Mara Bos-4/+7
2020-11-15Add (internal-only) SyncOnceCell::get_or_init_pin.Mara Bos-0/+52
2020-11-15Update ReentrantMutex tests to use Pin.Mara Bos-15/+21
2020-11-15Use Pin for the 'don't move' requirement of ReentrantMutex.Mara Bos-33/+19
2020-11-15Remove unnecessary import of `crate::marker` in std::sys_common::remutex.Mara Bos-2/+1
It was used for marker::Send, but Send is already in scope.
2020-11-15Fix outdated comment about not needing to flush stderr.Mara Bos-7/+3
2020-11-12[beta] always disable copy_file_range to avoid EOVERFLOW errorsThe8472-1/+1
2020-10-03Rollup merge of #77264 - fusion-engineering-forks:skip-local-stdio, r=dtolnayJonas Schievink-23/+61
Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used. The thread local `LOCAL_STDOUT` and `LOCAL_STDERR` are only used by the `test` crate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing. This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive. This change keeps a global flag (`LOCAL_STREAMS`) which will be set to `true` when either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered. --- Together with https://github.com/rust-lang/rust/pull/77154, this should make output a little bit more efficient.
2020-10-03Rollup merge of #77182 - GuillaumeGomez:missing-examples-fd-traits, r=pickfireJonas Schievink-0/+40
Add missing examples for Fd traits Not sure what happened here... This is a reopening of #77142 r? @Dylan-DPC
2020-10-03Rollup merge of #75377 - canova:map_debug_impl, r=dtolnayJonas Schievink-8/+4
Fix Debug implementations of some of the HashMap and BTreeMap iterator types HashMap's `ValuesMut`, BTreeMaps `ValuesMut`, IntoValues and `IntoKeys` structs were printing both keys and values on their Debug implementations. But they are iterators over either keys or values. Irrelevant values should not be visible. With this PR, they only show relevant fields. This fixes #75297. [Here's an example code.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0c79356ed860e347a0c1a205616f93b7) This prints this on nightly: ``` ValuesMut { inner: IterMut { range: [(1, "hello"), (2, "goodbye")], length: 2 } } IntoKeys { inner: [(1, "hello"), (2, "goodbye")] } IntoValues { inner: [(1, "hello"), (2, "goodbye")] } [(2, "goodbye"), (1, "hello")] ``` After the patch this example prints these instead: ``` ["hello", "goodbye"] ["hello", "goodbye"] [1, 2] ["hello", "goodbye"] ``` I didn't add test cases for them, since I couldn't see any tests for Debug implementations anywhere. But please let me know if I should add it to a specific place. r? @dtolnay
2020-10-02Rollup merge of #77432 - tmiasko:posix-spawn-musl, r=cuviperJonas Schievink-6/+8
Use posix_spawn on musl targets The posix_spawn had been available in a form suitable for use in a Command implementation since musl 0.9.12. Use it in a preference to a fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-10-02Simplify fd examplesGuillaume Gomez-19/+16
2020-10-02Auto merge of #77029 - ehuss:command-access, r=dtolnaybors-8/+303
Add accessors to Command. This adds some accessor methods to `Command` to provide a way to access the values set when building the `Command`. An example where this can be useful is to display the command to be executed. This is roughly based on the [`ProcessBuilder`](https://github.com/rust-lang/cargo/blob/13b73cdaf76b2d9182515c9cf26a8f68342d08ef/src/cargo/util/process_builder.rs#L105-L134) in Cargo. Possible concerns about the API: - Values with NULs on Unix will be returned as `"<string-with-nul>"`. I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept in `Command`. - Does not handle `arg0` on Unix. This can be awkward to support in `get_args` and is rarely used. I figure if someone really wants it, it can be added to `CommandExt` as a separate method. - Does not offer a way to detect `env_clear`. I'm uncertain if it would be useful for anyone. - Does not offer a way to get an environment variable by name (`get_env`). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return a `Option<Option<&OsStr>>`?). - `get_envs` could skip "cleared" entries and just return `&OsStr` values instead of `Option<&OsStr>`. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't display `None` entries. I erred on the side of providing extra information, but I suspect many situations will just filter out the `None`s. - Could implement more iterator stuff (like `DoubleEndedIterator`). I have not implemented new std items before, so I'm uncertain if the existing issue should be reused, or if a new tracking issue is needed. cc #44434
2020-10-02Rollup merge of #77429 - WaffleLapkin:doc_link_default_hasher_new, r=jyn514Yuki Okushi-4/+3
Link `new` method in `DefautHasher`s doc FIXME referenced #56922 which was resolved r? @jyn514
2020-10-02Rollup merge of #77362 - RReverser:patch-1, r=dtolnayYuki Okushi-1/+1
Fix is_absolute on WASI WASI does not match `cfg(unix)`, but its paths are Unix-like (`/some/path`) and don't have Windows-like prefixes. Without this change, `is_absolute` for any paths, including `/some/path`, was returning `false`on a WASI target, which is obviously not true and undesirable.
2020-10-02Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dtolnayYuki Okushi-121/+100
Split sys_common::Mutex in StaticMutex and MovableMutex. The (unsafe) `Mutex` from `sys_common` had a rather complicated interface. You were supposed to call `init()` manually, unless you could guarantee it was neither moved nor used reentrantly. Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if `destroy()` should only be called when `init()` was called. This allowed for a number of interesting (confusing?) different ways to use this `Mutex`, all captured in a single type. In practice, this type was only ever used in two ways: 1. As a static variable. In this case, neither `init()` nor `destroy()` are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the `LockGuard`, never with `raw_lock`. 2. As a `Box`ed variable. In this case, both `init()` and `destroy()` are called, it will be moved and possibly used reentrantly. No other combinations are used anywhere in `std`. This change simplifies things by splitting this `Mutex` type into two types matching the two use cases: `StaticMutex` and `MovableMutex`. The interface of both new types is now both safer and simpler. The first one does not call nor expose `init`/`destroy`, and the second one calls those automatically in its `new()` and `Drop` functions. Also, the locking functions of `MovableMutex` are no longer unsafe. --- This will also make it easier to conditionally box mutexes later, by moving that decision into sys/sys_common. Some of the mutex implementations (at least those of Wasm and 'sys/unsupported') are safe to move, so wouldn't need a box. ~~(But that's blocked on #76932 for now.)~~ (See #77380.)
2020-10-02Rollup merge of #76979 - fusion-engineering-forks:windows-fallback-check, ↵Yuki Okushi-45/+53
r=dtolnay Improve std::sys::windows::compat Improves the compat_fn macro in sys::windows, which is used for conditionally loading APIs that might not be available. - The module (dll) name can now be any string, not just an ident. (Not all Windows api modules are valid Rust identifiers. E.g. `WaitOnAddress` comes from `API-MS-Win-Core-Synch-l1-2-0.dll`.) - Adds `FuncName::is_available()` for checking if a function is really available without having to do a duplicate lookup. - Add comment explaining the lack of locking. - Use `$_:block` to simplify the macro_rules. - Apply `allow(unused_variables)` only to the fallback instead of everything. --- The second point (`is_available()`) simplifies code that needs to pick an implementation depening on what is available, like `sys/windows/mutex.rs`. Before this change, it'd do its own lookup and keep its own `AtomicUsize` to track the result. Now it can just use `c::AcquireSRWLockExclusive::is_available()` directly. This will also be useful when park/unpark/CondVar/etc. get improved implementations (e.g. from parking_lot or something else), as the best APIs for those are not available before Windows 8.
2020-10-02Link `new` method in `DefautHasher`s docWaffle-4/+3
2020-10-01Auto merge of #76969 - withoutboats:rawfd-refexive-traits, r=dtolnaybors-0/+57
Make RawFd implement the RawFd traits This PR makes `RawFd` implement `AsRawFd`, `IntoRawFd` and `FromRawFd`, so it can be passed to interfaces that use one of those traits as a bound.
2020-10-01Work around potential merging/duplication issues in sys/windows/compat.Mara Bos-3/+19
2020-10-01Formatting.Mara Bos-5/+1
2020-10-01Use AcquireSRWLockExclusive::is_available() instead of an extra lookup.Mara Bos-17/+6
2020-10-01Improve std::sys::windows::compat.Mara Bos-28/+35
- Module name can now be any string, not just an ident. (Not all Windows api modules are valid Rust identifiers.) - Adds c::FuncName::is_available() for checking if a function is really available without having to do a duplicate lookup. - Add comment explaining the lack of locking. - Use `$_:block` to simplify the macro_rules. - Apply allow(unused_variables) only to the fallback instead of everything.
2020-10-01Auto merge of #76919 - fusion-engineering-forks:thread-parker, r=dtolnaybors-112/+276
Use futex-based thread::park/unpark on Linux. This moves the parking/unparking logic out of `thread/mod.rs` into a module named `thread_parker` in `sys_common`. The current implementation is moved to `sys_common/thread_parker/generic.rs` and the new implementation using futexes is added in `sys_common/thread_parker/futex.rs`.
2020-10-01Rollup merge of #77315 - exrook:rename-allocerror, r=joshtriplettDylan DPC-12/+12
Rename AllocErr to AllocError Implements rust-lang/wg-allocators#57
2020-10-01Use posix_spawn on musl targetsTomasz Miąsko-6/+8
The posix_spawn had been available in a form suitable for use in a Command implementation since musl 0.9.12. Use it in a preference to a fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-09-30Rollup merge of #77328 - hyd-dev:assert-to-rtassert, r=AmanieuJonas Schievink-1/+1
Use `rtassert!` instead of `assert!` from the child process after fork() in std::sys::unix::process::Command::spawn() As discussed in #73894, `assert!` panics on failure, which is not signal-safe, and `rtassert!` is a suitable replacement. Fixes #73894. r? @Amanieu @cuviper @joshtriplett
2020-09-30Fix is_absolute on WASIIngvar Stepanyan-1/+1
WASI does not match `cfg(unix)`, but its paths are Unix-like (`/some/path`) and don't have Windows-like prefixes. Without this change, `is_absolute` for paths like `/some/path` was returning `false`on a WASI target, which is obviously not true and undesirable.
2020-09-30Auto merge of #77292 - lzutao:std_asm, r=Amanieubors-16/+24
Prefer asm! in std - all in sgx module Similar to the change in #76669 but all `llvm_asm!` is gate in x86/x86_64 target. Godbolt: - https://rust.godbolt.org/z/h7nG1h - https://rust.godbolt.org/z/xx39hW
2020-09-29Use `rtassert!` instead of `assert!` from the child process after fork() in ↵hyd-dev-1/+1
std::sys::unix::process::Command::spawn() `assert!` panics on failure, which is not signal-safe.
2020-09-28Rename AllocErr to AllocErrorJacob Hughes-12/+12
2020-09-28Rollup merge of #77288 - RalfJung:miri-macos, r=AmanieuRalf Jung-49/+50
fix building libstd for Miri on macOS Fixes a Miri regression introduced by https://github.com/rust-lang/rust/pull/75295 Cc @tmiasko @Amanieu
2020-09-28Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obkRalf Jung-0/+1
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]` `rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute. Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?). r? @oli-obk
2020-09-28Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matkladRalf Jung-0/+59
UI to unit test for those using Cell/RefCell/UnsafeCell Helps with #76268. I'm working on all files using `Cell` and moving them to unit tests when possible. r? @matklad
2020-09-28Prefer asm! in std - all in sgx moduleLzu Tao-16/+24
2020-09-28Auto merge of #77282 - glaubitz:sparc-linux, r=nagisabors-0/+2
Add missing definitions required by the sparc-unknown-linux-gnu target This PR adds a few missing definitions required by sparc-unknown-linux-target which were discovered during build tests.
2020-09-28fix building libstd for Miri on macOSRalf Jung-49/+50
2020-09-28library/std: Set OS raw type definitions for sparc-unknown-linux-gnuJohn Paul Adrian Glaubitz-0/+1
2020-09-28library/std/sys_common: Define MIN_ALIGN for sparc-unknown-linux-gnuJohn Paul Adrian Glaubitz-0/+1
2020-09-27Reopen standard streams when they are closed on UnixTomasz Miąsko-0/+62
The syscalls returning a new file descriptors generally use lowest-numbered file descriptor not currently opened, without any exceptions for those corresponding to the standard streams. Previously when any of standard streams has been closed before starting the application, operations on std::io::{stderr,stdin,stdout} objects were likely to operate on other logically unrelated file resources opened afterwards. Avoid the issue by reopening the standard streams when they are closed.
2020-09-27Add a feature gate for basic function pointer use in `const fn`Dylan MacKenzie-0/+1
2020-09-27Optimize set_{panic,print}(None).Mara Bos-0/+8
2020-09-27Relax memory ordering of LOCAL_STREAMS and document it.Mara Bos-5/+17
2020-09-27Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used.Mara Bos-23/+41
The thread local LOCAL_STDOUT and LOCAL_STDERR are only used by the test crate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing. This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive. This change keeps a global flag (LOCAL_STREAMS) which will be set to true when either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered.
2020-09-27Move thread parker to sys_common.Mara Bos-3/+2
2020-09-27Add notes about memory ordering to futex parker implementation.Mara Bos-0/+20
2020-09-27Check conversion from Duration to timespec in futex_wait.Mara Bos-12/+11
2020-09-27Move linux-specific futex code into `sys` module.Mara Bos-36/+42
2020-09-27Fix warning.Mara Bos-1/+1