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