about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-03-03Update test.Mara Bos-4/+4
2022-03-03Rename JoinHandle::is_running to is_finished and update docs.Mara Bos-8/+18
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-03-03Rollup merge of #94534 - bstrie:cffistd, r=Mark-SimulacrumMatthias Krüger-0/+10
Re-export (unstable) core::ffi types from std::ffi
2022-03-03Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplettMatthias Krüger-72/+111
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`. This change weakens the descriptions of the `{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that they *do* express ownership relations to say that they are *typically used* in ways that express ownership relations. This is needed since, for example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of the ownership relationships. This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`, adds the requirement that raw handles be not opened with the `FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle` comment into the main `FromRawHandle::from_raw_handle` comment. And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement `FromRawHandle`, since they are intended for limited use in FFI situations, and not for generic use, and they have constraints that are stronger than the those of `FromRawHandle`. [`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-03-02Remove the comment about `FILE_FLAG_OVERLAPPED`.Dan Gohman-2/+0
There may eventually be something to say about `FILE_FLAG_OVERLAPPED` here, however this appears to be independent of the other changes in this PR, so remove them from this PR so that it can be discussed separately.
2022-03-03Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=joshtriplettDylan DPC-25/+62
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`. Also, rename `BorrowedHandle::borrow_raw_handle` and `BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. This is just a minor rename to reduce redundancy in the user code calling these functions, and to eliminate an inessential difference between `BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code. While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`. r? ``````@joshtriplett``````
2022-03-03Rollup merge of #93354 - ↵Dylan DPC-0/+12
sunfishcode:sunfishcode/document-borrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on #88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? `````@joshtriplett`````
2022-03-03update available_parallelism docs since cgroups and sched_getaffinity are ↵The 8472-1/+4
now taken into account
2022-03-03hardcode /sys/fs/cgroup instead of doing a lookup via mountinfoThe 8472-53/+67
this avoids parsing mountinfo which can be huge on some systems and something might be emulating cgroup fs for sandboxing reasons which means it wouldn't show up as mountpoint additionally the new implementation operates on a single pathbuffer, reducing allocations
2022-03-03Use cgroup quotas for calculating `available_parallelism`The 8472-3/+68
Manually tested via ``` // spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS // quota.rs #![feature(available_parallelism)] fn main() { println!("{:?}", std::thread::available_parallelism()); // prints Ok(3) } ``` Caveats * cgroup v1 is ignored * funky mountpoints (containing spaces, newlines or control chars) for cgroupfs will not be handled correctly since that would require unescaping /proc/self/mountinfo The escaping behavior of procfs seems to be undocumented. systemd and docker default to `/sys/fs/cgroup` so it should be fine for most systems. * quota will be ignored when `sched_getaffinity` doesn't work * assumes procfs is mounted under `/proc` and cgroupfs mounted and readable somewhere in the directory tree
2022-03-02Fix a broken doc link on Windows.Dan Gohman-3/+1
2022-03-02Re-export core::ffi types from std::ffibstrie-0/+10
2022-03-01Provide C FFI types via core::ffi, not just in stdJosh Triplett-220/+27
The ability to interoperate with C code via FFI is not limited to crates using std; this allows using these types without std. The existing types in `std::os::raw` become type aliases for the ones in `core::ffi`. This uses type aliases rather than re-exports, to allow the std types to remain stable while the core types are unstable. This also moves the currently unstable `NonZero_` variants and `c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving them unstable.
2022-03-01Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnayDylan DPC-11/+26
use BOOL for TCP_NODELAY setsockopt value on Windows This issue was found by the Wine project and mitigated there [^1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [^2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [^1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-02-27Stabilize unix_socket_creationThomas de Zeeuw-3/+1
2022-02-27Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrumbors-2/+2
Make TLS __getit #[inline(always)] on non-Windows This may improve perf, and/or stop `externs` perf benchmarks from being flaky. r? `@ghost`
2022-02-25Make TLS __getit #[inline(always)] on non-WindowsErik Desjardins-2/+2
This may improve perf.
2022-02-25Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-21/+20
Bump bootstrap to 1.60 This bumps the bootstrap compiler to 1.60 and cleans up cfgs and Span's rustc_pass_by_value (enabled by the bootstrap bump).
2022-02-25Switch bootstrap cfgsMark Rousskov-21/+20
2022-02-25Rename unix::net::SocketAddr::from_path to from_pathnameThomas de Zeeuw-3/+3
Matching SocketAddr::as_pathname.
2022-02-25Fix SGX docs buildJethro Beekman-1/+1
2022-02-24Rollup merge of #94273 - Dylan-DPC:doc/errorkind, r=joshtriplettMatthias Krüger-0/+13
add matching doc to errorkind Rework of #90706
2022-02-24word wrpaDylan DPC-5/+5
2022-02-24word wrpaDylan DPC-6/+9
2022-02-23Update library/std/src/io/error.rsDylan DPC-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-23fs: Don't dereference a pointer to a too-small allocationTavian Barnes-5/+9
ptr::addr_of!((*ptr).field) still requires ptr to point to an appropriate allocation for its type. Since the pointer returned by readdir() can be smaller than sizeof(struct dirent), we need to entirely avoid dereferencing it as that type. Link: https://github.com/rust-lang/miri/pull/1981#issuecomment-1048278492 Link: https://github.com/rust-lang/rust/pull/93459#discussion_r795089971
2022-02-23add some more summary from pr discussionDylan DPC-1/+1
2022-02-23add some more summary from pr discussionDylan DPC-2/+4
2022-02-23add matching to errorkindDylan DPC-0/+8
2022-02-22Stabilize Termination and ExitCodeJane Lusby-19/+44
2022-02-22Fix typo.NyantasticUwU-1/+1
Yeah just a typo (probably some breaking changes in here be careful) :)
2022-02-22Rollup merge of #94179 - devnexen:getexecname_directcall, r=kennytmMatthias Krüger-4/+1
solarish current_exe using libc call directly
2022-02-21Rollup merge of #94220 - GuillaumeGomez:miniz-oxide-decl, r=AmanieuMatthias Krüger-0/+1
Correctly handle miniz_oxide extern crate declaration Fixes https://github.com/rust-lang/rust/issues/94219. Follow-up of https://github.com/rust-lang/rust/pull/94122. The `miniz_oxide` dependency is optional and therefore should allow be "imported" when it makes sense. r? `@ivmarkov`
2022-02-21Rollup merge of #91192 - r00ster91:futuredocs, r=GuillaumeGomezMatthias Krüger-6/+8
Some improvements to the async docs The goal here is to make the docs overall a little bit more comprehensive and add more links between the things. One thing that's not working yet is the links to the keywords. Somehow I couldn't get them to work. r? ````@GuillaumeGomez```` do you know how I could get the keyword links to work?
2022-02-21Correctly handle miniz_oxide extern crate declarationGuillaume Gomez-0/+1
2022-02-20use `BOOL` for `TCP_NODELAY` `setsockopt` value on WindowsChris Copeland-2/+2
This issue was found by the Wine project and mitigated there [1]. Windows' documented interface for `setsockopt` expects a `BOOL` (a `typedef` for `int`) for `TCP_NODELAY` [2]. Windows is forgiving and will accept any positive length and interpret the first byte of `*option_value` as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's `setsockopt`, where, e.g., Linux requires that `option_len` be correct for the chosen option, and `TCP_NODELAY` expects an `int`. [1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-02-20Remove assertion on output length for `getsockopt`.Chris Copeland-1/+0
POSIX allows `getsockopt` to set `*option_len` to a smaller value if necessary. Windows will set `*option_len` to 1 for boolean options even when the caller passes a `BOOL` (`int`) with `*option_len` as 4.
2022-02-20Fix `setsockopt` and `getsockopt` parameter names.Chris Copeland-9/+25
Previously `level` was named `opt` and `option_name` was named `val`, then extra names of `payload` or `slot` were used for the option value. This change aligns the wrapper parameters with their names in POSIX. Winsock uses similar but more abbreviated names: `level`, `optname`, `optval`, `optlen`.
2022-02-20solarish current_exe using libc call directlyDavid Carlier-4/+1
2022-02-20Rollup merge of #94122 - GuillaumeGomez:miniz-oxide-std, r=notriddleMatthias Krüger-0/+4
Fix miniz_oxide types showing up in std docs Fixes #90526. Thanks to ```````@camelid,``````` I rediscovered `doc(masked)`, allowing us to prevent `miniz_oxide` type to show up in std docs. r? ```````@notriddle```````
2022-02-20Rollup merge of #94019 - hermitcore:target, r=Mark-SimulacrumMatthias Krüger-1/+1
removing architecture requirements for RustyHermit RustHermit and HermitCore is able to run on aarch64 and x86_64. In the future these operating systems will also support RISC-V. Consequently, the dependency to a specific target should be removed. The build process of `hermit-abi` fails if the architecture isn't supported.
2022-02-20Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcmMatthias Krüger-1/+0
Stabilize pin_static_ref. FCP finished here: https://github.com/rust-lang/rust/issues/78186#issuecomment-1024987221 Closes #78186
2022-02-19Some improvements to the async docsr00ster91-6/+8
2022-02-19Auto merge of #94148 - matthiaskrgr:rollup-jgea68f, r=matthiaskrgrbors-21/+39
Rollup of 7 pull requests Successful merges: - #92902 (Improve the documentation of drain members) - #93658 (Stabilize `#[cfg(panic = "...")]`) - #93954 (rustdoc-json: buffer output) - #93979 (Add debug assertions to validate NUL terminator in c strings) - #93990 (pre #89862 cleanup) - #94006 (Use a `Field` in `ConstraintCategory::ClosureUpvar`) - #94086 (Fix ScalarInt to char conversion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-02-19Rollup merge of #93979 - SUPERCILEX:debug_check, r=dtolnayMatthias Krüger-20/+29
Add debug assertions to validate NUL terminator in c strings The `unchecked` variants from the stdlib usually perform the check anyway if debug assertions are on (for example, `unwrap_unchecked`). This PR does the same thing for `CStr` and `CString`, validating the correctness for the NUL byte in debug mode.
2022-02-19Rollup merge of #92902 - ssomers:docter_drain, r=yaahcMatthias Krüger-1/+10
Improve the documentation of drain members hopefully fixes #92765
2022-02-19Auto merge of #94105 - 5225225:destabilise-entry-insert, r=Mark-Simulacrumbors-2/+4
Destabilise entry_insert See: https://github.com/rust-lang/rust/pull/90345 I didn't revert the rename that was done in that PR, I left it as `entry_insert`. Additionally, before that PR, `VacantEntry::insert_entry` seemingly had no stability attribute on it? I kept the attribute, just made it an unstable one, same as the one on `Entry`. There didn't seem to be any mention of this in the RELEASES.md, so I don't think there's anything for me to do other than this?
2022-02-19Collections: improve the documentation of drain membersStein Somers-1/+10
2022-02-18Rollup merge of #93847 - solid-rs:fix-kmc-solid-fs-ts, r=yaahcMatthias Krüger-1/+20
kmc-solid: Use the filesystem thread-safety wrapper Fixes the thread unsafety of the `std::fs` implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. Neither the SOLID filesystem API nor built-in filesystem drivers guarantee thread safety by default. Although this may suffice in general embedded-system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`. This commit updates the implementation to leverage the filesystem thread-safety wrapper (which uses a pluggable synchronization mechanism) to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.)
2022-02-18Fix miniz_oxide types showing up in stdGuillaume Gomez-0/+4