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

Allow compilation on 32 bit architectures #213

Conversation

nashley
Copy link
Contributor

@nashley nashley commented Feb 11, 2021

Don't assume that usize is equivalant to a u64

@nashley nashley requested a review from a team as a code owner February 11, 2021 05:32
@nashley
Copy link
Contributor Author

nashley commented Feb 11, 2021

I think I followed the contribution guidelines, but please let me know if this is missing anything!

@nashley nashley force-pushed the allow-compilation-on-32-bit-architectures branch 2 times, most recently from b257d4f to b3e690a Compare February 17, 2021 02:56
@nashley
Copy link
Contributor Author

nashley commented Feb 17, 2021

rust-lang/rust#70460 would allow this to be done more cleanly than only allowing compilation on platforms where we know the try_from won't fail.

src/wire_msg.rs Outdated
{
compile_error!("You need an architecture capable of addressing 32 bit pointers");
}
let mut data: Vec<u8> = vec![0; usize::try_from(msg_header.data_len()).unwrap()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid using .unwrap() wherever we can to prevent panics.

Copy link
Contributor Author

@nashley nashley Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!
This should be an infallible operation on 32 and 64 bit platforms, which the preceding lines should ensure. The only built-in compile-time alternative I know of is to wait on rust-lang/rust#70460, but if you know of another way, I'd love to hear it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, nice one. Where the type is a result then ? is OK here.
Where we see a result we always use it or pass an error back (or resolve the error).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added in a runtime check as well. Do we want to keep both the compile-time check and the (theoretically unreachable) runtime check?

@nashley nashley force-pushed the allow-compilation-on-32-bit-architectures branch from 2eb41f6 to 1352568 Compare February 27, 2021 01:11
src/wire_msg.rs Outdated Show resolved Hide resolved
@nashley nashley marked this pull request as draft February 27, 2021 01:25
@nashley nashley force-pushed the allow-compilation-on-32-bit-architectures branch 2 times, most recently from 2790662 to 2cce2eb Compare February 27, 2021 02:37
@nashley nashley marked this pull request as ready for review February 27, 2021 02:37
@nashley nashley force-pushed the allow-compilation-on-32-bit-architectures branch from 2cce2eb to ca9b97d Compare March 7, 2021 14:19
@loziniak
Copy link

I'd love this to be merged.

@lionel-faber
Copy link
Contributor

Thanks for the poke @loziniak

@nashley could you give this a quick rebase. We can get this in.

- Don't assume that usize is equivalant to a u64
- Require 32-bit or 64-bit architecture at compile time

BREAKING CHANGE: this changes the data_len field in MsgHeader from usize
to u32
@lionel-faber lionel-faber force-pushed the allow-compilation-on-32-bit-architectures branch from ca9b97d to 67ab0a2 Compare March 25, 2021 06:21
@lionel-faber
Copy link
Contributor

I've rebased this and updated the commit message mentioning BREAKING CHANGE so that the next auto-deployed release is bumped up a minor version. Thanks for this @nashley 🎉

@lionel-faber lionel-faber merged commit 7c39399 into maidsafe:master Mar 25, 2021
@nashley nashley deleted the allow-compilation-on-32-bit-architectures branch March 26, 2021 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants