Skip to content

Commit

Permalink
Merge pull request #3433 from dsherret/as_engine_ref_deserialize
Browse files Browse the repository at this point in the history
Module.deserialize - accept AsEngineRef
  • Loading branch information
syrusakbary authored Dec 23, 2022
2 parents c1b8f20 + 47e7f5d commit 1cf110f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/api/src/sys/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
bytes: impl IntoBytes,
) -> Result<Self, DeserializeError> {
let bytes = bytes.into_bytes();
let artifact = store.as_store_ref().engine().deserialize(&bytes)?;
let artifact = engine.as_engine_ref().engine().deserialize(&bytes)?;
Ok(Self::from_artifact(artifact))
}

Expand All @@ -334,11 +334,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize_from_file(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
path: impl AsRef<Path>,
) -> Result<Self, DeserializeError> {
let artifact = store
.as_store_ref()
let artifact = engine
.as_engine_ref()
.engine()
.deserialize_from_file(path.as_ref())?;
Ok(Self::from_artifact(artifact))
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::hash::Hash;
use std::error::Error;
use wasmer::{Module, Store};
use wasmer::{Module, AsEngineRef};

/// A generic cache for storing and loading compiled wasm modules.
pub trait Cache {
Expand All @@ -17,7 +17,7 @@ pub trait Cache {
///
/// # Safety
/// This function is unsafe as the cache store could be tampered with.
unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError>;
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError>;

/// Store a [`Module`] into the cache with the given [`Hash`].
fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError>;
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::hash::Hash;
use std::fs::{create_dir_all, File};
use std::io::{self, Write};
use std::path::PathBuf;
use wasmer::{DeserializeError, Module, SerializeError, Store};
use wasmer::{DeserializeError, Module, SerializeError, AsEngineRef};

/// Representation of a directory that contains compiled wasm artifacts.
///
Expand Down Expand Up @@ -91,14 +91,14 @@ impl Cache for FileSystemCache {
type DeserializeError = DeserializeError;
type SerializeError = SerializeError;

unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError> {
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError> {
let filename = if let Some(ref ext) = self.ext {
format!("{}.{}", key.to_string(), ext)
} else {
key.to_string()
};
let path = self.path.join(filename);
Module::deserialize_from_file(store, path)
Module::deserialize_from_file(engine, path)
}

fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> {
Expand Down

0 comments on commit 1cf110f

Please sign in to comment.