Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rand = { version = "0.7", optional = true, default-features = false }
rustc-hex = { version = "2.0", optional = true, default-features = false }
quickcheck = { version = "0.9", optional = true }
byteorder = { version = "1.2", optional = true, default-features = false }
static_assertions = "0.3"
static_assertions = "1.0.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm afraid this is technically a breaking change, since we pub use static_assertions;, but this is unlikely to be a problem in practice.


[dev-dependencies]
rand_xorshift = "0.2.0"
Expand Down
1 change: 0 additions & 1 deletion fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ macro_rules! impl_ops_for_hash {
macro_rules! impl_fixed_hash_conversions {
($large_ty:ident, $small_ty:ident) => {
$crate::static_assertions::const_assert!(
VALID_SIZES;
$crate::core_::mem::size_of::<$small_ty>() < $crate::core_::mem::size_of::<$large_ty>()
);

Expand Down
1 change: 1 addition & 0 deletions uint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ byteorder = { version = "1", default-features = false }
rustc-hex = { version = "2.0", default-features = false }
quickcheck = { version = "0.6", optional = true }
crunchy = { version = "0.2", default-features = true }
static_assertions = "1.0.0"

[features]
default = ["std"]
Expand Down
3 changes: 3 additions & 0 deletions uint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub extern crate rustc_hex;
#[doc(hidden)]
pub extern crate quickcheck;

#[doc(hidden)]
pub extern crate static_assertions;

extern crate crunchy;
pub use crunchy::unroll;

Expand Down
18 changes: 8 additions & 10 deletions uint/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,34 @@ macro_rules! impl_try_from_for_primitive {
#[doc(hidden)]
macro_rules! uint_overflowing_binop {
($name:ident, $n_words: tt, $self_expr: expr, $other: expr, $fn:expr) => ({
use $crate::{core_ as core};
let $name(ref me) = $self_expr;
let $name(ref you) = $other;

let mut ret = unsafe { $crate::core_::mem::uninitialized() };
let mut ret = [0u64; $n_words];
let ret_ptr = &mut ret as *mut [u64; $n_words] as *mut u64;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let ret_ptr = &mut ret as *mut [u64; $n_words] as *mut u64;
let ret_ptr = ret.as_mut_ptr();

let mut carry = 0u64;
$crate::static_assertions::const_assert!(core::isize::MAX as usize / core::mem::size_of::<u64>() > $n_words);

@niklasad1 niklasad1 Oct 15, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

BTW, is isize::MAX used because of offset?


unroll! {
for i in 0..$n_words {
use $crate::core_::ptr;
use core::ptr;

if carry != 0 {
let (res1, overflow1) = ($fn)(me[i], you[i]);
let (res2, overflow2) = ($fn)(res1, carry);

unsafe {
ptr::write(
ret_ptr.offset(i as _),
res2
);
// SAFETY: `i` is within bounds and `i * size_of::<u64>() < isize::MAX`
*ret_ptr.offset(i as _) = res2
}
carry = (overflow1 as u8 + overflow2 as u8) as u64;
} else {
let (res, overflow) = ($fn)(me[i], you[i]);

unsafe {
ptr::write(
ret_ptr.offset(i as _),
res
);
// SAFETY: `i` is within bounds and `i * size_of::<u64>() < isize::MAX`
*ret_ptr.offset(i as _) = res
}

carry = overflow as u64;
Expand Down