about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2024-02-05Rollup merge of #120607 - conradludgate:fix-120603, r=dtolnayMatthias Krüger-2/+36
fix #120603 by adding a check in default_read_buf Fixes #120603 by checking the returned read n is in-bounds of the cursor. Interestingly, I noticed that `BorrowedBuf` side-steps this issue by using checked accesses. Maybe this can be switched to unchecked to mirror what BufReader does https://github.com/rust-lang/rust/blob/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/core/src/io/borrowed_buf.rs#L95
2024-02-05Rollup merge of #120572 - pheki:update-libc, r=Mark-SimulacrumMatthias Krüger-1/+1
Update libc to 0.2.153 Bumps libc dependency to 0.2.153, which includes this fix, required for building std for the vita: https://github.com/rust-lang/libc/pull/3552
2024-02-05Remove unused structr0cky-9/+0
2024-02-04Document various I/O handle conversionsRyan Lowe-0/+25
2024-02-03Rollup merge of #120528 - GnomedDev:atomicu8-backtrace-style, r=cuviperMatthias Krüger-6/+6
Store SHOULD_CAPTURE as AtomicU8 `BacktraceStyle` easily fits into a u8, so `SHOULD_CAPTURE`, which is just `Atomic<Option<BacktraceStyle>>`, should be stored as `AtomicU8`
2024-02-03Rollup merge of #120523 - a1phyr:improve_read_buf_exact, r=the8472Matthias Krüger-1/+4
Improve `io::Read::read_buf_exact` error case - Use `const_io_error` instead of `Error::new` - Use the same message as `read_exact`
2024-02-03add another test to make sure it still works with full readsConrad Ludgate-2/+15
2024-02-03fix #120603 by adding a check in default_read_bufConrad Ludgate-1/+22
2024-02-01Update libc to 0.2.153Aphek-1/+1
2024-01-31Make File::read_to_end less specialKornel-2/+2
Follow-up to #117925
2024-01-31Store SHOULD_CAPTURE as AtomicU8GnomedDev-6/+6
2024-01-31Rollup merge of #120430 - devnexen:fix_tls_dtor_fbsd, r=cuviperNadrieril-2/+2
std: thread_local::register_dtor fix proposal for FreeBSD. following-up 5d3d347 commit, rust started to spin __cxa_thread_call_dtors warnings even without any TLS usage. using instead home made TLS destructor handler `register_dtor_fallback`. close #120413
2024-01-31Improve `io::Read::read_buf_exact` error caseBenoît du Garreau-1/+4
- Use `const_io_error` instead of `Error::new` - Use the same message as `read_exact`
2024-01-30Rollup merge of #120485 - chenyukang:yukang-add-query-instability-check, ↵Guillaume Gomez-0/+3
r=michaelwoerister add missing potential_query_instability for keys and values in hashmap From https://github.com/rust-lang/rust/pull/120435#discussion_r1468883787, These API are also returning iterator, so we need add `potential_query_instability` for them?
2024-01-30Rollup merge of #120434 - fmease:revert-speeder, r=petrochenkovGuillaume Gomez-223/+124
Revert outdated version of "Add the wasm32-wasi-preview2 target" An outdated version of #119616 was merged in rollup #120309. This reverts those changes to enable #119616 to “retain the intended diff” after a rebase. ```@rylev``` has agreed that this would be the cleanest approach with respect to the history. Unblocks #119616. r? ```@petrochenkov``` or compiler or libs
2024-01-30Rollup merge of #120295 - reitermarkus:remove-ffi-nonzero, r=dtolnayGuillaume Gomez-17/+12
Remove `raw_os_nonzero` feature. This feature is superseded by a generic `NonZero` type: https://github.com/rust-lang/rust/issues/120257 Closes https://github.com/rust-lang/rust/issues/82363.
2024-01-30Rollup merge of #120452 - alexcrichton:update-windows-seek-write-docs, ↵Guillaume Gomez-1/+1
r=ChrisDenton std: Update documentation of seek_write on Windows Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states: > If Length and ByteOffset specify a write operation past the current > end-of-file mark, NtWriteFile automatically extends the file and updates > the end-of-file mark; any bytes that are not explicitly written between > such old and new end-of-file marks are defined to be zero. This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides.
2024-01-30Rollup merge of #119991 - kornelski:endless-read, r=the8472Guillaume Gomez-0/+10
Reject infinitely-sized reads from io::Repeat These calls would always run out of memory. Related to #117925
2024-01-30Auto merge of #117925 - kornelski:read-to-oom, r=Amanieubors-7/+47
Handle out of memory errors in io:Read::read_to_end() #116570 got stuck due to a [procedural confusion](https://github.com/rust-lang/rust/pull/116570#issuecomment-1768271068). Retrying so that it can get FCP with the proper team now. cc `@joshtriplett` `@BurntSushi` ---- I'd like to propose handling of out-of-memory errors in the default implementation of `io::Read::read_to_end()` and `fs::read()`. These methods create/grow a `Vec` with a size that is external to the program, and could be arbitrarily large. Due to being I/O methods, they can already fail in a variety of ways, in theory even including `ENOMEM` from the OS too, so another failure case should not surprise anyone. While this may not help much Linux with overcommit, it's useful for other platforms like WASM. [Internals thread](https://internals.rust-lang.org/t/io-read-read-to-end-should-handle-oom/19662). I've added documentation that makes it explicit that the OOM handling is a nice-to-have, and not a guarantee of the trait. I haven't changed the implementation of `impl Read for &[u8]` and `VecDeque` out of caution, because in these cases users could assume `read` can't fail. This code uses `try_reserve()` + `extend_from_slice()` which is optimized since #117503.
2024-01-30add missing potential_query_instability for keys and values in hashmapyukang-0/+3
2024-01-30Add stdarch_wasm_atomic_wait feature in stdAmanieu d'Antras-0/+1
2024-01-30Update feature names for new stdarchAmanieu d'Antras-12/+18
2024-01-30Update stdarch submoduleAmanieu d'Antras-0/+5
2024-01-29Handle out of memory errors in fs::read/read_to_stringKornel-4/+6
2024-01-29Handle out of memory errors in io:Read::read_to_end()Kornel-3/+41
2024-01-29Remove `raw_os_nonzero` feature.Markus Reiter-17/+12
2024-01-29std: always check the result of `pthread_mutex_lock`joboet-1/+18
2024-01-29Rollup merge of #120462 - mu001999:clean, r=NilstriebDylan DPC-3/+0
Clean dead code Detected by #118257
2024-01-29Rollup merge of #120373 - HTGAzureX1212:HTGAzureX1212/issue-120040, ↵Dylan DPC-1/+33
r=ChrisDenton Adjust Behaviour of `read_dir` and `ReadDir` in Windows Implementation: Check Whether Path to Search In Exists This pull request changes the `read_dir` function's and the `ReadDir` structure's internal implementations for the Windows operating system to make its behaviour more accurate. It should be noted that `ERROR_FILE_NOT_FOUND` is returned by the `FindFirstFileW` function when *no matching files can be found*, not necessarily that the path to search in does not exist in the first place. Therefore, directly returning the "The system cannot find the file specified." may not be accurate. An extra check for whether the path to search in exists is added, returning a constructed `ReadDir` iterator with its handle being an `INVALID_HANDLE_VALUE` returned by the `FindFirstFileW` function if `ERROR_FILE_NOT_FOUND` is indeed the last OS error. The `ReadDir` implementation for the Windows operating system is correspondingly updated to always return `None` if the handle it has is an `INVALID_HANDLE_VALUE` which can only be the case if and only if specifically constructed by the `read_dir` function in the aforementioned conditions. It should also be noted that `FindFirstFileW` would have returned `ERROR_PATH_NOT_FOUND` if the path to search in does not exist in the first place. Presumably fixes #120040.
2024-01-29Clean dead coder0cky-3/+0
2024-01-28Make `impl<T: AsHandle>` impl take `?Sized`Gary Guo-5/+5
2024-01-28Make `impl<Fd: AsFd>` impl take `?Sized`Gary Guo-5/+5
2024-01-28std: Update documentation of seek_write on WindowsAlex Crichton-1/+1
Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states: > If Length and ByteOffset specify a write operation past the current > end-of-file mark, NtWriteFile automatically extends the file and updates > the end-of-file mark; any bytes that are not explicitly written between > such old and new end-of-file marks are defined to be zero. This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides.
2024-01-28Revert "Add the wasm32-wasi-preview2 target"León Orell Valerian Liehr-223/+124
This reverts commit 31ecf341250a889ac1154b2cbe3f0b97f9d008c1. Co-authored-by: Ryan Levick <me@ryanlevick.com>
2024-01-27std: thread_local::register_dtor fix proposal for FreeBSD.David Carlier-2/+2
following-up 5d3d347 commit, rust started to spin __cxa_thread_call_dtors warnings even without any TLS usage. using instead home made TLS destructor handler `register_dtor_fallback`. close #120413
2024-01-27Reject infinitely-sized reads from io::RepeatKornel-0/+10
Related to #117925
2024-01-27Switch `NonZero` alias direction.Markus Reiter-0/+11
2024-01-27add extra check for invalid handle in ReadDir::nextHTGAzureX1212.-1/+8
2024-01-27make modifications as per reviewsHTGAzureX1212.-21/+25
2024-01-26Rollup merge of #120205 - Berrysoft:windows-alloc-init, r=ChrisDentonMatthias Krüger-11/+13
std: make `HEAP` initializer never inline The system allocator for Windows calls `init_or_get_process_heap` every time allocating. It generates very much useless code and makes the binary larger. The `HEAP` only needs to initialize once before the main fn. Concerns: * I'm not sure if `init` will be properly called in cdylib. * Do we need to ensure the allocator works if the user enables `no_main`? * Should we panic if `GetProcessHeap` returns null?
2024-01-26Rollup merge of #120117 - NobodyXu:99262/update-api-and-doc, r=m-ou-seMatthias Krüger-7/+33
Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in https://github.com/rust-lang/rust/issues/99262#issuecomment-1894246216
2024-01-26fixHTGAzureX1212.-2/+2
2024-01-26remove redundant call to Error::last_os_errorHTGAzureX1212.-1/+1
2024-01-26fix issue 120040HTGAzureX1212.-0/+21
2024-01-26Rollup merge of #120053 - AldanTanneo:specialize-stdinlock-bytes, r=the8472Matthias Krüger-1/+10
Specialize `Bytes` on `StdinLock<'_>` I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the `.bytes()` iterator adaptor; I figured, since `StdinLock` is a `BufReader` internally, it would work just as fast. But this is not the case, as `Bytes` is only specialized for the raw `BufReader`, and not the `StdinLock`/`MutexGuard` wrapper. Performance improved significantly when I wrapped the lock in a new `BufReader`, but I was still a bit sore about the double buffer indirection. This PR attempts to specialize it, by simply calling the already specialized implementation on `BufReader`.
2024-01-25Rollup merge of #120332 - mu001999:cleanup/dead_code, r=NilstriebMatthias Krüger-3/+0
Remove unused struct Detected by #118257
2024-01-25Rollup merge of #120306 - safinaskar:clone3-clean-up, r=petrochenkovMatthias Krüger-7/+32
Clean up after clone3 removal from pidfd code (docs and tests) https://github.com/rust-lang/rust/pull/113939 removed clone3 from pidfd code. This patchset does necessary clean up: fixes docs and tests
2024-01-24Rollup merge of #119616 - rylev:wasm32-wasi-preview2, r=petrochenkov,m-ou-seLeón Orell Valerian Liehr-124/+223
Add a new `wasm32-wasi-preview2` target This is the initial implementation of the MCP https://github.com/rust-lang/compiler-team/issues/694 creating a new tier 3 target `wasm32-wasi-preview2`. That MCP has been seconded and will most likely be approved in a little over a week from now. For more information on the need for this target, please read the [MCP](https://github.com/rust-lang/compiler-team/issues/694). There is one aspect of this PR that will become insta-stable once these changes reach a stable compiler: * A new `target_family` named `wasi` is introduced. This target family incorporates all wasi targets including `wasm32-wasi` and its derivative `wasm32-wasi-preview1-threads`. The difference between `target_family = wasi` and `target_os = wasi` will become much clearer when `wasm32-wasi` is renamed to `wasm32-wasi-preview1` and the `target_os` becomes `wasm32-wasi-preview1`. You can read about this target rename in [this MCP](https://github.com/rust-lang/compiler-team/issues/695) which has also been seconded and will hopefully be officially approved soon. Additional technical details include: * Both `std::sys::wasi_preview2` and `std::os::wasi_preview2` have been created and mostly use `#[path]` annotations on their submodules to reach into the existing `wasi` (soon to be `wasi_preview1`) modules. Over time the differences between `wasi_preview1` and `wasi_preview2` will grow and most like all `#[path]` based module aliases will fall away. * Building `wasi-preview2` relies on a [`wasi-sdk`](https://github.com/WebAssembly/wasi-sdk) in the same way that `wasi-preview1` does (one must include a `wasi-root` path in the `Config.toml` pointing to sysroot included in the wasi-sdk). The target should build against [wasi-sdk v21](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-21) without modifications. However, the wasi-sdk itself is growing [preview2 support](https://github.com/WebAssembly/wasi-sdk/pull/370) so this might shift rapidly. We will be following along quickly to make sure that building the target remains possible as the wasi-sdk changes. * This requires a [patch to libc](https://github.com/rylev/rust-libc/tree/wasm32-wasi-preview2) that we'll need to land in conjunction with this change. Until that patch lands the target won't actually build.
2024-01-24Finishing clone3 clean upAskar Safin-4/+2
2024-01-24This commit is part of clone3 clean up. Merge tests from ↵Askar Safin-2/+18
tests/ui/command/command-create-pidfd.rs to library/std/src/sys/pal/unix/process/process_unix/tests.rs to remove code duplication