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

std: Deprecate all std::os::*::raw types #31551

Merged
merged 1 commit into from
Feb 14, 2016

Conversation

alexcrichton
Copy link
Member

This commit is an implementation of RFC 1415 which deprecates all types
in the std::os::*::raw modules.

Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of stat on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in std::os::*::raw are billed as "compatible with C", which
in light of this means it isn't really possible.

To make matters worse, platforms like Android sometimes define these types as
smaller than the way they're actually represented in the stat structure
itself. This means that when methods like DirEntry::ino are called on Android
the result may be truncated as we're tied to returning a ino_t type, not the
underlying type.

The commit here incorporates two backwards-compatible components:

  • Deprecate all raw types that aren't in std::os::raw
  • Expand the std::os::*::fs::MetadataExt trait on all platforms for method
    accessors of all fields. The fields now returned widened types which are the
    same across platforms (consistency across platforms is not required, however,
    it's just convenient).

and two also backwards-incompatible components:

  • Change the definition of all std::os::*::raw type aliases to
    correspond to the newly widened types that are being returned on each
    platform.
  • Change the definition of std::os::*::raw::stat on Linux to match the LFS
    definitions rather than the standard ones.

The breaking changes here will specifically break code that assumes that libc
and std agree on the definition of std::os::*::raw types, or that the std
types are faithful representations of the types in C. An audit has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.


Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using stat64 and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!

Closes #28978
Closes #30050
Closes #31549

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@cuviper
Copy link
Member

cuviper commented Feb 11, 2016

we can open >4GB files

Yay! Although the limit was actually 2GB, since off_t was i32.

This highlights to me that you've made the "universal" type off_t = u64, changing the sign -- is that just so MetadataExt::size() -> u64 can still be assigned to a deprecated off_t?

@alexcrichton
Copy link
Member Author

@cuviper oh wow, even better than I thought!

The change for off_t was primarily done for the std::os::unix::fs::MetadataExt trait. Today it returns off_t, and code which looks like:

fn foo(amt: off_t) { ... }

foo(metadata.size());

would break otherwise. We in theory want to return u64 from the size method (both there and across all platforms), so the trait is indeed changing to return u64 and to prevent some breakage the type definition is changing as well.

Does that makes sense? I tried to word the deprecation message to indicate "these type definitions are known to not be correct" to ensure that this was conveyed.

@cuviper
Copy link
Member

cuviper commented Feb 11, 2016

Right, your explanation is basically what I suspected. Makes sense.

My only concern would be if someone also tried to use negative off_t for something, like posix's common -1 for error/invalid results. That may be more subtle - do you think your audit would have revealed this?

@alexcrichton
Copy link
Member Author

I think it would have, yeah. I found only a very few locations that use std::os::unix::raw at all, and anything I did find was just a intermediate cast or something that goes directly to a u64 anyway. We'll always have a window during nightly/beta, however, to weed out any other possible breakage, and we'll still have a chance to revert this if it comes to that.

@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Feb 11, 2016
@cuviper
Copy link
Member

cuviper commented Feb 11, 2016

OK. The easy fallback in this case is just i64, which ought to suffice since the platform itself does have to support signed offsets, conflated with file sizes.

@brson
Copy link
Contributor

brson commented Feb 11, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Feb 11, 2016

📌 Commit 9de5ff3 has been approved by brson

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⌛ Testing commit 9de5ff3 with merge d8c3443...

@bors
Copy link
Contributor

bors commented Feb 13, 2016

💔 Test failed - auto-linux-32-opt

@alexcrichton
Copy link
Member Author

@bors: r=brson 3a35cbb

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⌛ Testing commit 3a35cbb with merge 4906b4c...

@bors
Copy link
Contributor

bors commented Feb 13, 2016

💔 Test failed - auto-mac-64-opt

@alexcrichton
Copy link
Member Author

@bors: r=brson 2991b04

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⌛ Testing commit 2991b04 with merge 564ac80...

@bors
Copy link
Contributor

bors commented Feb 13, 2016

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: r=brson ede1e29

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⌛ Testing commit ede1e29 with merge 2905cd9...

@bors
Copy link
Contributor

bors commented Feb 13, 2016

💔 Test failed - auto-mac-ios-opt

This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md

Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.

To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.

The commit here incorporates two backwards-compatible components:

* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
  accessors of all fields. The fields now returned widened types which are the
  same across platforms (consistency across platforms is not required, however,
  it's just convenient).

and two also backwards-incompatible components:

* Change the definition of all `std::os::*::raw` type aliases to
  correspond to the newly widened types that are being returned on each
  platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
  definitions rather than the standard ones.

The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.

[audit]: rust-lang/rfcs#1415 (comment)

---

Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!

Closes rust-lang#28978
Closes rust-lang#30050
Closes rust-lang#31549
@alexcrichton
Copy link
Member Author

@bors: r=brson aa23c98

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⌛ Testing commit aa23c98 with merge 7589f86...

@bors
Copy link
Contributor

bors commented Feb 13, 2016

⛄ The build was interrupted to prioritize another pull request.

@bors
Copy link
Contributor

bors commented Feb 14, 2016

⌛ Testing commit aa23c98 with merge 09395bb...

bors added a commit that referenced this pull request Feb 14, 2016
This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md

Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.

To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.

The commit here incorporates two backwards-compatible components:

* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
  accessors of all fields. The fields now returned widened types which are the
  same across platforms (consistency across platforms is not required, however,
  it's just convenient).

and two also backwards-incompatible components:

* Change the definition of all `std::os::*::raw` type aliases to
  correspond to the newly widened types that are being returned on each
  platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
  definitions rather than the standard ones.

The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.

[audit]: rust-lang/rfcs#1415 (comment)

---

Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!

Closes #28978
Closes #30050
Closes #31549
@bors bors merged commit aa23c98 into rust-lang:master Feb 14, 2016
@alexcrichton alexcrichton deleted the deprecate-std-os-raw branch February 15, 2016 19:05
bors added a commit that referenced this pull request Feb 15, 2016
bors added a commit that referenced this pull request Feb 15, 2016
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 16, 2016
This follows the pattern already used for stat functions from rust-lang#31551.  Now
`ftruncate`, `lseek`, and `readdir_r` use their explicit 64-bit variants for
LFS support, using wider `off_t` and `dirent` types.  This also updates to
`open64`, which uses no different types but implies the `O_LARGEFILE` flag.

Non-Linux platforms just map their normal functions to the 64-bit names.

r? @alexcrichton
bors added a commit that referenced this pull request Feb 16, 2016
This follows the pattern already used for stat functions from #31551.  Now
`ftruncate`, `lseek`, and `readdir_r` use their explicit 64-bit variants for
LFS support, using wider `off_t` and `dirent` types.  This also updates to
`open64`, which uses no different types but implies the `O_LARGEFILE` flag.

Non-Linux platforms just map their normal functions to the 64-bit names.

r? @alexcrichton
ogham added a commit to ogham/exa that referenced this pull request Apr 16, 2016
Fixes #108. MetadataExt now returns direct numeric types rather than platform-specific ones, so we need to adjust the functions that use these to have the new types. I've just aliased the types to specific ones so the rest of the code remains the same (file.rs is the only place that uses this)

The RFC that changed this is here: rust-lang/rust#31551
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
5 participants