-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change TIO* constants to c_ulong, as ioctl() requires c_ulong #704
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
Conversation
This for example fixes code like: https://github.com/a8m/pb/blob/master/src/tty/unix.rs#L22 where we would need an "as c_ulong" otherwise.
Unfortunately this is a breaking change for now so I'll tag this as 1.0 cleanup |
The problem is that for some operating systems these constants are already defined in (rusty) libc as I assume a 1.0 release is light years away. Having things broken on BSDs is bad IMHO (it frustrates me to spend so much time fixing things like that :(). Can we at least introduce a |
Oh I agree it's frustrating! On the other hand though this is a breaking change. I hope that 1.0 is not lightyears away, though. Hopefully just on the order of months. |
@alexcrichton: Thanks! I understand it's a breaking change, but I'd argue that it's currently broken on these platforms as dependent crates won't currently build on Free- and DragonFly BSD. A few months I can wait :) |
This is a temporary fix to: rust-lang/libc#704 and closes: murarth#12
This is a temporary fix to: rust-lang/libc#704
It's not a breaking change if it only affects code that doesn't compile as-is. Can we please have this pre-1.0, unless somebody's aware of code that is using the incorrect types yet somehow actually works? |
@asomers code which works around these being the wrong types will break if this lands, and it's definitely possible to write working code today that breaks if these types change |
@asomers @alexcrichton I think code that works around this will do an "as u32" cast or an "into()", so whatever type libc exports, it will not break anything. |
This breaks code like |
@alexcrichton : Correct, that would break this code. But, that code would be broken anyway, as |
Sorry but we're just not accepting breaking changes right now, if and when 1.0 happens we can change this but until that time FreeBSD is a "high enough tier" that we don't accept breakage for it. |
Speaking as a FreeBSD committer, the potential breakage that would be caused by merging this PR is less bad than the actual breakage that is caused by not merging it. This bug breaks a lot of crates that were originally developed on Linux when they try to go to FreeBSD. |
If a crater-like run could be performed showing that this doesn't have any practical breakage in the ecosystem on FreeBSD then I think we would be able to make this change, but without that knowledge we simply cannot make breaking changes blindly |
Would it be sufficient to patch libc with this merged and then run Crater in check-only mode targeting FreeBSD? Or is more than that needed? |
I believe so yeah, but I don't think there's a lot of precedent for doing this on non-Linux platforms |
After migrating from ioctl-rs to libc for `ioctl()` calls, compilation fails on FreeBSD and DragonFlyBSD with type errors because some TIO* constants are defined as `c_uint` when `ioctl()` expects the `request` parameter to be `c_ulong`. Fixing the types in libc is considered a breaking change, so probably won't happen until the next major version bump [1]. A reasonable work-around is to cast the constants to the expected type with `into()`: ioctl(fd, TIOCEXCL.into()) This allows the constants to be used similarly to how one would use a `#define` in C, by letting the compiler convert the constant to the appropriate type [2]. Since Rust is more strict about numerical type conversions, this requires an explicit call to `into()`, which invokes type inference to work out the final type and avoids the need to name types explicitly (such as `TIOCEXCL as c_ulong`). Thus, this is portable across platforms with different types for the `request` parameter of `ioctl()`. This also won't break when libc changes the declared type for TIO* constants to the correct type. [1] rust-lang/libc#704 [2] Only lossless conversions (from smaller to larger type) implement `From` and `Into`. If TIO* constants were defined with a larger type than what `ioctl()` expects, then this would not compile.
@mneumann could you rebase this on top of master ? While this only affects FreeBSD, the APIs it touches are not super rare. I'd like to merge this tentatively and do a release that only contains this change, and then, update libc in rust-lang/rust with this change. If nobody complains for a reasonable amount of time, we can assume that this did not broke anybody. Otherwise, we'll have to yank that libc release, and revert this change from master, but we can hopefully do that during the nightly cycle as usual. |
@gnzlbg isn't this what crater is for? |
@asomers crater can check whether a rust-lang/rust PR breaks something, so when we upgrade libc in rust-lang/rust, we could do a crater run to check that. However, AFAIK, crater cannot be used yet to check whether a PR to a crate on crates.io would break its dependencies. IIRC, using the bundled libc actually requires a nightly feature ( |
☔ The latest upstream changes (presumably #1587) made this pull request unmergeable. Please resolve the merge conflicts. |
This for example fixes code like:
https://github.com/a8m/pb/blob/master/src/tty/unix.rs#L22
where we would need an "as c_ulong" otherwise.