about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2024-03-08further changes from feedbackDavid Carlier-19/+1
2024-03-08Document overrides of `clone_from()`Noa-2/+14
Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".
2024-03-08Rollup merge of #121938 - blyxxyz:quadratic-vectored-write, r=AmanieuMatthias Krüger-31/+50
Fix quadratic behavior of repeated vectored writes Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. This fix is to only calculate as much as needed if it's needed. Here's a test program: ```rust #![feature(write_all_vectored)] use std::fs::File; use std::io::{BufWriter, IoSlice, Write}; use std::time::Instant; fn main() { let buf = vec![b'\0'; 100_000_000]; let mut slices: Vec<IoSlice<'_>> = buf.chunks(100).map(IoSlice::new).collect(); let mut writer = BufWriter::new(File::create("/dev/null").unwrap()); let start = Instant::now(); write_smart(&slices, &mut writer); println!("write_smart(): {:?}", start.elapsed()); let start = Instant::now(); writer.write_all_vectored(&mut slices).unwrap(); println!("write_all_vectored(): {:?}", start.elapsed()); } fn write_smart(mut slices: &[IoSlice<'_>], writer: &mut impl Write) { while !slices.is_empty() { // Only try to write as many slices as can be written let res = writer .write_vectored(slices.get(..1024).unwrap_or(slices)) .unwrap(); slices = &slices[(res / 100)..]; } } ``` Before this change: ``` write_smart(): 6.666952ms write_all_vectored(): 498.437092ms ``` After this change: ``` write_smart(): 6.377158ms write_all_vectored(): 6.923412ms ``` `LineWriter` (and by extension `Stdout`) isn't fully repaired by this because it looks for newlines. I could open an issue for that after this is merged, I think it's fixable but not trivially.
2024-03-08Rollup merge of #118623 - haydonryan:master, r=workingjubileeMatthias Krüger-4/+4
Improve std::fs::read_to_string example Resolves [#118621](https://github.com/rust-lang/rust/issues/118621) For the original code to succeed it requires address.txt to contain a socketaddress, however it is much easier to follow if this is just any strong - eg address could be a street address or just text. Also changed the variable name from "foo" to something more meaningful as cargo clippy warns you against using foo as a placeholder. ``` $ cat main.rs use std::fs; use std::error::Error; fn main() -> Result<(), Box<dyn Error>> { let addr: String = fs::read_to_string("address.txt")?.parse()?; println!("{}", addr); Ok(()) } $ cat address.txt 123 rusty lane san francisco 94999 $ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.00s Running `/home/haydon/workspace/rust-test-pr/tester/target/debug/tester` 123 rusty lane san francisco 94999 ```
2024-03-07Rollup merge of #122147 - kadiwa4:private_impl_mods, r=workingjubileeGuillaume Gomez-48/+44
Make `std::os::unix::ucred` module private Tracking issue: #42839 Currently, this unstable module exists: [`std::os::unix::ucred`](https://doc.rust-lang.org/stable/std/os/unix/ucred/index.html). All it does is provide `UCred` (which is also available from `std::os::unix::net`), `impl_*` (which is probably a mishap and should be private) and `peer_cred` (which is undocumented but has a documented counterpart at `std::os::unix::net::UnixStream::peer_cred`). This PR makes the entire `ucred` module private and moves it into `net`, because that's where it is used. I hope it's fine to simply remove it without a deprecation phase. Otherwise, I can add back a deprecated reexport module `std::os::unix::ucred`. `@rustbot` label: -T-libs +T-libs-api
2024-03-07make `std::os::unix::ucred` module privateKalle Wachsmuth-48/+44
2024-03-07Rust is a proper name: rust → RustRalf Jung-11/+11
2024-03-07Auto merge of #122113 - matthiaskrgr:rollup-5d1jnwi, r=matthiaskrgrbors-0/+1
Rollup of 9 pull requests Successful merges: - #121958 (Fix redundant import errors for preload extern crate) - #121976 (Add an option to have an external download/bootstrap cache) - #122022 (loongarch: add frecipe and relax target feature) - #122026 (Do not try to format removed files) - #122027 (Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries) - #122063 (Make the lowering of `thir::ExprKind::If` easier to follow) - #122074 (Add missing PartialOrd trait implementation doc for array) - #122082 (remove outdated fixme comment) - #122091 (Note why we're using a new thread in `test_get_os_named_thread`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-06Document and test minimal stack size on WindowsChris Denton-0/+15
2024-03-06Dynamically size sigaltstk in stdJubilee Young-11/+39
On modern Linux with Intel AMX and 1KiB matrices, Arm SVE with potentially 2KiB vectors, and RISCV Vectors with up to 16KiB vectors, we must handle dynamic signal stack sizes. We can do so unconditionally by using getauxval, but assuming it may return 0 as an answer, thus falling back to the old constant if needed.
2024-03-06fix `close_read_wakes_up` testLukas Markeffsky-15/+18
2024-03-06Note why we're using a new thread in a testChris Denton-0/+1
2024-03-06Remove unnecessary fixmeChris Denton-5/+0
As the FIXME itself notes, there's nothing to fix here.
2024-03-06Be stricter with `copy_file_range` probe resultsTobias Bucher-33/+35
2024-03-06Auto merge of #121956 - ChrisDenton:srwlock, r=joboetbors-30/+136
Windows: Implement condvar, mutex and rwlock using futex Well, the Windows equivalent: [`WaitOnAddress`,](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress) [`WakeByAddressSingle`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakebyaddresssingle) and [`WakeByAddressAll`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakebyaddressall). Note that Windows flavoured futexes can be different sizes (1, 2, 4 or 8 bytes). I took advantage of that in the `Mutex` implementation. I also edited the Mutex implementation a bit more than necessary. I was having trouble keeping in my head what 0, 1 and 2 meant so I replaced them with consts. I *think* we're maybe spinning a bit much. `WaitOnAddress` seems to be looping quite a bit too. But for now I've keep the implementations the same. I do wonder if it'd be worth reducing or removing our spinning on Windows. This also adds a new shim to miri, because of course it does. Fixes #121949
2024-03-06Less syscalls for the `copy_file_range` probeTobias Bucher-23/+48
If it's obvious from the actual syscall results themselves that the syscall is supported or unsupported, don't do an extra syscall with an invalid file descriptor. CC #122052
2024-03-06unix time module now return resultAntoine PLASKOWSKI-51/+35
2024-03-05Add `Waitable` traitChris Denton-10/+43
2024-03-05Windows: Implement mutex using futexChris Denton-30/+103
Well, the Windows equivalent: `WaitOnAddress`, `WakeByAddressSingle` and `WakeByAddressAll`.
2024-03-04std::threads: revisit stack address calculation on netbsd.David Carlier-2/+21
like older linux glibc versions, we need to get the guard size and increasing the stack's bottom address accordingly.
2024-03-04Don't run test_get_os_named_thread on win7roblabla-1/+1
This test won't work on windows 7, as the Thread::set_name function is not implemented there (win7 does not provide a documented mechanism to set thread names).
2024-03-03std::rand: enable getrandom for dragonflybsd too.David Carlier-1/+9
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-31/+50
Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. The fix is to only calculate as much as needed if it's needed.
2024-03-03Add missing get_name for wasm::thread.Ian Neumann-0/+4
2024-03-03Auto merge of #121856 - ChrisDenton:abort, r=joboetbors-10/+13
Cleanup windows `abort_internal` As the comments on the functions say, we define abort in both in panic_abort and in libstd. This PR makes the two implementation (mostly) the same. Additionally it: * uses `options(noreturn)` on the asm instead of using `core::intrinsics::unreachable`. * removed unnecessary allow lints * added `FAST_FAIL_FATAL_APP_EXIT` to our generated Windows API bindings instead of defining it manually (std only)
2024-03-02Cleanup windows abort_internalChris Denton-10/+13
2024-03-02Rollup merge of #121758 - joboet:move_pal_thread_local, r=ChrisDentonMatthias Krüger-3/+4
Move thread local implementation to `sys` Part of #117276.
2024-03-02Rollup merge of #121666 - ChrisDenton:thread-name, r=cuviperMatthias Krüger-11/+137
Use the OS thread name by default if `THREAD_INFO` has not been initialized Currently if `THREAD_INFO` hasn't been initialized then the name will be set to `None`. This PR changes it to use the OS thread name by default. This mostly affects foreign threads at the moment but we could expand this to make more use of the OS thread name in the future. Note: I've only implemented `Thread::get_name` for windows, linux and macos (and macos adjacent) targets. The rest just return `None`.
2024-03-02Rollup merge of #121861 - tbu-:pr_floating_point_exact_examples, ↵Matthias Krüger-22/+26
r=workingjubilee Use the guaranteed precision of a couple of float functions in docs
2024-03-02Rollup merge of #109263 - squell:master, r=cuviperMatthias Krüger-5/+4
fix typo in documentation for std::fs::Permissions Please check and re-check this PR carefully to see if I got this right. But by my logic, if the `read_only` function returns `true`, I would not expect be able to write to the file (it being read only); so this text is meant to clarify that `read_only` being `false` doesn't mean *you* can actually write to the file, just that "in general" someone is able to.
2024-03-01Add `get_name` placeholder to other targetsChris Denton-8/+40
2024-03-01Use the guaranteed precision of a couple of float functions in docsTobias Bucher-22/+26
2024-03-01Rollup merge of #121736 - HTGAzureX1212:HTGAzureX1212/remove-mutex-unlock, ↵Matthias Krüger-20/+0
r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in https://github.com/rust-lang/rust/issues/81872#issuecomment-1474104525, it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes #81872.
2024-03-01revise interface to read directory entriesStefan Lankes-97/+116
The new interface has some similarities to Linux system call getdents64. The system call reads several dirent64 structures. At the end of each dirent64 is stored the name of the file. The length of file name is implictly part of dirent64 because d_reclen contains size of dirent64 plus the length of the file name.
2024-03-01Extending filesystem support for hermit-ossimonschoening-96/+225
2024-03-01Auto merge of #114016 - krtab:delete_sys_memchr, r=workingjubileebors-231/+8
Delete architecture-specific memchr code in std::sys Currently all architecture-specific memchr code is only used in `std::io`. Most of the actual `memchr` capacity exposed to the user through the slice API is instead implemented in `core::slice::memchr`. Hence this commit deletes `memchr` from `std::sys[_common]` and replace calls to it by calls to `core::slice::memchr` functions. This deletes `(r)memchr` from the list of symbols linked to libc. The interest of putting architecture specific code back in core is linked to the discussion to be had in #113654
2024-02-29Remove doc aliases to PATHTrevor Gross-2/+0
Remove aliases for `split_paths` and `join_paths` as should have been done in <https://github.com/rust-lang/rust/pull/119748> (Bors merged the wrong commit).
2024-02-29Rollup merge of #121596 - ChrisDenton:tls, r=joboetGuillaume Gomez-22/+13
Use volatile access instead of `#[used]` for `on_tls_callback` The first commit adds a volatile load of `p_thread_callback` when registering a dtor so that the compiler knows if the callback is used or not. I don't believe the added volatile instruction is otherwise significant in the context. In my testing using the volatile load allowed the compiler to correctly reason about whether `on_tls_callback` is used or not, allowing it to be omitted entirely in some cases. Admittedly it usually is used due to `Thread` but that can be avoided (e.g. in DLLs or with custom entry points that avoid the offending APIs). Ideally this would be something the compiler could help a bit more with so we didn't have to use tricks like `#[used]` or volatile. But alas. I also used this as an opportunity to clean up the `unused` lints which I don't think serve a purpose any more. The second commit removes the volatile load of `_tls_used` with `#cfg[target_thread_local]` because `#[thread_local]` already implies it. And if it ever didn't then `#[thread_local]` would be broken when there aren't any dtors.
2024-02-29Rollup merge of #121793 - tbu-:pr_floating_point_32, r=AmanieuGuillaume Gomez-0/+184
Document which methods on `f32` are precise Same as #118217 but for `f32`.
2024-02-29Rollup merge of #121765 - hermit-os:errno, r=ChrisDentonGuillaume Gomez-6/+6
add platform-specific function to get the error number for HermitOS Extending `std` to get the last error number for HermitOS. HermitOS is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-02-29Rollup merge of #118217 - tbu-:pr_floating_point, r=AmanieuGuillaume Gomez-0/+184
Document which methods on `f64` are precise
2024-02-29Document which methods on `f32` are preciseTobias Bucher-0/+184
Same as #118217 but for `f32`.
2024-02-29Document the precision of `f64` methodsTobias Bucher-0/+184
2024-02-29Rollup merge of #121778 - ibraheemdev:patch-19, r=RalfJungJacob Pratt-0/+3
Document potential memory leak in unbounded channel Follow up on https://github.com/rust-lang/rust/pull/121646.
2024-02-29Rollup merge of #121768 - ecton:condvar-unwindsafe, r=m-ou-seJacob Pratt-1/+5
Implement unwind safety for Condvar on all platforms Closes #118009 This commit adds unwind safety consistency to Condvar. Previously, only select platforms implemented unwind safety through auto traits. Known by this committer: On Linux, `Condvar` implemented `UnwindSafe` but on Mac and Windows, it did not. This change changes the implementation from auto to explicit. In #118009, it was suggested that the platform differences were a bug and that a simple PR could address this. In trying to determine the best information to put in the `#[stable]` attribute, it [was suggested](https://github.com/rust-lang/rust/issues/121690#issuecomment-1968298470) I copy the stability information from the previous unwind safety implementations.
2024-02-29Rollup merge of #119748 - tgross35:suggest-path-split, r=AmanieuJacob Pratt-1/+17
Increase visibility of `join_path` and `split_paths` Add some crosslinking among `std::env` pages to make it easier to discover `join_paths` and `split_paths`. Also add aliases to help anyone searching for `PATH`.
2024-02-29fix typosIbraheem Ahmed-3/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-02-29document potential memory leak in unbounded channelIbraheem Ahmed-0/+3
2024-02-29Rollup merge of #110543 - joboet:reentrant_lock, r=m-ou-seMatthias Krüger-207/+375
Make `ReentrantLock` public Implements the ACP rust-lang/libs-team#193. ``@rustbot`` label +T-libs-api +S-waiting-on-ACP
2024-02-28Implement unwind safety for CondvarJonathan Johnson-1/+5
Closes #118009 This commit adds unwind safety to Condvar. Previously, only select platforms implemented unwind safety through auto traits. Known by this committer: Linux was unwind safe, but Mac and Windows are not before this change.