Patchwork D10351: unit-tests: Fix `cargo test` on 32-bit platforms

login
register
mail settings
Submitter phabricator
Date April 9, 2021, 10:08 a.m.
Message ID <differential-rev-PHID-DREV-a47q7dafmnvkhqrxq2md-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48668/
State Superseded
Headers show

Comments

phabricator - April 9, 2021, 10:08 a.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Fixes https://bz.mercurial-scm.org/show_bug.cgi?id=6506
  
  This makes `IndexEntryBuilder::build`, which is only used in unit tests, use
  `u32` or `u64` instead of platform-dependent `usize` when packing binary data
  to be used at test input.
  
  To run Rust unit tests in 32-bit mode in a x86-64 environment, use:
  
    rustup target add i686-unknown-linux-gnu  # Once
    (cd rust && cargo test --target i686-unknown-linux-gnu)

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10351

AFFECTED FILES
  rust/hg-core/src/revlog/index.rs

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog/index.rs b/rust/hg-core/src/revlog/index.rs
--- a/rust/hg-core/src/revlog/index.rs
+++ b/rust/hg-core/src/revlog/index.rs
@@ -300,12 +300,12 @@ 
                 // Remaining offset bytes.
                 bytes.extend(&[0u8; 2]);
             } else {
-                // Offset is only 6 bytes will usize is 8.
-                bytes.extend(&self.offset.to_be_bytes()[2..]);
+                // Offset stored on 48 bits (6 bytes)
+                bytes.extend(&(self.offset as u64).to_be_bytes()[2..]);
             }
             bytes.extend(&[0u8; 2]); // Revision flags.
-            bytes.extend(&self.compressed_len.to_be_bytes()[4..]);
-            bytes.extend(&self.uncompressed_len.to_be_bytes()[4..]);
+            bytes.extend(&(self.compressed_len as u32).to_be_bytes());
+            bytes.extend(&(self.uncompressed_len as u32).to_be_bytes());
             bytes.extend(&self.base_revision.to_be_bytes());
             bytes
         }