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