Skip to content

Commit

Permalink
Try #1837:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Nov 26, 2020
2 parents 29eef4f + 5a00f26 commit 511cf2b
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 295 deletions.
7 changes: 6 additions & 1 deletion lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Function {
vmctx,
signature: ty.clone(),
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down Expand Up @@ -152,6 +153,7 @@ impl Function {
vmctx,
signature: ty.clone(),
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down Expand Up @@ -196,6 +198,7 @@ impl Function {
signature,
kind: VMFunctionKind::Static,
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down Expand Up @@ -252,6 +255,7 @@ impl Function {
vmctx,
signature,
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down Expand Up @@ -293,6 +297,7 @@ impl Function {
vmctx,
signature,
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down Expand Up @@ -474,7 +479,7 @@ impl Function {
Ok(results.into_boxed_slice())
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Self {
pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportFunction) -> Self {
if let Some(trampoline) = wasmer_export.call_trampoline {
Self {
store: store.clone(),
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/externals/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Global {
Ok(())
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
Self {
store: store.clone(),
global: wasmer_export.from,
Expand Down Expand Up @@ -218,6 +218,7 @@ impl<'a> Exportable<'a> for Global {
fn to_export(&self) -> Export {
ExportGlobal {
from: self.global.clone(),
instance_allocator: None,
}
.into()
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) }
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Self {
pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportMemory) -> Self {
Self {
store: store.clone(),
memory: wasmer_export.from,
Expand Down Expand Up @@ -248,6 +248,7 @@ impl<'a> Exportable<'a> for Memory {
fn to_export(&self) -> Export {
ExportMemory {
from: self.memory.clone(),
instance_allocator: None,
}
.into()
}
Expand Down
12 changes: 6 additions & 6 deletions lib/api/src/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ impl Extern {
}
}

/// Create an `Extern` from an `Export`.
pub fn from_export(store: &Store, export: Export) -> Self {
/// Create an `Extern` from an `wasmer_vm::Export`.
pub fn from_vm_export(store: &Store, export: Export) -> Self {
match export {
Export::Function(f) => Self::Function(Function::from_export(store, f)),
Export::Memory(m) => Self::Memory(Memory::from_export(store, m)),
Export::Global(g) => Self::Global(Global::from_export(store, g)),
Export::Table(t) => Self::Table(Table::from_export(store, t)),
Export::Function(f) => Self::Function(Function::from_vm_export(store, f)),
Export::Memory(m) => Self::Memory(Memory::from_vm_export(store, m)),
Export::Global(g) => Self::Global(Global::from_vm_export(store, g)),
Export::Table(t) => Self::Table(Table::from_vm_export(store, t)),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/externals/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Table {
Ok(())
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self {
pub(crate) fn from_vm_export(store: &Store, wasmer_export: ExportTable) -> Self {
Self {
store: store.clone(),
table: wasmer_export.from,
Expand All @@ -156,6 +156,7 @@ impl<'a> Exportable<'a> for Table {
fn to_export(&self) -> Export {
ExportTable {
from: self.table.clone(),
instance_allocator: None,
}
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Instance {
.map(|export| {
let name = export.name().to_string();
let export = handle.lookup(&name).expect("export");
let extern_ = Extern::from_export(store, export);
let extern_ = Extern::from_vm_export(store, export);
(name, extern_)
})
.collect::<Exports>();
Expand Down
2 changes: 2 additions & 0 deletions lib/api/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ where
signature,
kind: other.arg_kind,
call_trampoline: None,
instance_allocator: None,
}
}
}
Expand All @@ -90,6 +91,7 @@ where
signature,
kind: other.arg_kind,
call_trampoline: None,
instance_allocator: None,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ impl ValFuncRef for Val {
kind: wasmer_vm::VMFunctionKind::Static,
vmctx: item.vmctx,
call_trampoline: None,
instance_allocator: None,
};
let f = Function::from_export(store, export);
let f = Function::from_vm_export(store, export);
Self::FuncRef(f)
}
}
2 changes: 1 addition & 1 deletion lib/c-api/src/wasm_c_api/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ unsafe fn wasi_get_imports_inner(
import_type.name()
),
}));
let inner = Extern::from_export(store, export);
let inner = Extern::from_vm_export(store, export);

Some(Box::new(wasm_extern_t {
instance: None,
Expand Down
4 changes: 2 additions & 2 deletions lib/deprecated/runtime-core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ impl Module {

(
(namespace, name),
new::wasmer::Extern::from_export(store, Export::Function(function)),
new::wasmer::Extern::from_vm_export(store, Export::Function(function)),
)
}
export => (
(namespace, name),
new::wasmer::Extern::from_export(store, export),
new::wasmer::Extern::from_vm_export(store, export),
),
})
.for_each(|((namespace, name), extern_)| {
Expand Down
13 changes: 13 additions & 0 deletions lib/vm/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md

use crate::global::Global;
use crate::instance::InstanceAllocator;
use crate::memory::{Memory, MemoryStyle};
use crate::table::{Table, TableStyle};
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline};
Expand Down Expand Up @@ -38,6 +39,9 @@ pub struct ExportFunction {
/// Address of the function call trampoline owned by the same VMContext that owns the VMFunctionBody.
/// May be None when the function is a host-function (FunctionType == Dynamic or vmctx == nullptr).
pub call_trampoline: Option<VMTrampoline>,
/// A reference to the instance, to ensure it's not deallocated
/// before the function.
pub instance_allocator: Option<InstanceAllocator>,
}

/// # Safety
Expand All @@ -59,6 +63,9 @@ impl From<ExportFunction> for Export {
pub struct ExportTable {
/// Pointer to the containing `Table`.
pub from: Arc<dyn Table>,
/// A reference to the instance, to ensure it's not deallocated
/// before the table.
pub instance_allocator: Option<InstanceAllocator>,
}

/// # Safety
Expand Down Expand Up @@ -100,6 +107,9 @@ impl From<ExportTable> for Export {
pub struct ExportMemory {
/// Pointer to the containing `Memory`.
pub from: Arc<dyn Memory>,
/// A reference to the instance, to ensure it's not deallocated
/// before the memory.
pub instance_allocator: Option<InstanceAllocator>,
}

/// # Safety
Expand Down Expand Up @@ -141,6 +151,9 @@ impl From<ExportMemory> for Export {
pub struct ExportGlobal {
/// The global declaration, used for compatibility checking.
pub from: Arc<Global>,
/// A reference to the instance, to ensure it's not deallocated
/// before the global.
pub instance_allocator: Option<InstanceAllocator>,
}

/// # Safety
Expand Down
Loading

0 comments on commit 511cf2b

Please sign in to comment.