From dbf29d2964e496d9c33ca134b40f736cf4e4dc8f Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Sat, 2 Dec 2017 10:00:48 +0100 Subject: [PATCH] fix build on BE and 32bit Signed-off-by: Igor Gnatenko --- ...-more-robust-on-various-architecture.patch | 156 ++++++++++++++++++ rust-scroll.spec | 2 + 2 files changed, 158 insertions(+) create mode 100644 0001-build-make-tests-more-robust-on-various-architecture.patch diff --git a/0001-build-make-tests-more-robust-on-various-architecture.patch b/0001-build-make-tests-more-robust-on-various-architecture.patch new file mode 100644 index 0000000..51ef644 --- /dev/null +++ b/0001-build-make-tests-more-robust-on-various-architecture.patch @@ -0,0 +1,156 @@ +From 39e05345064ec1783f58a14ce896d521ef3cfc3a Mon Sep 17 00:00:00 2001 +From: m4b +Date: Sat, 2 Dec 2017 00:56:46 -0800 +Subject: [PATCH] build: make tests more robust on various architectures for + smaller pointers + different endianness. ref #20 + +--- + src/greater.rs | 10 +++++----- + src/lesser.rs | 6 +++--- + src/lib.rs | 5 ++++- + tests/api.rs | 12 ++++++------ + 4 files changed, 18 insertions(+), 15 deletions(-) + +diff --git a/src/greater.rs b/src/greater.rs +index 99560b1..cffdbbf 100644 +--- a/src/greater.rs ++++ b/src/greater.rs +@@ -60,7 +60,7 @@ pub trait Cread : Index + Index> + /// use scroll::Cread; + /// + /// let bytes = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,]; +- /// let foo = bytes.cread::(0); ++ /// let foo = bytes.cread::(0); + /// let bar = bytes.cread::(8); + /// assert_eq!(foo, 1); + /// assert_eq!(bar, 0xbeef); +@@ -108,9 +108,9 @@ pub trait Cwrite: Index + IndexMut> { + /// ``` + /// use scroll::{Cwrite, Cread}; + /// let mut bytes = [0x0; 0x10]; +- /// bytes.cwrite::(42, 0); ++ /// bytes.cwrite::(42, 0); + /// bytes.cwrite::(0xdeadbeef, 8); +- /// assert_eq!(bytes.cread::(0), 42); ++ /// assert_eq!(bytes.cread::(0), 42); + /// assert_eq!(bytes.cread::(8), 0xdeadbeef); + #[inline] + fn cwrite>>::Output>>(&mut self, n: N, offset: I) where Ctx: Default { +@@ -124,9 +124,9 @@ pub trait Cwrite: Index + IndexMut> { + /// ``` + /// use scroll::{Cwrite, Cread, LE, BE}; + /// let mut bytes = [0x0; 0x10]; +- /// bytes.cwrite_with::(42, 0, LE); ++ /// bytes.cwrite_with::(42, 0, LE); + /// bytes.cwrite_with::(0xdeadbeef, 8, BE); +- /// assert_eq!(bytes.cread::(0), 42); ++ /// assert_eq!(bytes.cread::(0), 42); + /// assert_eq!(bytes.cread::(8), 0xefbeadde); + #[inline] + fn cwrite_with>>::Output>>(&mut self, n: N, offset: I, ctx: Ctx) { +diff --git a/src/lesser.rs b/src/lesser.rs +index 1258216..a26042a 100644 +--- a/src/lesser.rs ++++ b/src/lesser.rs +@@ -15,13 +15,13 @@ use ctx::{FromCtx, IntoCtx, SizeWith}; + /// + /// #[repr(packed)] + /// struct Foo { +-/// foo: usize, ++/// foo: i64, + /// bar: u32, + /// } + /// + /// impl ctx::FromCtx for Foo { + /// fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self { +-/// Foo { foo: bytes.pread_with::(0, ctx).unwrap(), bar: bytes.pread_with::(8, ctx).unwrap() } ++/// Foo { foo: bytes.pread_with::(0, ctx).unwrap(), bar: bytes.pread_with::(8, ctx).unwrap() } + /// } + /// } + /// +@@ -35,7 +35,7 @@ use ctx::{FromCtx, IntoCtx, SizeWith}; + /// + /// let bytes_ = [0x0b,0x0b,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,]; + /// let mut bytes = Cursor::new(bytes_); +-/// let foo = bytes.ioread::().unwrap(); ++/// let foo = bytes.ioread::().unwrap(); + /// let bar = bytes.ioread::().unwrap(); + /// assert_eq!(foo, 0xb0b); + /// assert_eq!(bar, 0xbeef); +diff --git a/src/lib.rs b/src/lib.rs +index 2f9ecda..4311485 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -78,7 +78,7 @@ + //! let mut bytes = Cursor::new(bytes_); + //! + //! // this will bump the cursor's Seek +-//! let foo = bytes.ioread::().unwrap(); ++//! let foo = bytes.ioread::().unwrap(); + //! // ..ditto + //! let bar = bytes.ioread::().unwrap(); + //! ``` +@@ -222,7 +222,10 @@ mod tests { + let bytes: [u8; 2] = [0x7e, 0xef]; + let b = &bytes[..]; + let byte: u16 = b.pread(0).unwrap(); ++ #[cfg(target_endian = "little")] + assert_eq!(0xef7e, byte); ++ #[cfg(target_endian = "big")] ++ assert_eq!(0x7eef, byte); + } + + #[test] +diff --git a/tests/api.rs b/tests/api.rs +index e3d8574..942d5af 100644 +--- a/tests/api.rs ++++ b/tests/api.rs +@@ -171,13 +171,13 @@ fn lifetime_passthrough() { + #[derive(Default)] + #[repr(packed)] + struct Foo { +- foo: usize, ++ foo: i64, + bar: u32, + } + + impl scroll::ctx::FromCtx for Foo { + fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self { +- Foo { foo: bytes.cread_with::(0, ctx), bar: bytes.cread_with::(8, ctx) } ++ Foo { foo: bytes.cread_with::(0, ctx), bar: bytes.cread_with::(8, ctx) } + } + } + +@@ -194,7 +194,7 @@ fn ioread_api() { + use scroll::IOread; + let bytes_ = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,]; + let mut bytes = Cursor::new(bytes_); +- let foo = bytes.ioread::().unwrap(); ++ let foo = bytes.ioread::().unwrap(); + let bar = bytes.ioread::().unwrap(); + assert_eq!(foo, 1); + assert_eq!(bar, 0xbeef); +@@ -223,7 +223,7 @@ impl scroll::ctx::FromCtx for Bar { + fn cread_api() { + use scroll::Cread; + let bytes = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,]; +- let foo = bytes.cread::(0); ++ let foo = bytes.cread::(0); + let bar = bytes.cread::(8); + assert_eq!(foo, 1); + assert_eq!(bar, 0xbeef); +@@ -251,9 +251,9 @@ fn cwrite_api() { + use scroll::Cwrite; + use scroll::Cread; + let mut bytes = [0x0; 0x10]; +- bytes.cwrite::(42, 0); ++ bytes.cwrite::(42, 0); + bytes.cwrite::(0xdeadbeef, 8); +- assert_eq!(bytes.cread::(0), 42); ++ assert_eq!(bytes.cread::(0), 42); + assert_eq!(bytes.cread::(8), 0xdeadbeef); + } + +-- +2.15.1 + diff --git a/rust-scroll.spec b/rust-scroll.spec index addd648..effb31f 100644 --- a/rust-scroll.spec +++ b/rust-scroll.spec @@ -15,6 +15,8 @@ Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{ # Initial patched metadata # * Bump rayon to 0.9, https://github.com/m4b/scroll/commit/2b8ec1ccbf64fc0fa09cced9e9590186bc0c059e Patch0: scroll-0.7.0-fix-metadata.diff +# https://github.com/m4b/scroll/commit/39e05345064ec1783f58a14ce896d521ef3cfc3a +Patch1: 0001-build-make-tests-more-robust-on-various-architecture.patch ExclusiveArch: %{rust_arches}