about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-10-10Rollup merge of #101118 - devnexen:fs_getmode_bsd, r=Mark-SimulacrumYuki Okushi-2/+16
fs::get_mode enable getting the data via fcntl/F_GETFL on major BSD supporting this flag.
2022-10-09Auto merge of #93668 - SUPERCILEX:path_alloc, r=joshtriplettbors-286/+394
Reduce CString allocations in std as much as possible Currently, every operation involving paths in `fs` allocates memory to hold the path before sending it through the syscall. This PR instead uses a stack allocation (chosen size is somewhat arbitrary) when the path is short before falling back to heap allocations for long paths. Benchmarks show that the stack allocation is ~2x faster for short paths: ``` test sys::unix::fd::tests::bench_heap_path_alloc ... bench: 34 ns/iter (+/- 2) test sys::unix::fd::tests::bench_stack_path_alloc ... bench: 15 ns/iter (+/- 1) ``` For long paths, I couldn't find any measurable difference. --- I'd be surprised if I was the first to think of this, so I didn't fully flush out the PR. If this change is desirable, I'll make use of `run_with_cstr` across all platforms in every fs method (currently just unix open for testing). I also added an `impl From<FromBytesWithNulError>` which is presumably a no-no (or at least needs to be done in another PR). --- Also see https://github.com/nix-rust/nix/pull/1655 with a bunch of discussion where I'm doing something similar.
2022-10-08Rollup merge of #102812 - est31:remove_lazy, r=dtolnayMichael Howell-4/+0
Remove empty core::lazy and std::lazy PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08std: optimize TLS on Windowsjoboet-117/+202
2022-10-08Remove empty core::lazy and std::lazyest31-4/+0
PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08use memset to initialize a readbufThe 8472-3/+6
2022-10-08std: do not use dispatch semaphore under miri (yet)joboet-5/+8
2022-10-08std: remove unused linker attributejoboet-1/+1
2022-10-08Auto merge of #99505 - joboet:futex_once, r=thomccbors-289/+483
std: use futex in `Once` Now that we have efficient locks, let's optimize the rest of `sync` as well. This PR adds a futex-based implementation for `Once`, which drastically simplifies the implementation compared to the generic version, which is provided as fallback for platforms without futex (Windows only supports them on newer versions, so it uses the fallback for now). Instead of storing a linked list of waiters, the new implementation adds another state (`QUEUED`), which is set when there are waiting threads. These now use `futex_wait` on that state and are woken by the running thread when it finishes and notices the `QUEUED` state, thereby avoiding unnecessary calls to `futex_wake_all`.
2022-10-07Make tests capture the error printed by a Result returnDavid Tolnay-9/+24
2022-10-07Rollup merge of #102760 - saethlin:dont-reinit-buffer, r=Mark-SimulacrumDylan DPC-3/+48
Avoid repeated re-initialization of the BufReader buffer Fixes https://github.com/rust-lang/rust/issues/102727 We accidentally removed this in https://github.com/rust-lang/rust/pull/98748. It looks so redundant. But it isn't. The default `Read::read_buf` will defensively initialize the whole buffer, if any of it is indicated to be uninitialized. In uses where reads from the wrapped `Read` impl completely fill the `BufReader`, `initialized` and `filled` are the same, and this extra member isn't required. But in the reported issue, the `BufReader` wraps a `Read` impl which will _never_ fill the whole buffer. So the default `Read::read_buf` implementation repeatedly re-initializes the extra space in the buffer. This adds back the extra `initialized` member, which ensures that the default `Read::read_buf` only zero-initialized the buffer once, and I've tried to add a comment which explains this whole situation.
2022-10-07Rollup merge of #102475 - RalfJung:unsafe, r=dtolnayDylan DPC-31/+120
unsafe keyword: trait examples and unsafe_op_in_unsafe_fn update Having a safe `fn` in an `unsafe trait` vs an `unsafe fn` in a safe `trait` are pretty different situations, but the distinction is subtle and can confuse even seasoned Rust developers. So let's have explicit examples of both. I also removed the existing `unsafe trait` example since it was rather strange. Also the `unsafe_op_in_unsafe_fn` lint can help disentangle the two sides of `unsafe`, so update the docs to account for that.
2022-10-07review feedbackRalf Jung-42/+43
2022-10-07Improved documentation for `std::io::Error`StackOverflowExcept1on-1/+2
2022-10-07std: use futex in `Once`joboet-289/+483
2022-10-06Don't needless link to `libresolv` on Darwin in libstdThom Chiovoloni-4/+0
2022-10-06Avoid defensive re-initialization of the BufReader bufferBen Kimock-3/+48
2022-10-06std: add thread parking testsjoboet-0/+22
2022-10-06std: use semaphore for thread parking on Apple platformsjoboet-1/+140
2022-10-06Auto merge of #99497 - vladimir-ea:stdlib_os_api_watchos, r=thomccbors-0/+235
Standard library OS support for Apple WatchOS This PR was split from https://github.com/rust-lang/rust/pull/98101
2022-10-06Fix whitespaceFlorian Bartels-2/+2
2022-10-06Prevent UB in child process after calling libc::forkFlorian Bartels-4/+23
After calling libc::fork, the child process tried to access a TLS variable when processing a panic. This caused a memory allocation which is UB in the child. To prevent this from happening, the panic handler will not access the TLS variable in case `panic::always_abort` was called before.
2022-10-06Rollup merge of #102693 - BlackHoleFox:revert-apple-entropy-changes, r=thomccMatthias Krüger-56/+38
Revert "Use getentropy when possible on all Apple platforms" Per https://github.com/rust-lang/rust/issues/102643, This reverts commit 3fc35b5b935e390c61ea2bbf744838b2632b2df1 to avoid breaking any Rust on iOS users. Closes https://github.com/rust-lang/rust/issues/102643
2022-10-05tidyIbraheem Ahmed-2/+2
Co-authored-by: yvt <i@yvt.jp>
2022-10-05Revert "Use getentropy when possible on all Apple platforms"BlackHoleFox-56/+38
This reverts commit 3fc35b5b935e390c61ea2bbf744838b2632b2df1.
2022-10-04Rollup merge of #102574 - aDotInTheVoid:const_collections_with_hasher, ↵Michael Howell-2/+17
r=oli-obk,fee1-dead Make Hash{Set,Map}::with_hasher unstably const Makes [`HashMap::with_hasher`](https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.with_hasher) and [`HashSet::with_hasher`](https://doc.rust-lang.org/stable/std/collections/hash_set/struct.HashSet.html#method.with_hasher) `const`. This allows ```rust static GlobalState: Mutex<HashMap<i32, i32, SomeHasher>> = Mutex::new(HashMap::with_hasher(SomeHasher::new())) ``` Tracking issue: #102575
2022-10-05Interpret EH actions properlyGary Guo-3/+2
The EH actions stored in the LSDA follows the format of GCC except table (even for LLVM-generated code). An missing action in the table is the encoding for `Terminate`, see [1]. The currently code interprets it as `None`, as a workaround for #35011, an issue that seems to occur in LLVM 3.7 and not after 3.9. These are very old versions of LLVM and we don't support them anymore, so remove this workaround and interpret them properly. Note that LLVM currently does not emit any `Terminate` actions, but GCC does. Although GCC backend currently doesn't do unwinding, removing it preemptively would prevent future developers from wasting time to figure out what's wrong. [1]: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_personality.cc#L522-L526
2022-10-04Auto merge of #101768 - sunfishcode:sunfishcode/wasi-stdio-lock-asfd, ↵bors-0/+27
r=joshtriplett Add `AsFd` implementations for stdio lock types on WASI. This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls. This is similar to #100892, but is for the `*Lock` types.
2022-10-04fix backtrace small typoRageking8-3/+3
2022-10-03Reduce CString allocations in std as much as possibleAlex Saveau-286/+394
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-03Reword "has no meaning" per suggestionTim-2/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-10-03Add SAFETY comments for AsFd implementations on stdin/stdout/stderrJosh Triplett-0/+3
2022-10-03Add stability attributes.Dan Gohman-3/+6
2022-10-03scoped threads: pass closure through MaybeUninit to avoid invalid dangling ↵Ralf Jung-0/+33
references
2022-10-02Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-sebors-1/+1
Change `is_some_and` to take by value Consistent with other function-accepting `Option` methods. Tracking issue: #93050 r? `@m-ou-se`
2022-10-02Make Hash{Set,Map}::with_hasher unstably constNixon Enraght-Moony-2/+17
2022-10-02Rollup merge of #102313 - anirudh24seven:update_sleep_ms_doc, r=Mark-SimulacrumMatthias Krüger-0/+2
Update docs so that deprecated method points to relevant method The docs for the deprecated 'park_timeout_ms' method suggests that the user 'use park_timeout' method instead (at https://doc.rust-lang.org/std/thread/index.html). Making a similar change so that the docs for the deprecated `sleep_ms` method suggest that the user `use sleep` method instead.
2022-10-01Change feature name to is_some_andCameron Steffen-1/+1
2022-10-01`SetFileTime` doesn't allow setting the file time to `0xFFFF_FFFF_FFFF_FFFF`beetrees-0/+8
2022-10-01Error instead of panicking when setting file times if the passed ↵beetrees-49/+37
`SystemTime` doesn't fit into the required type
2022-09-30Standard library OS support for Apple WatchOSVladimir Michael Eatwell-0/+235
2022-09-29unsafe keyword: trait examples and unsafe_op_in_unsafe_fn updateRalf Jung-32/+120
2022-09-29Stabilize `nonnull_slice_from_raw_parts`Yuki Okushi-1/+0
2022-09-29Rollup merge of #102433 - RalfJung:temp-dir-typo, r=thomccYuki Okushi-1/+1
env::temp_dir: fix a typo
2022-09-29Rollup merge of #102368 - beetrees:nano-niche, r=joshtriplettYuki Okushi-13/+21
Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant` As the nanoseconds fields is always between `0` and `(NANOS_PER_SEC - 1)` inclusive, use the `rustc_layout_scalar_valid_range` attributes to create a niche in the nanosecond field of `Duration` and `Timespec` (which is used to implement unix `SystemTime` and non-apple unix `Instant`; windows `Instant` is implemented with `Duration` and therefore will also benefit). This change has the benefit of making `Option<T>` the same size as `T` for the previously mentioned types. Also shrinks the nanoseconds field of `Timespec` to a `u32` as nanoseconds do not need the extra range of an `i64`, shrinking `Timespec` by 4 bytes on 32-bit platforms. r? ```@joshtriplett```
2022-09-29Rollup merge of #98368 - sunfishcode:sunfishcode/std-os-fd, r=joshtriplettYuki Okushi-46/+26
Make `std::os::fd` public. `std::os::fd` defines types like `OwnedFd` and `RawFd` and is common between Unix and non-Unix platforms that share a basic file-descriptor concept. Rust currently uses this internally to simplify its own code, but it would be useful for external users in the same way, so make it public. This means that `OwnedFd` etc. will all appear in three places, for example on unix platforms: - `std::os::fd::OwnedFd` - `std::os::unix::io::OwnedFd` - `std::os::unix::prelude::OwnedFd` r? `````@joshtriplett`````
2022-09-28env::temp_dir: fix a typoRalf Jung-1/+1
2022-09-28Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant`beetrees-13/+21
2022-09-28std: never panic in `thread::park` and `thread::park_timeout`joboet-2/+20
2022-09-28Rollup merge of #102288 - mejrs:inner, r=compiler-errorsYuki Okushi-0/+2
Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`. This suggests various ways to get inside wrapper types if the method cannot be found on the wrapper type, but is present on the wrappee. For this PR, those wrapper types include `Localkey`, `MaybeUninit`, `RefCell`, `RwLock` and `Mutex`.