Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change WASI's RawFd from u32 to c_int (i32). #88012

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

sunfishcode
Copy link
Member

WASI previously used u32 as its RawFd type, since its "file descriptors"
are unsigned table indices, and there's no fundamental reason why WASI can't
have more than 2^31 handles.

However, this creates myriad little incompability problems with code
that also supports Unix platforms, where RawFd is c_int. While WASI
isn't a Unix, it often shares code with Unix, and this difference made
such shared code inconvenient. #87329 is the most recent example of such
code.

So, switch WASI to use c_int, which is i32. This will mean that code
intending to support WASI should ideally avoid assuming that negative file
descriptors are invalid, even though POSIX itself says that file descriptors
are never negative.

This is a breaking change, but RawFd is considerd an experimental
feature in the documentation.

r? @alexcrichton

WASI previously used `u32` as its `RawFd` type, since its "file descriptors"
are unsigned table indices, and there's no fundamental reason why WASI can't
have more than 2^31 handles.

However, this creates myriad little incompability problems with code
that also supports Unix platforms, where `RawFd` is `c_int`. While WASI
isn't a Unix, it often shares code with Unix, and this difference made
such shared code inconvenient. rust-lang#87329 is the most recent example of such
code.

So, switch WASI to use `c_int`, which is `i32`. This will mean that code
intending to support WASI should ideally avoid assuming that negative file
descriptors are invalid, even though POSIX itself says that file descriptors
are never negative.

This is a breaking change, but `RawFd` is considerd an experimental
feature in [the documentation].

[the documentation]: https://doc.rust-lang.org/stable/std/os/wasi/io/type.RawFd.html
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2021
@sunfishcode sunfishcode mentioned this pull request Aug 13, 2021
@alexcrichton
Copy link
Member

@bors: r+

Seems reasonable to me! And yeah the intention is that std::os::wasi is unstable still so I'm hopeful that this shouldn't break too many users in the wild.

@bors
Copy link
Contributor

bors commented Aug 16, 2021

📌 Commit 35de5c9 has been approved by alexcrichton

@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 Aug 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2021
…laumeGomez

Rollup of 10 pull requests

Successful merges:

 - rust-lang#87818 (Fix anchors display in rustdoc)
 - rust-lang#87983 (Use more accurate spans when proposing adding lifetime to item)
 - rust-lang#88012 (Change WASI's `RawFd` from `u32` to `c_int` (`i32`).)
 - rust-lang#88031 (Make `BuildHasher` object safe)
 - rust-lang#88036 (Fix dead code warning when inline const is used in pattern)
 - rust-lang#88082 (Take into account jobs number for rustdoc GUI tests)
 - rust-lang#88109 (Fix environment variable getter docs)
 - rust-lang#88111 (Add background-color on clickable definitions in source code)
 - rust-lang#88129 (Fix dataflow graphviz bug, make dataflow graphviz modules public)
 - rust-lang#88136 (Move private_unused.rs test to impl-trait)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 627bc60 into rust-lang:master Aug 19, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 19, 2021
@sunfishcode sunfishcode deleted the sunfishcode/wasi-raw-fd-c-int branch August 19, 2021 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants