about summary refs log tree commit diff
path: root/library/std/src/sys_common
AgeCommit message (Collapse)AuthorLines
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-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-5/+5
2022-02-02Configure panic hook backtrace behaviorMark Rousskov-57/+0
2022-01-25Avoid double panics when using `TempDir` in testsChris Denton-1/+7
2022-01-17Help optimize out backtraces when disabledKornel-7/+18
2022-01-01Auto merge of #92396 - xfix:remove-commandenv-apply, r=Mark-Simulacrumbors-16/+0
Remove CommandEnv::apply It's not being used and uses unsound set_var and remove_var functions. This is an internal function that isn't exported (even with `process_internals` feature), so this shouldn't break anything. Also see #92365. Note that this isn't the only use of those methods in standard library, so that particular pull request will need more changes than just this to work (in particular, `test_capture_env_at_spawn` is using `set_var` and `remove_var`).
2021-12-29Remove CommandEnv::applyKonrad Borowski-16/+0
It's not being used and uses unsound set_var and remove_var functions.
2021-12-29Address commentsXuanwo-4/+4
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28Implement support in wtf8Xuanwo-0/+37
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-14Fix a bunch of typosFrank Steffahn-3/+3
2021-11-21libcore: assume the input of `next_code_point` and `next_code_point_reverse` ↵Eduardo Sánchez Muñoz-1/+2
is UTF-8-like The functions are now `unsafe` and they use `Option::unwrap_unchecked` instead of `unwrap_or_0` `unwrap_or_0` was added in 42357d772b8a3a1ce4395deeac0a5cf1f66e951d. I guess `unwrap_unchecked` was not available back then. Given this example: ```rust pub fn first_char(s: &str) -> Option<char> { s.chars().next() } ``` Previously, the following assembly was produced: ```asm _ZN7example10first_char17ha056ddea6bafad1cE: .cfi_startproc test rsi, rsi je .LBB0_1 movzx edx, byte ptr [rdi] test dl, dl js .LBB0_3 mov eax, edx ret .LBB0_1: mov eax, 1114112 ret .LBB0_3: lea r8, [rdi + rsi] xor eax, eax mov r9, r8 cmp rsi, 1 je .LBB0_5 movzx eax, byte ptr [rdi + 1] add rdi, 2 and eax, 63 mov r9, rdi .LBB0_5: mov ecx, edx and ecx, 31 cmp dl, -33 jbe .LBB0_6 cmp r9, r8 je .LBB0_9 movzx esi, byte ptr [r9] add r9, 1 and esi, 63 shl eax, 6 or eax, esi cmp dl, -16 jb .LBB0_12 .LBB0_13: cmp r9, r8 je .LBB0_14 movzx edx, byte ptr [r9] and edx, 63 jmp .LBB0_16 .LBB0_6: shl ecx, 6 or eax, ecx ret .LBB0_9: xor esi, esi mov r9, r8 shl eax, 6 or eax, esi cmp dl, -16 jae .LBB0_13 .LBB0_12: shl ecx, 12 or eax, ecx ret .LBB0_14: xor edx, edx .LBB0_16: and ecx, 7 shl ecx, 18 shl eax, 6 or eax, ecx or eax, edx ret ``` After this change, the assembly is reduced to: ```asm _ZN7example10first_char17h4318683472f884ccE: .cfi_startproc test rsi, rsi je .LBB0_1 movzx ecx, byte ptr [rdi] test cl, cl js .LBB0_3 mov eax, ecx ret .LBB0_1: mov eax, 1114112 ret .LBB0_3: mov eax, ecx and eax, 31 movzx esi, byte ptr [rdi + 1] and esi, 63 cmp cl, -33 jbe .LBB0_4 movzx edx, byte ptr [rdi + 2] shl esi, 6 and edx, 63 or edx, esi cmp cl, -16 jb .LBB0_7 movzx ecx, byte ptr [rdi + 3] and eax, 7 shl eax, 18 shl edx, 6 and ecx, 63 or ecx, edx or eax, ecx ret .LBB0_4: shl eax, 6 or eax, esi ret .LBB0_7: shl eax, 12 or eax, edx ret ```
2021-11-10Use `target_family = "wasm"`Alex Crichton-2/+1
2021-11-10std: Get the standard library compiling for wasm64Alex Crichton-0/+1
This commit goes through and updates various `#[cfg]` as appropriate to get the wasm64-unknown-unknown target behaving similarly to the wasm32-unknown-unknown target. Most of this is just updating various conditions for `target_arch = "wasm32"` to also account for `target_arch = "wasm64"` where appropriate. This commit also lists `wasm64` as an allow-listed architecture to not have the `restricted_std` feature enabled, enabling experimentation with `-Z build-std` externally. The main goal of this commit is to enable playing around with `wasm64-unknown-unknown` externally via `-Z build-std` in a way that's similar to the `wasm32-unknown-unknown` target. These targets are effectively the same and only differ in their pointer size, but wasm64 is much newer and has much less ecosystem/library support so it'll still take time to get wasm64 fully-fledged.
2021-10-30Add #[must_use] to remaining std functions (O-Z)John Kugelman-0/+1
2021-10-22docs: Escape brackets to satisfy the linkcheckerNoah Lev-1/+1
My change to use `Type::def_id()` (formerly `Type::def_id_full()`) in more places caused some docs to show up that used to be missed by rustdoc. Those docs contained unescaped square brackets, which triggered linkcheck errors. This commit escapes the square brackets and adds this particular instance to the linkcheck exception list.
2021-10-11Rollup merge of #89707 - clemenswasser:apply_clippy_suggestions, ↵Matthias Krüger-4/+2
r=Mark-Simulacrum Apply clippy suggestions for std
2021-10-09Apply clippy suggestionsClemens Wasser-4/+2
2021-10-09Rollup merge of #88436 - lf-:stabilize-command-access, r=yaahcGuillaume Gomez-3/+3
std: Stabilize command_access Tracking issue: #44434 (not yet closed but the FCP is done so that should be soon).
2021-10-05Apply suggestions from code reviewJane Lusby-3/+3
2021-09-16Merge two THREAD_INFO.with and following RefCell borrowbjorn3-2/+5
This is a bit faster
2021-09-16Replace a couple of asserts with rtassert! in rt codebjorn3-1/+1
This replaces a couple of panic locations with hard aborts. The panics can't be catched by the user anyway in these locations.
2021-09-16Remove unused functionbjorn3-4/+0
2021-09-16Use const {} for the THREAD_INFO thread localbjorn3-1/+2
This makes accesses to it cheaper
2021-09-16Optimize ThreadInfo::withbjorn3-6/+7
The RefCell is now borrowed exactly once. In addition a code sequence that contains an unwrap that is guaranteed to never panic at runtime is replaced with get_or_insert_with, which makes the intended behavior clearer and will not emit code to panic even without optimizations.
2021-09-16Merge sys_common::rt into rtbjorn3-83/+0
2021-08-30add `TcpStream::set_linger` and `TcpStream::linger`ibraheemdev-0/+8
2021-08-28std: Stabilize command_accessJade-3/+3
Tracking issue: #44434
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-22Fix more “a”/“an” typosFrank Steffahn-2/+2
2021-08-19I/O safety.Dan Gohman-24/+18
Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: - <https://github.com/rust-lang/rust/issues/87074> RFC: - <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>
2021-08-12Auto merge of #87963 - GuillaumeGomez:rollup-e54sbez, r=GuillaumeGomezbors-4/+6
Rollup of 4 pull requests Successful merges: - #87819 (Use a more accurate span on assoc types WF checks) - #87863 (Fix Windows Command::env("PATH")) - #87885 (Link to edition guide instead of issues for 2021 lints.) - #87941 (Fix/improve rustdoc-js tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-08-10STD support for the ESP-IDF frameworkivmarkov-1/+3
2021-08-08Fix Windows Command::env("PATH")Chris Denton-4/+6
2021-08-02Rollup merge of #86509 - CDirkx:os_str, r=m-ou-seYuki Okushi-268/+0
Move `os_str_bytes` to `sys::unix` Followup to #84967, with `OsStrExt` and `OsStringExt` moved out of `sys_common`, there is no reason anymore for `os_str_bytes` to live in `sys_common` and not in sys. This pr moves it to the location `sys::unix::os_str` and reuses the code on other platforms via `#[path]` (as is common in `sys`) instead of importing.
2021-07-29[backtraces]: look for the `begin` symbol only after seeing `end`Wesley Wiser-1/+1
On `x86_64-pc-windows-msvc`, we often get backtraces which look like this: ``` 10: 0x7ff77e0e9be5 - std::panicking::rust_panic_with_hook 11: 0x7ff77e0e11b4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c 12: 0x7ff77e0e116f - std::sys_common::backtrace::__rust_end_short_backtrace::h61c7ecb1b55338ae 13: 0x7ff77e0f89dd - std::panicking::begin_panic::h8e60ef9f82a41805 14: 0x7ff77e0e108c - d 15: 0x7ff77e0e1069 - c 16: 0x7ff77e0e1059 - b 17: 0x7ff77e0e1049 - a 18: 0x7ff77e0e1039 - core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>::h1bfcd14d5e15ba81 19: 0x7ff77e0e1186 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c 20: 0x7ff77e0e100c - std::rt::lang_start::{{closure}}::ha054184bbf9921e3 ``` Notice that `__rust_begin_short_backtrace` appears on frame 11 before `__rust_end_short_backtrace` on frame 12. This is because in typical release binaries without debug symbols, dbghelp.dll, which we use to walk and symbolize the stack, does not know where CGU internal functions start or end and so the closure invoked by `__rust_end_short_backtrace` is incorrectly described as `__rust_begin_short_backtrace` because it happens to be near that symbol. While that can obviously change, this has been happening quite consistently since #75048. Since this is a very small change to the std and the change makes sense by itself, I think this is worth doing. This doesn't completely resolve the situation for release binaries on Windows, since without debug symbols, the stack printed can still show incorrect symbol names (this is why the test uses `#[no_mangle]`) but it does slightly improve the situation in that you see the same backtrace you would see with `RUST_BACKTRACE=full` or in a debugger (without the uninteresting bits at the top and bottom).
2021-07-03Move `os_str_bytes` to `sys::unix` and reuse it on other platforms.Christiaan Dirkx-268/+0
2021-06-21Merge `sys_common::bytestring` into `os_str_bytes`Christiaan Dirkx-50/+28
2021-06-20Auto merge of #84967 - CDirkx:os_str_ext, r=m-ou-sebors-71/+6
Move `OsStringExt` and `OsStrExt` to `std::os` Moves the `OsStringExt` and `OsStrExt` traits and implementations from `sys_common` to `os`. `sys_common` is for abstractions over `sys` and shouldn't really contain publicly exported items. This does introduce some duplication: the traits and implementations are now duplicated in `unix`, `wasi`, `hermit`, and `sgx`. However, I would argue that this duplication is no different to how something like `MetadataExt` is duplicated in `linux`, `vxworkx`, `redox`, `solaris` etc. The duplication also matches the fact that the traits on different platforms are technically distinct types: any platform is free to add it's own extra methods to the extension trait.
2021-06-20Make `os_str_bytes::{Buf, Slice}` `pub` and `repr(transparent)`Christiaan Dirkx-8/+4
2021-06-20Move `OsStringExt` and `OsStrExt` to `std::os`Christiaan Dirkx-63/+2
2021-06-20Auto merge of #86463 - fee1-dead:fixed-encode_wide, r=m-ou-sebors-1/+14
Account for self.extra in size_hint for EncodeWide Fixes #86414.
2021-06-19Account for self.extra in size_hint for EncodeWideDeadbeef-1/+14
2021-06-18Lint for unused borrows as part of UNUSED_MUST_USEhi-rustin-3/+3
2021-06-01Multiple improvements to RwLocksBenoît du Garreau-37/+83
- Split `sys_common::RWLock` between `StaticRWLock` and `MovableRWLock` - Unbox `RwLock` on some platforms (Windows, Wasm and unsupported) - Simplify `RwLock::into_inner`
2021-05-21Auto merge of #85060 - ChrisDenton:win-file-exists, r=yaahcbors-0/+8
Windows implementation of feature `path_try_exists` Draft of a Windows implementation of `try_exists` (#83186). The first commit reorganizes the code so I would be interested to get some feedback on if this is a good idea or not. It moves the `Path::try_exists` function to `fs::exists`. leaving the former as a wrapper for the latter. This makes it easier to provide platform specific implementations and matches the `fs::metadata` function. The other commit implements a Windows specific variant of `exists`. I'm still figuring out my approach so this is very much a first draft. Eventually this will need some more eyes from knowledgable Windows people.
2021-05-20Rollup merge of #85275 - CDirkx:memchr, r=m-ou-seGuillaume Gomez-0/+138
Move `std::memchr` to `sys_common` `std::memchr` is a thin abstraction over the different `memchr` implementations in `sys`, along with documentation and tests. The module is only used internally by `std`, nothing is exported externally. Code like this is exactly what the `sys_common` module is for, so this PR moves it there.
2021-05-19Move the implementation of `Path::exists` to `sys_common::fs` so platforms ↵Chris Denton-0/+8
can specialize it Windows implementation of `fs::try_exists`
2021-05-19Rename `rterr` to `rtprintpanic`Christiaan Dirkx-2/+6
2021-05-19Replace `sys_common::util::dumb_print` with `rterr!`Christiaan Dirkx-10/+0