From 99692a888827c1ed1cbe91a4594cdf5c388c2279 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Mar 09 2018 07:45:54 +0000 Subject: fix build on 32bit systems Signed-off-by: Igor Gnatenko --- diff --git a/0001-Fix-read_u64-for-32-bit-platforms.patch b/0001-Fix-read_u64-for-32-bit-platforms.patch new file mode 100644 index 0000000..6ee9aa0 --- /dev/null +++ b/0001-Fix-read_u64-for-32-bit-platforms.patch @@ -0,0 +1,50 @@ +From f578b5f3761f56cb5c5d74ae476006341a5c33c8 Mon Sep 17 00:00:00 2001 +From: Diggory Hardy +Date: Sat, 25 Nov 2017 17:38:40 +0000 +Subject: [PATCH] Fix read_u64 for 32-bit platforms + +(Why you can't rely on .to_le() being correct I don't understand. If compiler +is mixed-endian then to_le ought still do the correct swaps.) +--- + seahash/src/buffer.rs | 4 ++-- + seahash/src/helper.rs | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/seahash/src/buffer.rs b/seahash/src/buffer.rs +index 573273d..eb2193c 100644 +--- a/seahash/src/buffer.rs ++++ b/seahash/src/buffer.rs +@@ -63,7 +63,7 @@ impl State { + + // Calculate the number of excessive bytes. These are bytes that could not be handled in + // the loop above. +- let mut excessive = buf.len() as usize + buf.as_ptr() as usize - end_ptr as usize; ++ let mut excessive = buf.len() % 32; + // Handle the excessive bytes. + match excessive { + 0 => {}, +@@ -71,7 +71,7 @@ impl State { + // 1 or more excessive. + + // Write the last excessive bytes (<8 bytes). +- a ^= helper::read_int(slice::from_raw_parts(ptr as *const u8, excessive)); ++ a ^= helper::read_int(slice::from_raw_parts(ptr, excessive)); + + // Diffuse. + a = helper::diffuse(a); +diff --git a/seahash/src/helper.rs b/seahash/src/helper.rs +index a95b89c..d3be89a 100644 +--- a/seahash/src/helper.rs ++++ b/seahash/src/helper.rs +@@ -60,7 +60,7 @@ pub unsafe fn read_u64(ptr: *const u8) -> u64 { + { + // We cannot be sure about the memory layout of a potentially emulated 64-bit integer, so + // we read it manually. If possible, the compiler should emit proper instructions. +- (*(ptr as *const u32)).to_le() as u64 | ((*(ptr as *const u32)).to_le() as u64) << 32 ++ (*(ptr as *const u32)).to_le() as u64 | ((*(ptr as *const u32).offset(1)).to_le() as u64) << 32 + } + + #[cfg(target_pointer_width = "64")] +-- +2.16.2 + diff --git a/rust-seahash.spec b/rust-seahash.spec index 73b722f..2d00ade 100644 --- a/rust-seahash.spec +++ b/rust-seahash.spec @@ -13,6 +13,8 @@ Summary: Blazingly fast, portable hash function with proven statistical g License: MIT URL: https://crates.io/crates/seahash Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate +# https://github.com/redox-os/tfs/pull/74 +Patch0001: 0001-Fix-read_u64-for-32-bit-platforms.patch ExclusiveArch: %{rust_arches} @@ -32,7 +34,7 @@ This package contains library source intended for building other packages which use %{crate} from crates.io. %prep -%autosetup -n %{crate}-%{version} -p1 +%autosetup -n %{crate}-%{version} -p2 %cargo_prep %build