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