about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2022-03-25Check for `"` and `\` in a filenameChris Denton-1/+9
And also fix typo.
2022-03-25std::process docs: linkify references to output, spawn and statusest31-7/+20
2022-03-24Document Linux kernel handoff in std::io::copy and std::fs::copyMartin Pool-2/+14
2022-03-24Explicitly use CLOCK_MONOTONIC in futex_wait.Mara Bos-3/+3
Instant might be changed to use CLOCK_BOOTTIME at some point.
2022-03-24Make Timespec available in sys::unix.Mara Bos-15/+13
2022-03-24Use FUTEX_WAIT_BITSET rather than FUTEX_WAIT on Linux.Mara Bos-22/+38
2022-03-23Add a `compile_fail` doctest to check that `io::Error: !UnwindSafe`Thom Chiovoloni-0/+9
2022-03-23Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafeThom Chiovoloni-5/+6
2022-03-23Spin before blocking in Mutex::lock.Mara Bos-4/+38
2022-03-23Update tests.Mara Bos-1/+1
2022-03-23Replace Linux Mutex and Condvar with futex based ones.Mara Bos-8/+149
2022-03-23Add futex_wake_all.Mara Bos-0/+12
2022-03-23Return timeout status in futex_wait.Mara Bos-4/+5
2022-03-23Auto merge of #95173 - m-ou-se:sys-locks-module, r=dtolnaybors-100/+133
Move std::sys::{mutex, condvar, rwlock} to std::sys::locks. This cleans up the the std::sys modules a bit by putting the locks in a single module called `locks` rather than spread over the three modules `mutex`, `condvar`, and `rwlock`. This makes it easier to organise lock implementations, which helps with https://github.com/rust-lang/rust/issues/93740.
2022-03-23Add test for issue #95178Chris Denton-0/+21
2022-03-23Command: handle exe and batch files separatelyChris Denton-22/+113
2022-03-23Refactor: Move argument building into argsChris Denton-69/+70
2022-03-23Rollup merge of #91608 - workingjubilee:fold-neon-fp, r=nagisa,AmanieuDylan DPC-1/+0
Fold aarch64 feature +fp into +neon Arm's FEAT_FP and Feat_AdvSIMD describe the same thing on AArch64: The Neon unit, which handles both floating point and SIMD instructions. Moreover, a configuration for AArch64 must include both or neither. Arm says "entirely proprietary" toolchains may omit floating point: https://developer.arm.com/documentation/102374/0101/Data-processing---floating-point In the Programmer's Guide for Armv8-A, Arm says AArch64 can have both FP and Neon or neither in custom implementations: https://developer.arm.com/documentation/den0024/a/AArch64-Floating-point-and-NEON In "Bare metal boot code for Armv8-A", enabling Neon and FP is just disabling the same trap flag: https://developer.arm.com/documentation/dai0527/a In an unlikely future where "Neon and FP" become unrelated, we can add "[+-]fp" as its own feature flag. Until then, we can simplify programming with Rust on AArch64 by folding both into "[+-]neon", which is valid as it supersets both. "[+-]neon" is retained for niche uses such as firmware, kernels, "I just hate floats", and so on. I am... pretty sure no one is relying on this. An argument could be made that, as we are not an "entirely proprietary" toolchain, we should not support AArch64 without floats at all. I think that's a bit excessive. However, I want to recognize the intent: programming for AArch64 should be simplified where possible. For x86-64, programmers regularly set up illegal feature configurations because it's hard to understand them, see https://github.com/rust-lang/rust/issues/89586. And per the above notes, plus the discussion in https://github.com/rust-lang/rust/issues/86941, there should be no real use cases for leaving these features split: the two should in fact always go together. - Fixes rust-lang/rust#95002. - Fixes rust-lang/rust#95064. - Fixes rust-lang/rust#95122.
2022-03-22Fold aarch64 feature +fp into +neonJubilee Young-1/+0
Arm's FEAT_FP and Feat_AdvSIMD describe the same thing on AArch64: The Neon unit, which handles both floating point and SIMD instructions. Moreover, a configuration for AArch64 must include both or neither. Arm says "entirely proprietary" toolchains may omit floating point: https://developer.arm.com/documentation/102374/0101/Data-processing---floating-point In the Programmer's Guide for Armv8-A, Arm says AArch64 can have both FP and Neon or neither in custom implementations: https://developer.arm.com/documentation/den0024/a/AArch64-Floating-point-and-NEON In "Bare metal boot code for Armv8-A", enabling Neon and FP is just disabling the same trap flag: https://developer.arm.com/documentation/dai0527/a In an unlikely future where "Neon and FP" become unrelated, we can add "[+-]fp" as its own feature flag. Until then, we can simplify programming with Rust on AArch64 by folding both into "[+-]neon", which is valid as it supersets both. "[+-]neon" is retained for niche uses such as firmware, kernels, "I just hate floats", and so on.
2022-03-22Move std::sys::{mutex, condvar, rwlock} to std::sys::locks.Mara Bos-40/+64
2022-03-22add some fixZHANGWENTAI-3/+4
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22fix the lint problemZHANGWENTAI-1/+1
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22update Termination trait docsZHANGWENTAI-0/+4
2022-03-22Auto merge of #95158 - sunfishcode:sunfishcode/windows-8, r=joshtriplettbors-2/+24
Preserve the Windows `GetLastError` error in `HandleOrInvalid`. In the `TryFrom<HandleOrInvalid> for OwnedHandle` and `TryFrom<HandleOrNull> for OwnedHandle` implemenations, `forget` the owned handle on the error path, to avoid calling `CloseHandle` on an invalid handle. It's harmless, except that it may overwrite the thread's `GetLastError` error. r? `@joshtriplett`
2022-03-21Stabilize Stdin::lines.Mara Bos-2/+1
2022-03-21Move pthread locks to own module.Mara Bos-60/+69
2022-03-20Add a testcase.Dan Gohman-0/+6
2022-03-20Preserve the Windows `GetLastError` error in `HandleOrInvalid`.Dan Gohman-2/+18
In the `TryFrom<HandleOrInvalid> for OwnedHandle` and `TryFrom<HandleOrNull> for OwnedHandle` implemenations, `forget` the owned handle on the error path, to avoid calling `CloseHandle` on an invalid handle. It's harmless, except that it may overwrite the thread's `GetLastError` error.
2022-03-20Rollup merge of #95114 - ChrisDenton:symlink-test, r=the8472Matthias Krüger-2/+9
Skip a test if symlink creation is not possible If someone running tests on Windows does not have Developer Mode enabled then creating symlinks will fail which in turn would cause this test to fail. This can be a stumbling block for contributors.
2022-03-20Rollup merge of #94749 - RalfJung:remove-dir-all-miri, r=cuviperMatthias Krüger-6/+7
remove_dir_all: use fallback implementation on Miri Fixes https://github.com/rust-lang/miri/issues/1966 The new implementation requires `openat`, `unlinkat`, and `fdopendir`. These cannot easily be shimmed in Miri since libstd does not expose APIs corresponding to them. So for now it is probably easiest to just use the fallback code in Miri. Nobody should run Miri as root anyway...
2022-03-19Stabilize thread::is_finishedJubilee Young-2/+2
2022-03-19Skip a test if symlink creation is not possibleChris Denton-2/+9
2022-03-19Rollup merge of #94650 - ChrisDenton:windows-absolute-fix, r=dtolnayDylan DPC-7/+7
Relax tests for Windows dos device names Windows 11 no longer turn paths ending with dos device names into device paths. E.g. `C:\path\to\COM1.txt` used to get turned into `\\.\COM1`. Whereas now this path is left as is. Note though that if the given path is an exact (case-insensitive) match for the string `COM1` then it'll still be converted to `\\.\COM1`.
2022-03-19Rollup merge of #93858 - krallin:process-process_group, r=dtolnayDylan DPC-2/+90
Add a `process_group` method to UNIX `CommandExt` - Tracking issue: #93857 - RFC: https://github.com/rust-lang/rfcs/pull/3228 Add a `process_group` method to `std::os::unix::process::CommandExt` that allows setting the process group id (i.e. calling `setpgid`) in the child, thus enabling users to set process groups while leveraging the `posix_spawn` fast path.
2022-03-19Rollup merge of #94984 - ericseppanen:cstr_from_bytes, r=Mark-SimulacrumDylan DPC-0/+106
add `CStr` method that accepts any slice containing a nul-terminated string I haven't created an issue (tracking or otherwise) for this yet; apologies if my approach isn't correct. This is my first code contribution. This change adds a member fn that converts a slice into a `CStr`; it is intended to be safer than `from_ptr` (which is unsafe and may read out of bounds), and more useful than `from_bytes_with_nul` (which requires that the caller already know where the nul byte is). The reason I find this useful is for situations like this: ```rust let mut buffer = [0u8; 32]; unsafe { some_c_function(buffer.as_mut_ptr(), buffer.len()); } let result = CStr::from_bytes_with_nul(&buffer).unwrap(); ``` This code above returns an error with `kind = InteriorNul`, because `from_bytes_with_nul` expects that the caller has passed in a slice with the NUL byte at the end of the slice. But if I just got back a nul-terminated string from some FFI function, I probably don't know where the NUL byte is. I would wish for a `CStr` constructor with the following properties: - Accept `&[u8]` as input - Scan for the first NUL byte and return the `CStr` that spans the correct sub-slice (see [future note below](https://github.com/rust-lang/rust/pull/94984#issuecomment-1070754281)). - Return an error if no NUL byte is found within the input slice I asked on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/CStr.20from.20.26.5Bu8.5D.20without.20knowing.20the.20NUL.20location.3F) whether this sounded like a good idea, and got a couple of positive-sounding responses from ``@joshtriplett`` and ``@AzureMarker.`` This is my first draft, so feedback is welcome. A few issues that definitely need feedback: 1. Naming. ``@joshtriplett`` called this `from_bytes_with_internal_nul` on Zulip, but after staring at all of the available methods, I believe that this function is probably what end users want (rather than the existing fn `from_bytes_with_nul`). Giving it a simpler name (**`from_bytes`**) implies that this should be their first choice. 2. Should I add a similar method on `CString` that accepts `Vec<u8>`? I'd assume the answer is probably yes, but I figured I'd try to get early feedback before making this change bigger. 3. What should the error type look like? I made a unit struct since `CStr::from_bytes` can only fail in one obvious way, but if I need to do this for `CString` as well then that one may want to return `FromVecWithNulError`. And maybe that should dictate the shape of the `CStr` error type also? Also, cc ``@poliorcetics`` who wrote #73139 containing similar fns.
2022-03-19Rollup merge of #93692 - mfrw:mfrw/document-keyword-in, r=dtolnayDylan DPC-0/+14
keyword_docs: document use of `in` with `pub` keyword Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com> Fixes: #93609
2022-03-19Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-handle, ↵Dylan DPC-16/+100
r=dtolnay Consistently present absent stdio handles on Windows as NULL handles. This addresses #90964 by making the std API consistent about presenting absent stdio handles on Windows as NULL handles. Stdio handles may be absent due to `#![windows_subsystem = "windows"]`, due to the console being detached, or due to a child process having been launched from a parent where stdio handles are absent. Specifically, this fixes the case of child processes of parents with absent stdio, which previously ended up with `stdin().as_raw_handle()` returning `INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an unrelated valid handle value. With this patch, `stdin().as_raw_handle()` now returns null in these situation, which is consistent with what it does in the parent process. And, document this in the "Windows Portability Considerations" sections of the relevant documentation.
2022-03-19Rollup merge of #92663 - cuviper:generic-write-cursor, r=dtolnayDylan DPC-51/+86
Implement `Write for Cursor<[u8; N]>`, plus `A: Allocator` cursor support This implements `Write for Cursor<[u8; N]>`, and also adds support for generic `A: Allocator` in `Box` and `Vec` cursors. This was inspired by a user questioning why they couldn't write a `Cursor<[u8; N]>`: https://users.rust-lang.org/t/why-vec-and-not-u8-makes-cursor-have-write/68210 Related history: - #27197 switched `AsRef<[u8]>` for reading and seeking - #67415 tried to use `AsMut<[u8]>` for writing, but did not specialize `Vec`.
2022-03-19Rollup merge of #92612 - atopia:update-lib-l4re, r=dtolnayDylan DPC-17/+809
Update stdlib for the l4re target This PR contains the work by ``@humenda`` and myself to update standard library support for the x86_64-unknown-l4re-uclibc tier 3 target, split out from humenda/rust as requested in #85967. The changes have been rebased on current master and updated in follow up commits by myself. The publishing of the changes is authorized and preferred by the original author. To preserve attribution, when standard library changes were introduced as part of other changes to the compiler, I have kept the changes concerning the standard library and altered the commit messages as indicated. Any incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
2022-03-19Rollup merge of #92519 - ChrisDenton:command-maybe-verbatim, r=dtolnayDylan DPC-30/+44
Use verbatim paths for `process::Command` if necessary In #89174, the standard library started using verbatim paths so longer paths are usable by default. However, `Command` was originally left out because of the way `CreateProcessW` was being called. This was changed as a side effect of #87704 so now `Command` paths can be converted to verbatim too (if necessary).
2022-03-18add CStr::from_bytes_until_nulEric Seppanen-0/+106
This adds a member fn that converts a slice into a CStr; it is intended to be safer than from_ptr (which is unsafe and may read out of bounds), and more useful than from_bytes_with_nul (which requires that the caller already know where the nul byte is). feature gate: cstr_from_bytes_until_nul Also add an error type FromBytesUntilNulError for this fn.
2022-03-18Bump impl Write for Cursor<[u8; N]> to 1.61David Tolnay-1/+1
2022-03-18Rollup merge of #95058 - wcampbell0x2a:use-then-in-unix-process, r=dtolnayMatthias Krüger-3/+3
Add use of bool::then in sys/unix/process Remove `else { None }` in favor of using `bool::then()`
2022-03-18Auto merge of #88098 - Amanieu:oom_panic, r=nagisabors-1/+15
Implement -Z oom=panic This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue #43596). Perf and binary size tests show negligible impact.
2022-03-17feat: Add use of bool::then in sys/unix/processwcampbell-3/+3
Remove else { None } in favor of using bool::then()
2022-03-16resolve the conflict in compiler/rustc_session/src/parse.rscodehorseman-1/+1
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16Rollup merge of #94957 - iamzhangyong:explanation-read_line, r=Dylan-DPCDylan DPC-1/+2
Improve the explanation about the behaviour of read_line Close issue like https://github.com/rust-lang/book/issues/2574
2022-03-16changed wordingDylan DPC-1/+2
2022-03-15Improve the explanation about the behaviour of read_linezed.zy-1/+1
2022-03-14Add a `process_group` method to UNIX `CommandExt`Thomas Orozco-2/+90