-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
FD_ISSET: take a *const fd_set instead of *mut fd_set #1725
Conversation
r? @JohnTitor (rust_highfive has picked a reviewer for you, use r? to override) |
While I was researching my nix PR, I came across this page about the const-ness of that argument. I'm not enough of an OS expert to opine on whether the arguments are convincing, but thought I'd pass along in case it's useful. |
Uhm, it's reasonable indeed but I'd prefer as-is since it may cause some confusion by difference with the original definition. |
By "original definition" do you mean existing versions of libc, or what's documented in C libraries? AFAIK the only place in C that describes the pointer as mutable is in some man pages. But that's a misnomer since the function is really a macro, and its arguments don't have constedness. And some operating systems document |
Fair enough, but on the other hand, it makes the current signature stricter, I think we shouldn't do that without any strong reason or announcement. |
Apparently libc does not object to changing the signatures of other functions, even when that causes downstream breakage. Since that's the case, why not merge this PR? |
☔ The latest upstream changes (presumably #1975) made this pull request unmergeable. Please resolve the merge conflicts. |
Triage: Re-visiting, I still, however, don't see much motivation for this. |
The motivation is const-correctness. Right now for example, Nix forces users to use a mutable reference in a place where an immutable reference should suffice, just because libc defines |
FD_ISSET does not modify its fd_set argument, so it may as well take a const pointer. AFAICT the only reason to take a *mut pointer is because the Linux man page documents it that way (though since glibc implements it as a macro, the constedness is undefined). But since libc implements it directly rather than calling a (nonexistent on most platforms) C function, we're defining the API ourselves.
A |
Thanks for clarifying both! |
@bors r+ |
📌 Commit 3eafb3b has been approved by |
☀️ Test successful - checks-actions, checks-cirrus-freebsd-11, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13 |
There was never any good reason to use mutable receives in the first place. Nix originally did so because libc defined FD_ISSET as taking a mutable receiver, which it did based on an inaccurate Linux man page. But that's fixed now. rust-lang/libc#1725
FD_ISSET does not modify its fd_set argument, so it may as well take a
const pointer. AFAICT the only reason to take a *mut pointer is because
the Linux man page documents it that way (though since glibc implements
it as a macro, the constedness is undefined). But since libc implements
it directly rather than calling a (nonexistent on most platforms) C
function, we're defining the API ourselves.