dcefa4
--- thunderbird-78.9.0/Cargo.lock.D87019-thin-vec-big-endian.diff	2021-03-22 11:34:35.584716638 +0100
dcefa4
+++ thunderbird-78.9.0/Cargo.lock	2021-03-22 12:29:14.140624979 +0100
dcefa4
@@ -4792,9 +4792,9 @@ checksum = "8eaa81235c7058867fa8c0e7314f
83ba88
 
83ba88
 [[package]]
83ba88
 name = "thin-vec"
dcefa4
-version = "0.1.2"
83ba88
+version = "0.2.1"
83ba88
 source = "registry+https://github.com/rust-lang/crates.io-index"
dcefa4
-checksum = "3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"
83ba88
+checksum = "dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"
83ba88
 
83ba88
 [[package]]
83ba88
 name = "thiserror"
dcefa4
--- thunderbird-78.9.0/gfx/webrender_bindings/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/gfx/webrender_bindings/Cargo.toml	2021-03-22 11:34:35.587716631 +0100
83ba88
@@ -20,7 +20,7 @@ nsstring = { path = "../../xpcom/rust/ns
83ba88
 bincode = "1.0"
83ba88
 uuid = { version = "0.8", features = ["v4"] }
83ba88
 fxhash = "0.2.1"
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 swgl = { path = "../wr/swgl" }
83ba88
 
83ba88
 [dependencies.webrender]
dcefa4
--- thunderbird-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml	2021-03-22 11:34:35.589716625 +0100
83ba88
@@ -10,4 +10,4 @@ fluent-pseudo = "0.2"
83ba88
 intl-memoizer = "0.4"
83ba88
 unic-langid = "0.8"
83ba88
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
dcefa4
--- thunderbird-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml	2021-03-22 11:34:35.590716623 +0100
83ba88
@@ -9,7 +9,7 @@ edition = "2018"
83ba88
 nserror = { path = "../../../../xpcom/rust/nserror" }
83ba88
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
83ba88
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 fluent-langneg = { version = "0.12.1", features = ["cldr"] }
83ba88
 unic-langid = "0.8"
83ba88
 unic-langid-ffi = { path = "../unic-langid-ffi" }
dcefa4
--- thunderbird-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml	2021-03-22 11:34:35.591716620 +0100
83ba88
@@ -9,5 +9,5 @@ edition = "2018"
83ba88
 nserror = { path = "../../../../xpcom/rust/nserror" }
83ba88
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
83ba88
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 unic-langid = { version = "0.8", features = ["likelysubtags"] }
dcefa4
--- thunderbird-78.9.0/netwerk/socket/neqo_glue/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:40.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/netwerk/socket/neqo_glue/Cargo.toml	2021-03-22 11:34:35.600716597 +0100
83ba88
@@ -14,7 +14,7 @@ neqo-common = { tag = "v0.2.4", git = "h
83ba88
 nserror = { path = "../../../xpcom/rust/nserror" }
83ba88
 nsstring = { path = "../../../xpcom/rust/nsstring" }
83ba88
 xpcom = { path = "../../../xpcom/rust/xpcom" }
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 
83ba88
 [dependencies.neqo-crypto]
83ba88
 tag = "v0.2.4"
dcefa4
--- thunderbird-78.9.0/security/manager/ssl/cert_storage/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:52.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/security/manager/ssl/cert_storage/Cargo.toml	2021-03-22 11:34:35.601716594 +0100
83ba88
@@ -18,6 +18,6 @@ rust_cascade = "0.6.0"
83ba88
 sha2 = "^0.8"
83ba88
 storage_variant = { path = "../../../../storage/variant" }
83ba88
 tempfile = "3"
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 time = "0.1"
83ba88
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
dcefa4
--- thunderbird-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:49.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml	2021-03-22 11:34:35.603716589 +0100
83ba88
@@ -20,5 +20,5 @@ nserror = { path = "../../../../xpcom/ru
83ba88
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
83ba88
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
83ba88
 storage_variant = { path = "../../../../storage/variant" }
83ba88
-thin-vec = { version = "0.1", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 fxa-client = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b", features = ["gecko"] }
dcefa4
--- thunderbird-78.9.0/services/sync/golden_gate/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:53.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/services/sync/golden_gate/Cargo.toml	2021-03-22 11:34:35.605716584 +0100
83ba88
@@ -19,5 +19,5 @@ sync15-traits = { git = "https://github.
83ba88
 xpcom = { path = "../../../xpcom/rust/xpcom" }
83ba88
 
83ba88
 [dependencies.thin-vec]
83ba88
-version = "0.1.0"
83ba88
+version = "0.2.1"
83ba88
 features = ["gecko-ffi"]
dcefa4
--- thunderbird-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json.D87019-thin-vec-big-endian.diff	2021-03-22 11:34:35.606716581 +0100
dcefa4
+++ thunderbird-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json	2021-03-22 12:30:38.588587238 +0100
83ba88
@@ -1 +1 @@
dcefa4
-{"files":{"Cargo.toml":"7b164cc8a702a204a4732cb4da2940711b8e3be915c258e2a972d4874d767b4c","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"9f2a087cabfe0b6f83818323bb9004b45fe7548c51376816fd8d4572256bd0e8","src/range.rs":"bac59bcb6230367a39c7e28ac15263e4526f966cd8c72015873017f17c115aaa"},"package":"3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"}
83ba88
\ No newline at end of file
83ba88
+{"files":{"Cargo.toml":"754c05523d17eb7591c3ea2c9294e47c05fbb257fed04b78546fb2ec7cafa8b4","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"627c6094c3f0286dba25bc73f5672c06c5061c25b01c513d213cbdda100673a2"},"package":"dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"}
dcefa4
--- thunderbird-78.9.0/third_party/rust/thin-vec/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/third_party/rust/thin-vec/Cargo.toml	2021-03-22 12:32:38.577621737 +0100
dcefa4
@@ -11,8 +11,9 @@
83ba88
 # will likely look very different (and much more reasonable)
83ba88
 
83ba88
 [package]
83ba88
+edition = "2018"
83ba88
 name = "thin-vec"
dcefa4
-version = "0.1.2"
83ba88
+version = "0.2.1"
83ba88
 authors = ["Alexis Beingessner <a.beingessner@gmail.com>"]
83ba88
 description = "a vec that takes up less space on the stack"
83ba88
 homepage = "https://github.com/gankro/thin-vec"
dcefa4
--- thunderbird-78.9.0/third_party/rust/thin-vec/src/lib.rs.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:28.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/third_party/rust/thin-vec/src/lib.rs	2021-03-22 12:34:10.271595434 +0100
dcefa4
@@ -1,47 +1,252 @@
83ba88
-mod range;
83ba88
+//! ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
83ba88
+//! it allocates.
83ba88
+//!
83ba88
+//! This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
83ba88
+//! a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
83ba88
+//! space. Being pointer-sized also means it can be passed/stored in registers.
83ba88
+//!
83ba88
+//! Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
83ba88
+//! the fuzzy nature of allocators means that might not actually be the case.
83ba88
+//!
83ba88
+//! Properties of Vec that are preserved:
83ba88
+//! * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
83ba88
+//! * reallocation can be done in place
83ba88
+//! * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
83ba88
+//!
83ba88
+//! Properties of Vec that aren't preserved:
83ba88
+//! * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
83ba88
+//! * `from_raw_parts` doesn't exist
83ba88
+//! * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
83ba88
+//!   but it could be done if someone cared enough to implement it.
83ba88
+//!
83ba88
+//!
83ba88
+//!
83ba88
+//! # Gecko FFI
83ba88
+//!
83ba88
+//! If you enable the gecko-ffi feature, ThinVec will verbatim bridge with the nsTArray type in
83ba88
+//! Gecko (Firefox). That is, ThinVec and nsTArray have identical layouts *but not ABIs*, 
83ba88
+//! so nsTArrays/ThinVecs an be natively manipulated by C++ and Rust, and ownership can be 
83ba88
+//! transferred across the FFI boundary (**IF YOU ARE CAREFUL, SEE BELOW!!**).
83ba88
+//!
83ba88
+//! While this feature is handy, it is also inherently dangerous to use because Rust and C++ do not
83ba88
+//! know about eachother. Specifically, this can be an issue with non-POD types (types which
83ba88
+//! have destructors, move constructors, or are `!Copy`).
83ba88
+//!
83ba88
+//! ## Do Not Pass By Value
83ba88
+//!
83ba88
+//! The biggest thing to keep in mind is that **FFI functions cannot pass ThinVec/nsTArray 
83ba88
+//! by-value**. That is, these are busted APIs:
83ba88
+//!
83ba88
+//! ```rust,ignore
83ba88
+//! // BAD WRONG
83ba88
+//! extern fn process_data(data: ThinVec<u32>) { ... }
83ba88
+//! // BAD WRONG
83ba88
+//! extern fn get_data() -> ThinVec<u32> { ... }
83ba88
+//! ```
83ba88
+//!
83ba88
+//! You must instead pass by-reference:
83ba88
+//!
83ba88
+//! ```rust
83ba88
+//! # use thin_vec::*;
83ba88
+//! # use std::mem;
83ba88
+//!
83ba88
+//! // Read-only access, ok!
83ba88
+//! extern fn process_data(data: &ThinVec<u32>) {
83ba88
+//!     for val in data {
83ba88
+//!         println!("{}", val);
83ba88
+//!     }
83ba88
+//! }
83ba88
+//! 
83ba88
+//! // Replace with empty instance to take ownership, ok!
83ba88
+//! extern fn consume_data(data: &mut ThinVec<u32>) {
83ba88
+//!     let owned = mem::replace(data, ThinVec::new());
83ba88
+//!     mem::drop(owned);
83ba88
+//! }
83ba88
+//! 
83ba88
+//! // Mutate input, ok!
83ba88
+//! extern fn add_data(dataset: &mut ThinVec<u32>) {
83ba88
+//!     dataset.push(37);
83ba88
+//!     dataset.push(12);
83ba88
+//! }
83ba88
+//! 
83ba88
+//! // Return via out-param, usually ok!
83ba88
+//! //
83ba88
+//! // WARNING: output must be initialized! (Empty nsTArrays are free, so just do it!)
83ba88
+//! extern fn get_data(output: &mut ThinVec<u32>) {
83ba88
+//!     *output = thin_vec![1, 2, 3, 4, 5];
83ba88
+//! }
83ba88
+//! ```
83ba88
+//!
83ba88
+//! Ignorable Explanation For Those Who Really Want To Know Why:
83ba88
+//!
83ba88
+//! > The fundamental issue is that Rust and C++ can't currently communicate about destructors, and
83ba88
+//! > the semantics of C++ require destructors of function arguments to be run when the function
83ba88
+//! > returns. Whether the callee or caller is responsible for this is also platform-specific, so
83ba88
+//! > trying to hack around it manually would be messy. 
83ba88
+//! >
83ba88
+//! > Also a type having a destructor changes its C++ ABI, because that type must actually exist 
83ba88
+//! > in memory (unlike a trivial struct, which is often passed in registers). We don't currently
83ba88
+//! > have a way to communicate to Rust that this is happening, so even if we worked out the
83ba88
+//! > destructor issue with say, MaybeUninit, it would still be a non-starter without some RFCs
83ba88
+//! > to add explicit rustc support.
83ba88
+//! >
83ba88
+//! > Realistically, the best answer here is to have a "heavier" bindgen that can secretly
83ba88
+//! > generate FFI glue so we can pass things "by value" and have it generate by-reference code
83ba88
+//! > behind our back (like the cxx crate does). This would muddy up debugging/searchfox though.
83ba88
+//!
83ba88
+//! ## Types Should Be Trivially Relocatable
83ba88
+//!
83ba88
+//! Types in Rust are always trivially relocatable (unless suitably borrowed/[pinned][]/hidden).
83ba88
+//! This means all Rust types are legal to relocate with a bitwise copy, you cannot provide
83ba88
+//! copy or move constructors to execute when this happens, and the old location won't have its
83ba88
+//! destructor run. This will cause problems for types which have a significant location
83ba88
+//! (types that intrusively point into themselves or have their location registered with a service).
83ba88
+//!
83ba88
+//! While relocations are generally predictable if you're very careful, **you should avoid using
83ba88
+//! types with significant locations with Rust FFI**.
83ba88
+//!
83ba88
+//! Specifically, ThinVec will trivially relocate its contents whenever it needs to reallocate its
83ba88
+//! buffer to change its capacity. This is the default reallocation strategy for nsTArray, and is
83ba88
+//! suitable for the vast majority of types. Just be aware of this limitation!
83ba88
+//!
83ba88
+//! ## Auto Arrays Are Dangerous
83ba88
+//!
83ba88
+//! ThinVec has *some* support for handling auto arrays which store their buffer on the stack, 
83ba88
+//! but this isn't well tested.
83ba88
+//!
83ba88
+//! Regardless of how much support we provide, Rust won't be aware of the buffer's limited lifetime,
83ba88
+//! so standard auto array safety caveats apply about returning/storing them! ThinVec won't ever
83ba88
+//! produce an auto array on its own, so this is only an issue for transferring an nsTArray into
83ba88
+//! Rust.
83ba88
+//!
83ba88
+//! ## Other Issues
83ba88
+//!
83ba88
+//! Standard FFI caveats also apply: 
83ba88
+//!
83ba88
+//!  * Rust is more strict about POD types being initialized (use MaybeUninit if you must)
83ba88
+//!  * `ThinVec<T>` has no idea if the C++ version of `T` has move/copy/assign/delete overloads
83ba88
+//!  * `nsTArray<T>` has no idea if the Rust version of `T` has a Drop/Clone impl
83ba88
+//!  * C++ can do all sorts of unsound things that Rust can't catch
83ba88
+//!  * C++ and Rust don't agree on how zero-sized/empty types should be handled
83ba88
+//!
83ba88
+//! The gecko-ffi feature will not work if you aren't linking with code that has nsTArray
83ba88
+//! defined. Specifically, we must share the symbol for nsTArray's empty singleton. You will get
83ba88
+//! linking errors if that isn't defined.
83ba88
+//!
83ba88
+//! The gecko-ffi feature also limits ThinVec to the legacy behaviors of nsTArray. Most notably,
83ba88
+//! nsTArray has a maximum capacity of i32::MAX (~2.1 billion items). Probably not an issue.
83ba88
+//! Probably.
83ba88
+//!
83ba88
+//! [pinned]: https://doc.rust-lang.org/std/pin/index.html
83ba88
 
83ba88
 use std::{fmt, io, ptr, mem, slice};
83ba88
 use std::collections::Bound;
83ba88
 use std::iter::FromIterator;
83ba88
 use std::slice::IterMut;
83ba88
-use std::ops::{Deref, DerefMut};
83ba88
+use std::ops::{Deref, DerefMut, RangeBounds};
83ba88
 use std::marker::PhantomData;
dcefa4
 use std::alloc::*;
83ba88
 use std::cmp::*;
83ba88
 use std::hash::*;
83ba88
 use std::borrow::*;
83ba88
-use range::RangeArgument;
83ba88
 use std::ptr::NonNull;
83ba88
 
83ba88
-#[cfg(not(feature = "gecko-ffi"))]
83ba88
-type SizeType = usize;
83ba88
-#[cfg(feature = "gecko-ffi")]
83ba88
-type SizeType = u32;
dcefa4
+use impl_details::*;
dcefa4
 
83ba88
-#[cfg(feature = "gecko-ffi")]
83ba88
-const AUTO_MASK: u32 = 1 << 31;
83ba88
-#[cfg(feature = "gecko-ffi")]
83ba88
-const CAP_MASK: u32 = !AUTO_MASK;
83ba88
+// modules: a simple way to cfg a whole bunch of impl details at once
83ba88
 
83ba88
 #[cfg(not(feature = "gecko-ffi"))]
83ba88
-const MAX_CAP: usize = !0;
83ba88
-#[cfg(feature = "gecko-ffi")]
83ba88
-const MAX_CAP: usize = i32::max_value() as usize;
83ba88
+mod impl_details {
83ba88
+    pub type SizeType = usize;
83ba88
+    pub const MAX_CAP: usize = !0;
83ba88
 
83ba88
-#[cfg(not(feature = "gecko-ffi"))]
83ba88
-#[inline(always)]
83ba88
-fn assert_size(x: usize) -> SizeType { x }
83ba88
+    #[inline(always)]
83ba88
+    pub fn assert_size(x: usize) -> SizeType { x }
83ba88
+}
83ba88
 
83ba88
 #[cfg(feature = "gecko-ffi")]
83ba88
-#[inline]
83ba88
-fn assert_size(x: usize) -> SizeType {
83ba88
-    if x > MAX_CAP as usize {
83ba88
-        panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
83ba88
+mod impl_details {
83ba88
+    // Support for briding a gecko nsTArray verbatim into a ThinVec.
83ba88
+    //
83ba88
+    // ThinVec can't see copy/move/delete implementations
83ba88
+    // from C++
83ba88
+    //
83ba88
+    // The actual layout of an nsTArray is:
83ba88
+    //
83ba88
+    // ```cpp
83ba88
+    // struct {
83ba88
+    //   uint32_t mLength;
83ba88
+    //   uint32_t mCapacity: 31;
83ba88
+    //   uint32_t mIsAutoArray: 1;
83ba88
+    // }
83ba88
+    // ```
83ba88
+    //
83ba88
+    // Rust doesn't natively support bit-fields, so we manually mask
83ba88
+    // and shift the bit. When the "auto" bit is set, the header and buffer
83ba88
+    // are actually on the stack, meaning the ThinVec pointer-to-header
83ba88
+    // is essentially an "owned borrow", and therefore dangerous to handle.
83ba88
+    // There are no safety guards for this situation.
83ba88
+    //
83ba88
+    // On little-endian platforms, the auto bit will be the high-bit of
83ba88
+    // our capacity u32. On big-endian platforms, it will be the low bit.
83ba88
+    // Hence we need some platform-specific CFGs for the necessary masking/shifting.
83ba88
+    // 
83ba88
+    // ThinVec won't ever construct an auto array. They only happen when
83ba88
+    // bridging from C++. This means we don't need to ever set/preserve the bit.
83ba88
+    // We just need to be able to read and handle it if it happens to be there.
83ba88
+    //
83ba88
+    // Handling the auto bit mostly just means not freeing/reallocating the buffer.
83ba88
+
83ba88
+    pub type SizeType = u32;
83ba88
+
83ba88
+    pub const MAX_CAP: usize = i32::max_value() as usize;
83ba88
+
83ba88
+    // Little endian: the auto bit is the high bit, and the capacity is
83ba88
+    // verbatim. So we just need to mask off the high bit. Note that
83ba88
+    // this masking is unnecessary when packing, because assert_size
83ba88
+    // guards against the high bit being set.
83ba88
+    #[cfg(target_endian = "little")]
83ba88
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
83ba88
+        cap as SizeType
83ba88
+    }
83ba88
+    #[cfg(target_endian = "little")]
83ba88
+    pub fn unpack_capacity(cap: SizeType) -> usize {
83ba88
+        (cap as usize) & !(1 << 31)
83ba88
+    }
83ba88
+    #[cfg(target_endian = "little")]
83ba88
+    pub fn is_auto(cap: SizeType) -> bool {
83ba88
+        (cap & (1 << 31)) != 0
83ba88
+    }
83ba88
+
83ba88
+    // Big endian: the auto bit is the low bit, and the capacity is
83ba88
+    // shifted up one bit. Masking out the auto bit is unnecessary,
83ba88
+    // as rust shifts always shift in 0's for unsigned integers.
83ba88
+    #[cfg(target_endian = "big")]
83ba88
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
83ba88
+        (cap as SizeType) << 1
83ba88
+    }
83ba88
+    #[cfg(target_endian = "big")]
83ba88
+    pub fn unpack_capacity(cap: SizeType) -> usize {
83ba88
+        (cap >> 1) as usize
83ba88
+    }
83ba88
+    #[cfg(target_endian = "big")]
83ba88
+    pub fn is_auto(cap: SizeType) -> bool {
83ba88
+        (cap & 1) != 0
dcefa4
     }
dcefa4
-    x as SizeType
83ba88
+
83ba88
+    #[inline]
83ba88
+    pub fn assert_size(x: usize) -> SizeType {
83ba88
+        if x > MAX_CAP as usize {
83ba88
+            panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
83ba88
+        }
83ba88
+        x as SizeType
dcefa4
+    }
83ba88
+
83ba88
 }
83ba88
 
83ba88
-/// The header of a ThinVec
83ba88
+/// The header of a ThinVec.
83ba88
+///
83ba88
+/// The _cap can be a bitfield, so use accessors to avoid trouble.
83ba88
 #[repr(C)]
83ba88
 struct Header {
83ba88
     _len: SizeType,
dcefa4
@@ -53,38 +258,10 @@ impl Header {
83ba88
         self._len as usize
83ba88
     }
83ba88
 
83ba88
-    #[cfg(feature = "gecko-ffi")]
83ba88
-    fn cap(&self) -> usize {
83ba88
-        (self._cap & CAP_MASK) as usize
83ba88
-    }
83ba88
-
83ba88
-    #[cfg(not(feature = "gecko-ffi"))]
83ba88
-    fn cap(&self) -> usize {
83ba88
-        self._cap as usize
83ba88
-    }
83ba88
-
83ba88
     fn set_len(&mut self, len: usize) {
83ba88
         self._len = assert_size(len);
83ba88
     }
83ba88
 
83ba88
-    #[cfg(feature = "gecko-ffi")]
83ba88
-    fn set_cap(&mut self, cap: usize) {
83ba88
-        debug_assert!(cap & (CAP_MASK as usize) == cap);
83ba88
-        // FIXME: this is busted because it reads uninit memory
83ba88
-        // debug_assert!(!self.uses_stack_allocated_buffer());
83ba88
-        self._cap = assert_size(cap) & CAP_MASK;
83ba88
-    }
83ba88
-
83ba88
-    #[cfg(feature = "gecko-ffi")]
83ba88
-    fn uses_stack_allocated_buffer(&self) -> bool {
83ba88
-        self._cap & AUTO_MASK != 0
83ba88
-    }
83ba88
-
83ba88
-    #[cfg(not(feature = "gecko-ffi"))]
83ba88
-    fn set_cap(&mut self, cap: usize) {
83ba88
-        self._cap = assert_size(cap);
83ba88
-    }
83ba88
-
83ba88
     fn data<T>(&self) -> *mut T {
83ba88
         let header_size = mem::size_of::<Header>();
83ba88
         let padding = padding::<T>();
dcefa4
@@ -102,6 +279,41 @@ impl Header {
83ba88
     }
83ba88
 }
83ba88
 
83ba88
+
83ba88
+#[cfg(feature = "gecko-ffi")]
83ba88
+impl Header {
83ba88
+    fn cap(&self) -> usize {
83ba88
+        unpack_capacity(self._cap)
83ba88
+    }
83ba88
+
83ba88
+    fn set_cap(&mut self, cap: usize) {
83ba88
+        // debug check that our packing is working
83ba88
+        debug_assert_eq!(unpack_capacity(pack_capacity(cap as SizeType)), cap);
83ba88
+        // FIXME: this assert is busted because it reads uninit memory
83ba88
+        // debug_assert!(!self.uses_stack_allocated_buffer());
83ba88
+
83ba88
+        // NOTE: this always stores a cleared auto bit, because set_cap
83ba88
+        // is only invoked by Rust, and Rust doesn't create auto arrays.
83ba88
+        self._cap = pack_capacity(assert_size(cap));
83ba88
+    }
83ba88
+
83ba88
+    fn uses_stack_allocated_buffer(&self) -> bool {
83ba88
+        is_auto(self._cap)
83ba88
+    }
83ba88
+}
83ba88
+
83ba88
+#[cfg(not(feature = "gecko-ffi"))]
83ba88
+impl Header {
83ba88
+    fn cap(&self) -> usize {
83ba88
+        self._cap as usize
83ba88
+    }
83ba88
+
83ba88
+    fn set_cap(&mut self, cap: usize) {
83ba88
+        self._cap = assert_size(cap);
83ba88
+    }
83ba88
+}
83ba88
+
83ba88
+
83ba88
 /// Singleton that all empty collections share.
83ba88
 /// Note: can't store non-zero ZSTs, we allocate in that case. We could
83ba88
 /// optimize everything to not do that (basically, make ptr == len and branch
dcefa4
@@ -118,9 +330,7 @@ extern {
83ba88
 
83ba88
 // TODO: overflow checks everywhere
83ba88
 
83ba88
-// Utils
83ba88
-
83ba88
-fn oom() -> ! { std::process::abort() }
83ba88
+// Utils for computing layouts of allocations
83ba88
 
83ba88
 fn alloc_size<T>(cap: usize) -> usize {
83ba88
     // Compute "real" header size with pointer math
dcefa4
@@ -165,9 +375,10 @@ fn layout<T>(cap: usize) -> Layout {
dcefa4
 fn header_with_capacity<T>(cap: usize) -> NonNull<Header> {
dcefa4
     debug_assert!(cap > 0);
83ba88
     unsafe {
dcefa4
-        let header = alloc(layout::<T>(cap)) as *mut Header;
83ba88
+        let layout = layout::<T>(cap);
83ba88
+        let header = alloc(layout) as *mut Header;
dcefa4
 
dcefa4
-        if header.is_null() { oom() }
83ba88
+        if header.is_null() { handle_alloc_error(layout) }
83ba88
 
83ba88
         // "Infinite" capacity for zero-sized types:
83ba88
         (*header).set_cap(if mem::size_of::<T>() == 0 { MAX_CAP } else { cap });
dcefa4
@@ -179,28 +390,8 @@ fn header_with_capacity<T>(cap: usize) -
83ba88
 
83ba88
 
83ba88
 
83ba88
-/// ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
83ba88
-/// it allocates.
83ba88
-///
83ba88
-/// This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
83ba88
-/// a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
83ba88
-/// space. Being pointer-sized also means it can be passed/stored in registers.
83ba88
-///
83ba88
-/// Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
83ba88
-/// the fuzzy nature of allocators means that might not actually be the case.
83ba88
-///
83ba88
-/// Properties of Vec that are preserved:
83ba88
-/// * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
83ba88
-/// * reallocation can be done in place
83ba88
-/// * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
83ba88
-///   * NOTE: This is only possible when the `unstable` feature is used.
83ba88
-///
83ba88
-/// Properties of Vec that aren't preserved:
83ba88
-/// * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
83ba88
-/// * `from_raw_parts` doesn't exist
83ba88
-/// * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
83ba88
-///   but it could be done if someone cared enough to implement it.
83ba88
-#[cfg_attr(feature = "gecko-ffi", repr(C))]
83ba88
+/// See the crate's top level documentation for a description of this type.
83ba88
+#[repr(C)]
83ba88
 pub struct ThinVec<T> {
83ba88
     ptr: NonNull<Header>,
83ba88
     boo: PhantomData<T>,
dcefa4
@@ -630,15 +821,15 @@ impl<T> ThinVec<T> {
83ba88
     }
83ba88
 
83ba88
     pub fn drain<R>(&mut self, range: R) -> Drain<T>
83ba88
-        where R: RangeArgument<usize>
83ba88
+        where R: RangeBounds<usize>
83ba88
     {
83ba88
         let len = self.len();
83ba88
-        let start = match range.start() {
83ba88
+        let start = match range.start_bound() {
83ba88
             Bound::Included(&n) => n,
83ba88
             Bound::Excluded(&n) => n + 1,
83ba88
             Bound::Unbounded => 0,
83ba88
         };
83ba88
-        let end = match range.end() {
83ba88
+        let end = match range.end_bound() {
83ba88
             Bound::Included(&n) => n + 1,
83ba88
             Bound::Excluded(&n) => n,
83ba88
             Bound::Unbounded => len,
dcefa4
@@ -688,11 +879,30 @@ impl<T> ThinVec<T> {
dcefa4
                 alloc_size::<T>(new_cap),
dcefa4
             ) as *mut Header;
83ba88
 
83ba88
-            if ptr.is_null() { oom() }
83ba88
+            if ptr.is_null() { handle_alloc_error(layout::<T>(new_cap)) }
83ba88
             (*ptr).set_cap(new_cap);
83ba88
             self.ptr = NonNull::new_unchecked(ptr);
83ba88
         } else {
83ba88
-            self.ptr = header_with_capacity::<T>(new_cap);
83ba88
+            let mut new_header = header_with_capacity::<T>(new_cap);
83ba88
+
83ba88
+            // If we get here and have a non-zero len, then we must be handling
83ba88
+            // a gecko auto array, and we have items in a stack buffer. We shouldn't
83ba88
+            // free it, but we should memcopy the contents out of it and mark it as empty.
83ba88
+            //
83ba88
+            // T is assumed to be trivially relocatable, as this is ~required
83ba88
+            // for Rust compatibility anyway. Furthermore, we assume C++ won't try
83ba88
+            // to unconditionally destroy the contents of the stack allocated buffer
83ba88
+            // (i.e. it's obfuscated behind a union).
83ba88
+            //
83ba88
+            // In effect, we are partially reimplementing the auto array move constructor
83ba88
+            // by leaving behind a valid empty instance.
83ba88
+            let len = self.len();
83ba88
+            if cfg!(feature = "gecko-ffi") && len > 0 {
83ba88
+                new_header.as_mut().data::<T>().copy_from_nonoverlapping(self.data_raw(), len);
83ba88
+                self.set_len(0);
83ba88
+            }
83ba88
+            
83ba88
+            self.ptr = new_header;
83ba88
         }
83ba88
     }
83ba88
 
dcefa4
@@ -1093,10 +1303,7 @@ mod tests {
83ba88
         use std::mem::size_of;
83ba88
         assert_eq!(size_of::<ThinVec<u8>>(), size_of::<&u8>());
83ba88
 
83ba88
-        // We don't perform the null-pointer optimization on stable rust.
83ba88
-        if cfg!(feature = "unstable") {
83ba88
-            assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
83ba88
-        }
83ba88
+        assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
83ba88
     }
83ba88
 
83ba88
     #[test]
dcefa4
@@ -1731,7 +1938,6 @@ mod std_tests {
83ba88
         assert_eq!(v, &[(), ()]);
83ba88
     }
83ba88
 
83ba88
-/* TODO: support inclusive ranges
83ba88
     #[test]
83ba88
     fn test_drain_inclusive_range() {
83ba88
         let mut v = thin_vec!['a', 'b', 'c', 'd', 'e'];
dcefa4
@@ -1761,6 +1967,7 @@ mod std_tests {
83ba88
     }
83ba88
 
83ba88
     #[test]
83ba88
+    #[cfg(not(feature = "gecko-ffi"))]
83ba88
     fn test_drain_max_vec_size() {
83ba88
         let mut v = ThinVec::<()>::with_capacity(usize::max_value());
83ba88
         unsafe { v.set_len(usize::max_value()); }
dcefa4
@@ -1781,7 +1988,6 @@ mod std_tests {
83ba88
         let mut v = thin_vec![1, 2, 3, 4, 5];
83ba88
         v.drain(5..=5);
83ba88
     }
83ba88
-*/
83ba88
 
83ba88
 /* TODO: implement splice?
83ba88
     #[test]
dcefa4
@@ -2187,7 +2393,7 @@ mod std_tests {
83ba88
         assert!(v.capacity() >= 33)
83ba88
     }
83ba88
 
83ba88
-/* TODO: implement try_reserve 
83ba88
+/* TODO: implement try_reserve
83ba88
     #[test]
83ba88
     fn test_try_reserve() {
83ba88
 
dcefa4
--- thunderbird-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:12.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml	2021-03-22 11:37:44.287130273 +0100
83ba88
@@ -8,5 +8,5 @@ nserror = { path = "../../../xpcom/rust/
83ba88
 nsstring = { path = "../../../xpcom/rust/nsstring" }
83ba88
 rental = "0.5.5"
83ba88
 rust_cascade = "0.6.0"
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 xpcom = { path = "../../../xpcom/rust/xpcom" }
dcefa4
--- thunderbird-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:28.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml	2021-03-22 11:37:44.288130270 +0100
83ba88
@@ -13,7 +13,7 @@ moz_task = { path = "../../../../../xpco
83ba88
 nserror = { path = "../../../../../xpcom/rust/nserror" }
83ba88
 nsstring = { path = "../../../../../xpcom/rust/nsstring" }
83ba88
 once_cell = "1"
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 xpcom = { path = "../../../../../xpcom/rust/xpcom" }
83ba88
 serde = "1"
83ba88
 serde_json = "1"
dcefa4
--- thunderbird-78.9.0/toolkit/components/kvstore/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/toolkit/components/kvstore/Cargo.toml	2021-03-22 11:37:44.289130267 +0100
83ba88
@@ -18,7 +18,7 @@ rkv = "0.10.2"
83ba88
 storage_variant = { path = "../../../storage/variant" }
83ba88
 xpcom = { path = "../../../xpcom/rust/xpcom" }
83ba88
 tempfile = "3"
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
83ba88
 
83ba88
 # Get rid of failure's dependency on backtrace. Eventually
83ba88
 # backtrace will move into Rust core, but we don't need it here.
dcefa4
--- thunderbird-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:25.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml	2021-03-22 11:37:44.289130267 +0100
83ba88
@@ -19,5 +19,5 @@ url = "2.0"
83ba88
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
83ba88
 
83ba88
 [dependencies.thin-vec]
83ba88
-version = "0.1.0"
83ba88
+version = "0.2.1"
83ba88
 features = ["gecko-ffi"]
dcefa4
--- thunderbird-78.9.0/tools/profiler/rust-helper/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/tools/profiler/rust-helper/Cargo.toml	2021-03-22 11:37:44.290130265 +0100
83ba88
@@ -23,7 +23,7 @@ features = ["endian_fd", "elf32", "elf64
83ba88
 default-features = false
83ba88
 
83ba88
 [dependencies.thin-vec]
83ba88
-version = "0.1.0"
83ba88
+version = "0.2.1"
83ba88
 features = ["gecko-ffi"]
83ba88
 
83ba88
 [features]
dcefa4
--- thunderbird-78.9.0/xpcom/rust/xpcom/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
dcefa4
+++ thunderbird-78.9.0/xpcom/rust/xpcom/Cargo.toml	2021-03-22 11:37:44.291130262 +0100
83ba88
@@ -9,4 +9,4 @@ nsstring = { path = "../nsstring" }
83ba88
 nserror = { path = "../nserror" }
83ba88
 threadbound = "0.1"
83ba88
 xpcom_macros = { path = "xpcom_macros" }
83ba88
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
83ba88
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }