std: merge the unix-like io::error modules into one file#158870
Conversation
|
|
|
|
||
| #[cfg(target_os = "teeos")] | ||
| pub fn errno() -> i32 { | ||
| unsafe { (*libc::__errno_location()) as i32 } |
There was a problem hiding this comment.
I think it'd be good to use the extern "C" redefinition of __errno_location for TEEOS as well; that way it'll benefit from the #[ffi_const] annotation.
| #[cfg(target_os = "wasi")] | ||
| pub fn error_string(errno: i32) -> String { | ||
| let mut buf = [0 as libc::c_char; 1024]; | ||
|
|
||
| let p = buf.as_mut_ptr(); | ||
| unsafe { | ||
| if libc::strerror_r(errno as libc::c_int, p, buf.len()) < 0 { | ||
| panic!("strerror_r failure"); | ||
| } | ||
| str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned() | ||
| } | ||
| } |
There was a problem hiding this comment.
I'd merge this with the UNIX implementation. Keeping the larger buffer size for WASI seems less risky to me, perhaps there's a good reason for it being larger? Not sure...
There was a problem hiding this comment.
Merged, kept the 1024 buffer for them.
I couldn't find the reason in the history either. But bigger is probably safer, will truncate longer messages.
The merge also switches wasi from unwrap to from_utf8_lossy.
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
| #[cfg(any(target_family = "unix", target_os = "teeos"))] | ||
| unsafe extern "C" { | ||
| #[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems")))] |
There was a problem hiding this comment.
I'd just add WASI to these exceptions.
| #[cfg(any(target_family = "unix", target_os = "teeos"))] | |
| unsafe extern "C" { | |
| #[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems")))] | |
| unsafe extern "C" { | |
| #[cfg(not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems", target_os = "wasi")))] |
| @@ -1,6 +1,9 @@ | |||
| use crate::ffi::{CStr, c_char, c_int}; | |||
| use crate::ffi::c_int; | |||
| #[cfg(any(target_family = "unix", target_os = "wasi"))] | |||
There was a problem hiding this comment.
| #[cfg(any(target_family = "unix", target_os = "wasi"))] | |
| #[cfg(not(target_os = "teeos"))] |
| #[cfg(all( | ||
| any(target_family = "unix", target_os = "teeos"), | ||
| not(any(target_os = "dragonfly", target_os = "vxworks", target_os = "rtems")) | ||
| ))] |
There was a problem hiding this comment.
Likewise...
| #[cfg(any(target_family = "unix", target_os = "wasi"))] | ||
| pub fn error_string(errno: i32) -> String { | ||
| const TMPBUF_SZ: usize = 128; | ||
| const TMPBUF_SZ: usize = 1024; |
There was a problem hiding this comment.
I'd keep the 128-byte buffer for UNIX – some smaller UNIXes are very mindful about stack usage. Try using cfg! perhaps.
| #[cfg(all( | ||
| target_family = "unix", | ||
| not(target_os = "dragonfly"), | ||
| not(target_os = "vxworks"), | ||
| not(target_os = "rtems") | ||
| ))] |
There was a problem hiding this comment.
It's fine to leave this unused on TEEOS...
| #[cfg(all( | |
| target_family = "unix", | |
| not(target_os = "dragonfly"), | |
| not(target_os = "vxworks"), | |
| not(target_os = "rtems") | |
| ))] | |
| #[cfg(not(any( | |
| target_os = "dragonfly", | |
| target_os = "vxworks", | |
| target_os = "rtems", | |
| target_os = "wasi", | |
| )))] |
There was a problem hiding this comment.
Thanks for you guidance on this, applied your suggestions.
Sorry that haven't noticed it in first attempts.
cf885f7 to
7b789b7
Compare
This comment has been minimized.
This comment has been minimized.
The POSIX-like `decode_error_kind` copies under `sys/io/error/` (unix, wasi, teeos) had drifted apart, each missing different arms. Fold wasi and teeos into unix: `decode_error_kind` and `is_interrupted` are shared, while `errno`, `set_errno`, `error_string`, and the `errno_location` extern stay per-target behind `cfg`, expressed as exceptions to the unix/wasi/teeos set rather than enumerating the matching targets, matching the platform `cfg_attr`s the file already had. teeos now goes through the shared `errno_location` extern instead of calling `libc::__errno_location()` directly, so it gets the same `#[ffi_const]` annotation as the other targets. `error_string` is shared between unix and wasi, with the buffer sized per target: 128 bytes on unix, where some targets are mindful of stack usage, and 1024 on wasi. The shared decode table is unix's existing one, so wasi picks up `ENOTEMPTY` -> `DirectoryNotEmpty` and teeos picks up `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported`, all previously `Uncategorized` on those targets. No test: with one shared `decode_error_kind` the copies can't drift again, and no test asserts the errno to `ErrorKind` mappings today.
7b789b7 to
865fb57
Compare
Sure, squashed it, the commit body is pretty detailed after squash, so if you would prefer to make it more concise, please let me know. |
|
No, that's fine. Though I should point out that the merge commit will include the PR description anyway, so commit messages don't need to be that detailed... @bors r+ |
…file, r=joboet std: merge the unix-like io::error modules into one file `library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (rust-lang#158490). Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three. The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing: - wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`). - teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`). All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`. No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests) Addresses rust-lang#158490 r? @joboet
Rollup of 25 pull requests Successful merges: - #158871 (add relnotes for 1.97.0) - #158968 (stdarch subtree update) - #157690 (codegen_ssa: pack small const aggregates into immediate stores) - #158541 (Move `std::io::Write` to `core::io`) - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently) - #156370 (Reject linked dylib EII default overrides) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158655 (Fix coroutine MIR saved local remapping) - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`) - #158870 (std: merge the unix-like io::error modules into one file) - #158920 (Update wasm-component-ld to 0.5.26) - #158926 (wrapping_sh* methods: clarify underspecified reference) - #158927 (add core test run with `-Zforce-intrinsic-fallback`) - #158932 (Do not build the compiler when invoking `x perf compare`) - #158937 (Emit the emscripten entry point as `__main_argc_argv`) - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`) - #156144 (Better docs for PartialEq (includes macro rename)) - #156548 ( Library support for aarch64-unknown-linux-pauthtest target) - #158307 (CI job for parallel frontend ui tests) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158741 (Simplify `Option::into_flat_iter` signature)
…file, r=joboet std: merge the unix-like io::error modules into one file `library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (rust-lang#158490). Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three. The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing: - wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`). - teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`). All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`. No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests) Addresses rust-lang#158490 r? @joboet
Rollup of 23 pull requests Successful merges: - #158968 (stdarch subtree update) - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently) - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS) - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`) - #158870 (std: merge the unix-like io::error modules into one file) - #158920 (Update wasm-component-ld to 0.5.26) - #158926 (wrapping_sh* methods: clarify underspecified reference) - #158927 (add core test run with `-Zforce-intrinsic-fallback`) - #158932 (Do not build the compiler when invoking `x perf compare`) - #158937 (Emit the emscripten entry point as `__main_argc_argv`) - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`) - #156144 (Better docs for PartialEq (includes macro rename)) - #156548 ( Library support for aarch64-unknown-linux-pauthtest target) - #157995 (`Vec::dedup_by` docs explicit function argument order) - #158307 (CI job for parallel frontend ui tests) - #158741 (Simplify `Option::into_flat_iter` signature) - #158807 (Add regression test for CString::clone_into unwind safety) - #158862 (Fix the span for parameter suggestion ) - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic) - #158902 (add codegen test for range length bound propagation) - #158913 (Update `browser-ui-test` version to `0.24.1`) - #158935 (std: support real fd methods on Emscripten) - #158978 (Add regression test for too-big by-value ABI args)
Rollup merge of #158870 - valentynkit:posix-io-error-single-file, r=joboet std: merge the unix-like io::error modules into one file `library/std/src/sys/io/error/` had a separate `decode_error_kind` (errno -> `io::ErrorKind`) for each POSIX-like target: `unix.rs`, `wasi.rs`, and `teeos.rs`. The three were near-identical hand copies and had drifted apart, each in its own way (#158490). Per the discussion there, this folds `wasi.rs` and `teeos.rs` into `unix.rs`. `decode_error_kind` and `is_interrupted` are now shared; `errno`, `set_errno`, and `error_string` stay per-target behind `cfg`, next to the target-specific cases the file already had. A new mapping is written once and applies to all three. The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing: - wasi now maps `ENOTEMPTY` -> `DirectoryNotEmpty` (was `Uncategorized`). - teeos now maps `EINPROGRESS` -> `InProgress`, `EMFILE`/`ENFILE` -> `TooManyOpenFiles`, and `EOPNOTSUPP` -> `Unsupported` (were `Uncategorized`). All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's `EWOULDBLOCK` arm becomes the `x == EAGAIN || x == EWOULDBLOCK` guard the other two already use; that is a no-op on wasi, where `EWOULDBLOCK == EAGAIN`. No test: with one shared `decode_error_kind` the copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests) Addresses #158490 r? @joboet
Rollup of 23 pull requests Successful merges: - rust-lang/rust#158968 (stdarch subtree update) - rust-lang/rust#154445 (rustdoc: Represent `--output-format=json` coverage and ir differently) - rust-lang/rust#158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS) - rust-lang/rust#158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`) - rust-lang/rust#158870 (std: merge the unix-like io::error modules into one file) - rust-lang/rust#158920 (Update wasm-component-ld to 0.5.26) - rust-lang/rust#158926 (wrapping_sh* methods: clarify underspecified reference) - rust-lang/rust#158927 (add core test run with `-Zforce-intrinsic-fallback`) - rust-lang/rust#158932 (Do not build the compiler when invoking `x perf compare`) - rust-lang/rust#158937 (Emit the emscripten entry point as `__main_argc_argv`) - rust-lang/rust#151379 (Stabilize `VecDeque::retain_back` from `truncate_front`) - rust-lang/rust#156144 (Better docs for PartialEq (includes macro rename)) - rust-lang/rust#156548 ( Library support for aarch64-unknown-linux-pauthtest target) - rust-lang/rust#157995 (`Vec::dedup_by` docs explicit function argument order) - rust-lang/rust#158307 (CI job for parallel frontend ui tests) - rust-lang/rust#158741 (Simplify `Option::into_flat_iter` signature) - rust-lang/rust#158807 (Add regression test for CString::clone_into unwind safety) - rust-lang/rust#158862 (Fix the span for parameter suggestion ) - rust-lang/rust#158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic) - rust-lang/rust#158902 (add codegen test for range length bound propagation) - rust-lang/rust#158913 (Update `browser-ui-test` version to `0.24.1`) - rust-lang/rust#158935 (std: support real fd methods on Emscripten) - rust-lang/rust#158978 (Add regression test for too-big by-value ABI args)
library/std/src/sys/io/error/had a separatedecode_error_kind(errno ->io::ErrorKind) for each POSIX-like target:unix.rs,wasi.rs, andteeos.rs. The three were near-identical hand copies and had drifted apart, each in its own way (#158490).Per the discussion there, this folds
wasi.rsandteeos.rsintounix.rs.decode_error_kindandis_interruptedare now shared;errno,set_errno, anderror_stringstay per-target behindcfg, next to the target-specific cases the file already had. A new mapping is written once and applies to all three.The shared table is unix's existing one, so the merge also picks up the arms wasi and teeos were missing:
ENOTEMPTY->DirectoryNotEmpty(wasUncategorized).EINPROGRESS->InProgress,EMFILE/ENFILE->TooManyOpenFiles, andEOPNOTSUPP->Unsupported(wereUncategorized).All of those errnos are defined on the respective targets in libc, so the arms compile everywhere the file does. wasi's
EWOULDBLOCKarm becomes thex == EAGAIN || x == EWOULDBLOCKguard the other two already use; that is a no-op on wasi, whereEWOULDBLOCK == EAGAIN.No test: with one shared
decode_error_kindthe copies can't drift again, and the decode arms are not tested today. (Let me know if it worth covering with tests)Addresses #158490
r? @joboet