about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-02-26std: use random HashMap keys on Hermitjoboet-2/+17
2023-02-25Auto merge of #107405 - hermitcore:bsd, r=bjorn3bors-475/+583
add support of RustyHermit's BSD socket layer RustyHermit is a tier 3 platform and publishes a new kernel interface. The new version supports a common BSD socket layer. By supporting this interface, the implementation of `std` can be harmonized to other operating systems. In `sys_common/mod.rs` we remove only a special case for RustyHermit. All changes are done in the RustyHermit specific directories. To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-25[stdio][windows] Use MBTWC and WCTMBNicole Mazzuca-29/+78
2023-02-25Auto merge of #108233 - ChrisDenton:move-std-tests, r=thomccbors-0/+16
Move some std tests from `tests/ui-fulldeps` into `library/std` This allows them to be tested normally along with other `./x test std` tests. Moving `rename_directory` is simple enough but `create_dir_all_bare` needed to be an std integration test. Additionally, some tests that I couldn't move atm have instead been placed in an `std` subdirectory. These tests include ones that do fun things with processes or that intentionally abort the test process. r? libs
2023-02-24avoid the usage of libc during the creation of documentationStefan Lankes-9/+7
2023-02-24remove code duplicationsStefan Lankes-393/+129
2023-02-24move IO traits to std/src/os/hermitStefan Lankes-73/+102
By moving the IO traits, the RustyHermit support is harmonized to of other operating systems.
2023-02-24add support of RustyHermit's BSD socket layerStefan Lankes-456/+801
RustHermit publishs a new kernel interface and supports a common BSD socket layer. By supporting this interface, the implementation can be harmonized to other operating systems. To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-24Rollup merge of #108391 - sunfishcode:sunfishcode/is-terminal-file-length, ↵Dylan DPC-19/+21
r=ChrisDenton Fix `is_terminal`'s handling of long paths on Windows. As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case. This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-24Rollup merge of #108370 - fbq:time-doc-fix, r=thomccDylan DPC-3/+3
std: time: Avoid to use "was created" in elapsed() description ".. since this instant was created" is inaccurate and misleading, consider the following case: ```rust let i1 = Instant::now(); // i1 is created at T1 let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2 i2.elapsed(); // at T3 ``` Per the current description, `elapsed()` at T3 should return T3 - T2? To avoid the inaccuracy, removes the "was created" in the description of {Instant,SystemTime}::elapsed(). And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
2023-02-23Stabilize atomic_as_ptrTrevor Gross-1/+0
2023-02-23Fix `is_terminal`'s handling of long paths on Windows.Dan Gohman-19/+21
As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case. This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-23Rollup merge of #108218 - ChrisDenton:cmd-escape, r=cuviperMatthias Krüger-1/+10
Windows: Quote more batch file arguments Make sure to always quote batch file arguments that contain command prompt special characters. Additionally add `/d` command line parameter to disable any autorun scripts that may change the way variable expansion works. This makes it more consistent across systems and may help avoid surprises. ## Background Info [`CreateProcess`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with the `lpApplicationName` set can only be used to run `.exe` files and not script files such as `.bat`. However, for historical reasons, we do have special handling so that `.bat` files will be correctly run with `cmd.exe` as the application. In Windows, command line arguments are passed as a single string (not an array). Applications can parse this string however they like but most follow the standard MSVC C/C++ convention. But `cmd.exe` uses different argument parsing rules to other Windows programs (because it emulates old DOS). This PR aims to help smooth over some of the differences. r? libs
2023-02-22std: time: Avoid to use "was created" in elapsed() descriptionBoqun Feng-3/+3
".. since this instant was created" is inaccurate and misleading, consider the following case: let i1 = Instant::now(); // i1 is created at T1 let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2 i2.elapsed(); // at T3 Per the current description, `elapsed()` at T3 should return T3 - T2? Therefore removes the "was created" in the description of {Instant,SystemTime}::elapsed(). And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
2023-02-22Rollup merge of #107736 - tgross35:atomic-as-ptr, r=m-ou-seMatthias Krüger-3/+3
Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893) Originally discussed in https://github.com/rust-lang/rust/issues/66893#issuecomment-1419198623 ~~This uses #107706 as a base to avoid a merge conflict once that gets rolled up (so disregard const changes in the diff until it does)~~ all merged & rebased `@rustbot` label +T-libs-api r? m-ou-se
2023-02-22Quote more batch file argumentsChris Denton-1/+10
Make sure to quote batch file arguments that contain command prompt special characters. Additionally add `/d` command line parameter to disable any commands that may change the way variable expansion works.
2023-02-21Move `rename_directory` from ui-fulldeps to stdChris Denton-0/+16
std has had a `TempDir` implementation for a long time now.
2023-02-21Remove unused FileDesc::get_cloexecTomasz Miąsko-5/+0
2023-02-21Rollup merge of #108272 - MrNossiom:master, r=thomccDylan DPC-1/+1
docs: wrong naming convention in struct keyword doc Noticed that the naming convention mentioned is not the right one. As far as I know, PacalCase is the naming convention used for structs names. PacalCase is not the same as camelCase
2023-02-21Rollup merge of #108105 - majaha:patch-1, r=cuviperDylan DPC-6/+10
Explain the default panic hook better This changes the documentation of `std::panic::set_hook` and `take_hook` to explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs. I also reworded a few things for clarity.
2023-02-20Explain the default panic hook betterMatt Harding-6/+10
This changes the documentation of `std::panic::set_hook` and `take_hook` to better explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.
2023-02-20use UpperCamelCaseMilo Moisson-1/+1
2023-02-20docs: wrong naming convention in struct keyword docMilo Moisson-1/+1
2023-02-20Distribute libntdll.a with windows-gnu toolchainsChris Denton-47/+40
This allows loading some essential functions (e.g. read/write file) at load time instead of lazily.
2023-02-19Use custom implementation of read_buf in Read for &'a FileDescTomasz Miąsko-0/+4
This allows to skip an unnecessary buffer initialization.
2023-02-19Rollup merge of #104659 - tshepang:reflow, r=workingjubileeDylan DPC-2/+4
reflow the stack size story
2023-02-18Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-sebors-17/+120
Optimize `LazyLock` size The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently. `@rustbot` label +T-libs +A-atomic
2023-02-17Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on WindowsDan Gohman-0/+72
Implement the Windows counterpart to #97437 and #107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2023-02-17std: add regression test for #107466joboet-0/+13
Tests that messages are immediately dropped once the last receiver is destroyed.
2023-02-17std: drop all messages in bounded channel when destroying the last receiverjoboet-27/+109
2023-02-16std: replace generic thread parker with explicit no-op parkerjoboet-129/+17
2023-02-16Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-seDylan DPC-179/+40
Use id-based thread parking on SOLID By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX. ping ``@kawadakk`` r? ``@m-ou-se`` ``@rustbot`` label +T-libs
2023-02-15Suggest simpler fs helper methods in File::{open,create}Kornel-1/+10
2023-02-15Demonstrate I/O in File examplesKornel-0/+9
2023-02-14Revert to using `RtlGenRandom`Chris Denton-103/+31
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems.
2023-02-13Rollup merge of #107985 - alesito85:master, r=ChrisDentonMatthias Krüger-1/+6
Added another error to be processed in fallback This pull request addresses the problem of Rust not being able to read file/directory metadata because the current user doesn't have permission to read the file and are thus inaccessible. One particular example is `System Volume Information`. But any example can be made by having a file/directory, which the current user can't access even though the system does allow to view the metadata, which is handled by the fallback. The fallback exists to get the metadata but it was limited to one error type. Having added ERROR_ACCESS_DENIED per Chris Denton's suggestion, file/directory properties are now properly read. Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-13Add another error to Windows file open fallbackalesito85-1/+6
Added another error to be processed in fallback Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-12Hermit: Remove floor symbolMartin Kröning-5/+0
This symbol should be provided by Hermit.
2023-02-12Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcmbors-5/+4
Use associated items of `char` instead of freestanding items in `core::char` The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-11Auto merge of #106677 - tbu-:pr_less_doc_hidden_pub, r=scottmcmbors-4/+0
Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gates
2023-02-11Rollup merge of #107900 - ChrisDenton:zero-header, r=thomccDylan DPC-0/+2
Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` header Makes sure the full header is correctly initialized. Fixes #107884
2023-02-11Rollup merge of #106001 - sdroege:glibc-skip-over-null-argv, r=ChrisDentonDylan DPC-6/+22
Stop at the first `NULL` argument when iterating `argv` Some C commandline parsers (e.g. GLib and Qt) are replacing already handled arguments in `argv` with `NULL` and move them to the end. That means that `argc` might be bigger than the actual number of non-`NULL` pointers in `argv` at this point. To handle this we simply stop iterating at the first `NULL` argument. `argv` is also guaranteed to be `NULL`-terminated so any non-`NULL` arguments after the first `NULL` can safely be ignored. Fixes https://github.com/rust-lang/rust/issues/105999
2023-02-10Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893)Trevor Gross-3/+3
2023-02-10Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` headerChris Denton-0/+2
Makes sure the full header is correctly initialized, including reserve parameters.
2023-02-10Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gatesTobias Bucher-4/+0
2023-02-09Allow wasi-libc to initialize its environment variables lazily.Dan Gohman-1/+7
Use `__wasilibc_get_environ()` to read the environment variable list from wasi-libc instead of using `environ`. `environ` is a global variable which effectively requires wasi-libc to initialize the environment variables eagerly, and `__wasilibc_get_environ()` is specifically designed to be an alternative that lets wasi-libc intiailize its environment variables lazily. This should have the side effect of fixing at least some of the cases of #107635.
2023-02-08Rollup merge of #107429 - tgross35:from-bytes-until-null-stabilization, ↵Michael Goulet-1/+0
r=dtolnay Stabilize feature `cstr_from_bytes_until_nul` This PR seeks to stabilize `cstr_from_bytes_until_nul`. Partially addresses #95027 This function has only been on nightly for about 10 months, but I think it is simple enough that there isn't harm discussing stabilization. It has also had at least a handful of mentions on both the user forum and the discord, so it seems like it's already in use or at least known. This needs FCP still. Comment on potential discussion points: - eventual conversion of `CStr` to be a single thin pointer: this function will still be useful to provide a safe way to create a `CStr` after this change. - should this return a length too, to address concerns about the `CStr` change? I don't see it as being particularly useful, and it seems less ergonomic (i.e. returning `Result<(&CStr, usize), FromBytesUntilNulError>`). I think users that also need this length without the additional `strlen` call are likely better off using a combination of other methods, but this is up for discussion - `CString::from_vec_until_nul`: this is also useful, but it doesn't even have a nightly implementation merged yet. I propose feature gating that separately, as opposed to blocking this `CStr` implementation on that Possible alternatives: A user can use `from_bytes_with_nul` on a slice up to `my_slice[..my_slice.iter().find(|c| c == 0).unwrap()]`. However; that is significantly less ergonomic, and is a bit more work for the compiler to optimize compared the direct `memchr` call that this wraps. ## New stable API ```rs // both in core::ffi pub struct FromBytesUntilNulError(()); impl CStr { pub const fn from_bytes_until_nul( bytes: &[u8] ) -> Result<&CStr, FromBytesUntilNulError> } ``` cc ```@ericseppanen``` original author, ```@Mark-Simulacrum``` original reviewer, ```@m-ou-se``` brought up some issues on the thin pointer CStr ```@rustbot``` modify labels: +T-libs-api +needs-fcp
2023-02-08Rollup merge of #107317 - ids1024:asfd-rc, r=dtolnayMichael Goulet-0/+16
Implement `AsFd` and `AsRawFd` for `Rc` Fixes https://github.com/rust-lang/rust/issues/105931.
2023-02-08std: add tracking issue for `RawOsError`joboet-2/+2
2023-02-06Rollup merge of #107714 - Wilfred:round_docs, r=m-ou-seMatthias Krüger-4/+4
Clarify wording on f64::round() and f32::round() "Round half-way cases" is a little confusing (it's a 'garden path sentence' as it's not immediately clear whether round is an adjective or verb). Make this sentence longer and clearer.