Skip to content

Conversation

joboet
Copy link
Member

@joboet joboet commented Mar 28, 2025

By marking __errno_location as #[ffi_const] and std::sys::os::errno as #[inline], this PR allows merging multiple calls to io::Error::last_os_error() into one.

By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
@rustbot
Copy link
Collaborator

rustbot commented Mar 28, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2025
@Noratrieb
Copy link
Member

https://github.com/bminor/glibc/blob/b0897944cc3081e019b39981790051f7ee127406/stdlib/errno.h#L37 in glibc, the function is indeed declared const, so this should be correct.
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Mar 29, 2025

📌 Commit dd4f616 has been approved by Noratrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2025
@joboet
Copy link
Member Author

joboet commented Mar 29, 2025

https://github.com/bminor/glibc/blob/b0897944cc3081e019b39981790051f7ee127406/stdlib/errno.h#L37 in glibc, the function is indeed declared const, so this should be correct.

Note that e.g. Apple's libc does not use that attribute. Still, the C standard mandates that errno

expands to a modifiable lvalue that has type int and thread storage duration [emphasis mine]

So a libc that changes the address of errno would be in clear violation of the standard (and would probably encounter errors, e.g. it's perfectly valid in C to take the address of errno and read from the resulting pointer later).

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 29, 2025
std: deduplicate `errno` accesses

By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137928 (stabilize const_cell)
 - rust-lang#138431 (Fix `uclibc` LLVM target triples)
 - rust-lang#138832 (Start using `with_native_path` in `std::sys::fs`)
 - rust-lang#139060 (replace commit placeholder in vendor status with actual commit)
 - rust-lang#139081 (std: deduplicate `errno` accesses)
 - rust-lang#139100 (compiletest: Support matching diagnostics on lines below)
 - rust-lang#139105 (`BackendRepr::is_signed`: comment why this may panics)
 - rust-lang#139106 (Mark .pp files as Rust)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137928 (stabilize const_cell)
 - rust-lang#138431 (Fix `uclibc` LLVM target triples)
 - rust-lang#138832 (Start using `with_native_path` in `std::sys::fs`)
 - rust-lang#139081 (std: deduplicate `errno` accesses)
 - rust-lang#139100 (compiletest: Support matching diagnostics on lines below)
 - rust-lang#139105 (`BackendRepr::is_signed`: comment why this may panics)
 - rust-lang#139106 (Mark .pp files as Rust)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 821e0fe into rust-lang:master Mar 30, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Mar 30, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 30, 2025
Rollup merge of rust-lang#139081 - joboet:errno_dedup, r=Noratrieb

std: deduplicate `errno` accesses

By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 2, 2025
std: deduplicate `errno` accesses

By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 2, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137928 (stabilize const_cell)
 - rust-lang#138431 (Fix `uclibc` LLVM target triples)
 - rust-lang#138832 (Start using `with_native_path` in `std::sys::fs`)
 - rust-lang#139081 (std: deduplicate `errno` accesses)
 - rust-lang#139100 (compiletest: Support matching diagnostics on lines below)
 - rust-lang#139105 (`BackendRepr::is_signed`: comment why this may panics)
 - rust-lang#139106 (Mark .pp files as Rust)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants