Repository navigation
Big endian support - minor adjustments - #147
Merged
Merged
Conversation
The Serialize/Deserialize impls for bit_vec::BitVec and bit_set::BitSet (both the 0.6/0.5 and the 0.8 versions) copy the u32 storage words of the bit vector to and from the stream as raw memory, which only yields the little-endian savefile format on little-endian hosts. Instead of handling that case the crate refused to build on big-endian targets with a compile_error!, so every dependent crate using the default feature set failed to compile there (seen with FreeBSD/powerpc64). Keep the raw memory copy on little-endian hosts. On big-endian hosts, write the storage words through write_u32 and convert them with u32::from_le after the bulk read. The on-disk format is unchanged: a big-endian build now produces byte-identical output to a little-endian one for both bit-vec and both bit-set versions, and round-trips it (verified on FreeBSD powerpc64 against powerpc64le).
get_variant_offsets conjures a value of each variant by writing the discriminant into the first bytes of a zeroed buffer, byte by byte in little-endian order. On a big-endian host that produces an invalid tag for u16/u32 discriminants (e.g. 0x01000000 for variant 1), so the derive's const evaluation of repr_c_optimization_safe fails to compile for every #[repr(u16)]/#[repr(u32)] enum with fields: error[E0080]: enum value has invalid tag: 0x01000000 Write the discriminant with to_ne_bytes instead, which is const and yields the host's own byte order on either endianness.
The Packed optimization copies the in-memory representation of a type
straight to and from the stream, which equals the little-endian savefile
format only on little-endian hosts (the Packed docs already list "The
host platform is little endian" as a precondition). Nothing enforces
that: the primitive impls answer IsPacked::yes() unconditionally, and
the derive macro writes every run of address-contiguous primitive
fields with raw_write_region() while the generated Deserialize impl
reads them back field by field as little-endian. On a big-endian host
data is silently corrupted on round-trip: a struct { a: f64, b: f64 }
written and read on the same machine returns byte-swapped values, and
20 tests of savefile-test fail that way.
Make IsPacked::yes() yield "no" on big-endian targets, so every fast
path keyed off repr_c_optimization_safe (Vec<T>, arrays, derived types,
manual Packed impls) falls back to the per-field little-endian code, and
gate the derive's contiguous-field raw_write_region() on little-endian
as well, since that one only checks field adjacency. The output of a
big-endian build then becomes byte-identical to a little-endian one.
The compile-time #[savefile_require_fast] layout check only inspects
field offsets and is unaffected.
avl
enabled auto-merge (squash)
October 19, 2026 21:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.