Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Use OOM-handling collections for `Metadata` (#12608)

Nick Fitzgerald55aa6a5def05
diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs
index 8a86da64cb..b725d9bb5e 100644
--- a/crates/wasmtime/src/engine/serialization.rs
+++ b/crates/wasmtime/src/engine/serialization.rs
@@ -35,7 +35,7 @@ use object::{
};
use serde_derive::{Deserialize, Serialize};
use wasmtime_environ::obj;
-use wasmtime_environ::{FlagValue, ObjectKind, Tunables};
+use wasmtime_environ::{FlagValue, ObjectKind, Tunables, collections};
const VERSION: u8 = 0;
@@ -180,11 +180,11 @@ pub fn detect_precompiled_file(path: impl AsRef<std::path::Path>) -> Result<Opti
#[derive(Serialize, Deserialize)]
pub struct Metadata<'a> {
- target: String,
+ target: collections::String,
#[serde(borrow)]
- shared_flags: Vec<(&'a str, FlagValue<'a>)>,
+ shared_flags: collections::Vec<(&'a str, FlagValue<'a>)>,
#[serde(borrow)]
- isa_flags: Vec<(&'a str, FlagValue<'a>)>,
+ isa_flags: collections::Vec<(&'a str, FlagValue<'a>)>,
tunables: Tunables,
features: u64,
}
@@ -194,9 +194,9 @@ impl Metadata<'_> {
pub fn new(engine: &Engine) -> Result<Metadata<'static>> {
let compiler = engine.try_compiler()?;
Ok(Metadata {
- target: compiler.triple().to_string(),
- shared_flags: compiler.flags(),
- isa_flags: compiler.isa_flags(),
+ target: compiler.triple().to_string().into(),
+ shared_flags: compiler.flags().into(),
+ isa_flags: compiler.isa_flags().into(),
tunables: engine.tunables().clone(),
features: engine.features().bits(),
})
@@ -463,7 +463,7 @@ mod test {
fn test_architecture_mismatch() -> Result<()> {
let engine = Engine::default();
let mut metadata = Metadata::new(&engine)?;
- metadata.target = "unknown-generic-linux".to_string();
+ metadata.target = "unknown-generic-linux".to_string().into();
match metadata.check_compatible(&engine) {
Ok(_) => unreachable!(),
@@ -486,7 +486,8 @@ mod test {
metadata.target = format!(
"{}-generic-unknown",
target_lexicon::Triple::host().architecture
- );
+ )
+ .into();
match metadata.check_compatible(&engine) {
Ok(_) => unreachable!(),
@@ -515,7 +516,7 @@ mod test {
metadata
.shared_flags
- .push(("preserve_frame_pointers", FlagValue::Bool(false)));
+ .push(("preserve_frame_pointers", FlagValue::Bool(false)))?;
match metadata.check_compatible(&engine) {
Ok(_) => unreachable!(),
@@ -541,7 +542,7 @@ mod test {
metadata
.isa_flags
- .push(("not_a_flag", FlagValue::Bool(true)));
+ .push(("not_a_flag", FlagValue::Bool(true)))?;
match metadata.check_compatible(&engine) {
Ok(_) => unreachable!(),