mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
Fixed wasmer-js send+sync
This commit is contained in:
@@ -16,6 +16,9 @@ pub struct VMMemory {
|
||||
pub(crate) ty: MemoryType,
|
||||
}
|
||||
|
||||
unsafe impl Send for VMMemory {}
|
||||
unsafe impl Sync for VMMemory {}
|
||||
|
||||
impl VMMemory {
|
||||
pub(crate) fn new(memory: Memory, ty: MemoryType) -> Self {
|
||||
Self { memory, ty }
|
||||
@@ -34,12 +37,18 @@ impl VMGlobal {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for VMGlobal {}
|
||||
unsafe impl Sync for VMGlobal {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VMTable {
|
||||
pub(crate) table: Table,
|
||||
pub(crate) ty: TableType,
|
||||
}
|
||||
|
||||
unsafe impl Send for VMTable {}
|
||||
unsafe impl Sync for VMTable {}
|
||||
|
||||
impl VMTable {
|
||||
pub(crate) fn new(table: Table, ty: TableType) -> Self {
|
||||
Self { table, ty }
|
||||
@@ -53,6 +62,9 @@ pub struct VMFunction {
|
||||
pub(crate) environment: Option<Arc<RefCell<Box<dyn WasmerEnv>>>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for VMFunction {}
|
||||
unsafe impl Sync for VMFunction {}
|
||||
|
||||
impl VMFunction {
|
||||
pub(crate) fn new(
|
||||
function: Function,
|
||||
|
||||
@@ -42,7 +42,7 @@ pub trait LikeNamespace {
|
||||
/// ```
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ImportObject {
|
||||
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace>>>>,
|
||||
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace + Send + Sync>>>>,
|
||||
}
|
||||
|
||||
impl ImportObject {
|
||||
@@ -88,7 +88,7 @@ impl ImportObject {
|
||||
pub fn register<S, N>(&mut self, name: S, namespace: N) -> Option<Box<dyn LikeNamespace>>
|
||||
where
|
||||
S: Into<String>,
|
||||
N: LikeNamespace + 'static,
|
||||
N: LikeNamespace + Send + Sync + 'static,
|
||||
{
|
||||
let mut guard = self.map.lock().unwrap();
|
||||
let map = guard.borrow_mut();
|
||||
|
||||
@@ -92,7 +92,10 @@ impl Instance {
|
||||
/// Those are, as defined by the spec:
|
||||
/// * Link errors that happen when plugging the imports into the instance
|
||||
/// * Runtime errors that happen when running the module `start` function.
|
||||
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Self, InstantiationError> {
|
||||
pub fn new(
|
||||
module: &Module,
|
||||
resolver: &(dyn Resolver + Send + Sync),
|
||||
) -> Result<Self, InstantiationError> {
|
||||
let (instance, imports) = module
|
||||
.instantiate(resolver)
|
||||
.map_err(|e| InstantiationError::Start(e))?;
|
||||
|
||||
@@ -52,7 +52,7 @@ impl<T: NamedResolver> NamedResolver for &T {
|
||||
}
|
||||
}
|
||||
|
||||
impl NamedResolver for Box<dyn NamedResolver> {
|
||||
impl NamedResolver for Box<dyn NamedResolver + Send + Sync> {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
|
||||
(**self).resolve_by_name(module, field)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl Resolver for NullResolver {
|
||||
}
|
||||
|
||||
/// A [`Resolver`] that links two resolvers together in a chain.
|
||||
pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
|
||||
pub struct NamedResolverChain<A: NamedResolver + Send + Sync, B: NamedResolver + Send + Sync> {
|
||||
a: A,
|
||||
b: B,
|
||||
}
|
||||
@@ -85,14 +85,14 @@ pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
|
||||
/// ```
|
||||
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
|
||||
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
|
||||
/// # where A: NamedResolver + Sized,
|
||||
/// # B: NamedResolver + Sized,
|
||||
/// # where A: NamedResolver + Sized + Send + Sync,
|
||||
/// # B: NamedResolver + Sized + Send + Sync,
|
||||
/// # {
|
||||
/// // override duplicates with imports from `imports2`
|
||||
/// imports1.chain_front(imports2);
|
||||
/// # }
|
||||
/// ```
|
||||
pub trait ChainableNamedResolver: NamedResolver + Sized {
|
||||
pub trait ChainableNamedResolver: NamedResolver + Sized + Send + Sync {
|
||||
/// Chain a resolver in front of the current resolver.
|
||||
///
|
||||
/// This will cause the second resolver to override the first.
|
||||
@@ -100,8 +100,8 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
|
||||
/// ```
|
||||
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
|
||||
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
|
||||
/// # where A: NamedResolver + Sized,
|
||||
/// # B: NamedResolver + Sized,
|
||||
/// # where A: NamedResolver + Sized + Send + Sync,
|
||||
/// # B: NamedResolver + Sized + Send + Sync,
|
||||
/// # {
|
||||
/// // override duplicates with imports from `imports2`
|
||||
/// imports1.chain_front(imports2);
|
||||
@@ -109,7 +109,7 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
|
||||
/// ```
|
||||
fn chain_front<U>(self, other: U) -> NamedResolverChain<U, Self>
|
||||
where
|
||||
U: NamedResolver,
|
||||
U: NamedResolver + Send + Sync,
|
||||
{
|
||||
NamedResolverChain { a: other, b: self }
|
||||
}
|
||||
@@ -121,8 +121,8 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
|
||||
/// ```
|
||||
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
|
||||
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
|
||||
/// # where A: NamedResolver + Sized,
|
||||
/// # B: NamedResolver + Sized,
|
||||
/// # where A: NamedResolver + Sized + Send + Sync,
|
||||
/// # B: NamedResolver + Sized + Send + Sync,
|
||||
/// # {
|
||||
/// // override duplicates with imports from `imports1`
|
||||
/// imports1.chain_back(imports2);
|
||||
@@ -130,19 +130,19 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
|
||||
/// ```
|
||||
fn chain_back<U>(self, other: U) -> NamedResolverChain<Self, U>
|
||||
where
|
||||
U: NamedResolver,
|
||||
U: NamedResolver + Send + Sync,
|
||||
{
|
||||
NamedResolverChain { a: self, b: other }
|
||||
}
|
||||
}
|
||||
|
||||
// We give these chain methods to all types implementing NamedResolver
|
||||
impl<T: NamedResolver> ChainableNamedResolver for T {}
|
||||
impl<T: NamedResolver + Send + Sync> ChainableNamedResolver for T {}
|
||||
|
||||
impl<A, B> NamedResolver for NamedResolverChain<A, B>
|
||||
where
|
||||
A: NamedResolver,
|
||||
B: NamedResolver,
|
||||
A: NamedResolver + Send + Sync,
|
||||
B: NamedResolver + Send + Sync,
|
||||
{
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
|
||||
self.a
|
||||
@@ -153,8 +153,8 @@ where
|
||||
|
||||
impl<A, B> Clone for NamedResolverChain<A, B>
|
||||
where
|
||||
A: NamedResolver + Clone,
|
||||
B: NamedResolver + Clone,
|
||||
A: NamedResolver + Clone + Send + Sync,
|
||||
B: NamedResolver + Clone + Send + Sync,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user