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