src/lib: Convert libc::rlim_t to u64#6
Merged
NikVolf merged 1 commit intoparitytech:masterfrom Oct 1, 2020
Merged
Conversation
Previously a27a68d wrongly assumed `libc::rlim_t` to be a `u64` on all platforms. Instead the following is the case: - x86_64-unknown-linux-gnu: u64 - x86_64-apple-darwin: u64 - i686-unknown-linux-musl: u64 - i686-unknown-linux-gnu: u32 - ... There are different options in order to compile on all platforms: - Return `usize`. While `usize` would work for most platforms, `i686-unknown-linux-musl` is an exception. Thus casting would be needed which introduces yet another way to panic. In addition `usize` should be used to index into collections, not so much to represent actual data. - Return `libc::rlim_t`. This type is not present on all platforms. In addition exposing a `libc` type in the public interface unnecessarily ties us to `libc`. - Return `u32`. Would require a fallible cast on all `u64` platforms. - Return `u64`. Supported on all platforms. It is not the most space efficient option. Given that memory efficiency (`u32` vs `u64`) is irrelevant in this context, compared to the involved system calls, this commit converts the limit to `u64` before returning for all platforms.
Contributor
Author
|
Tested on the following platforms. Let me know in case I am missing one. ➜ fdlimit git:(convert-to-u64) cargo build --target x86_64-unknown-linux-gnu
Compiling libc v0.2.76
Compiling fdlimit v0.2.0 (/home/mxinden/code/github.com/paritytech/fdlimit)
Finished dev [unoptimized + debuginfo] target(s) in 0.73s
➜ fdlimit git:(convert-to-u64) cargo build --target x86_64-apple-darwin
Compiling fdlimit v0.2.0 (/home/mxinden/code/github.com/paritytech/fdlimit)
Finished dev [unoptimized + debuginfo] target(s) in 0.43s
➜ fdlimit git:(convert-to-u64) cargo build --target i686-unknown-linux-musl
Compiling fdlimit v0.2.0 (/home/mxinden/code/github.com/paritytech/fdlimit)
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
➜ fdlimit git:(convert-to-u64) cargo build --target i686-unknown-linux-gnu
Compiling fdlimit v0.2.0 (/home/mxinden/code/github.com/paritytech/fdlimit)
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
➜ fdlimit git:(convert-to-u64) cargo build --target armv7-unknown-linux-gnueabihf
Finished dev [unoptimized + debuginfo] target(s) in 0.01s |
|
Oh, it's really weird that it's not even consistent across 32-bit targets ... |
Contributor
Author
|
@NikVolf could you give this a review? |
NikVolf
approved these changes
Oct 1, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously a27a68d wrongly assumed
libc::rlim_tto be au64on allplatforms. Instead the following is the case:
There are different options in order to compile on all platforms:
Return
usize. Whileusizewould work for most platforms,i686-unknown-linux-muslis an exception. Thus casting would be neededwhich introduces yet another way to panic. In addition
usizeshould beused to index into collections, not so much to represent actual data.
Return
libc::rlim_t. This type is not present on all platforms. Inaddition exposing a
libctype in the public interface unnecessarilyties us to
libc.Return
u32. Would require a fallible cast on allu64platforms.Return
u64. Supported on all platforms. It is not the most spaceefficient option.
Given that memory efficiency (
u32vsu64) is irrelevant in thiscontext, compared to the involved system calls, this commit converts the
limit to
u64before returning for all platforms.Fixes #5.