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