Compare commits

...

3 Commits

Author SHA1 Message Date
Michael Mueller e2816f4661
Bump version 2019-06-25 15:05:01 +02:00
Michael Mueller a1ea2d689f
Implement Clone for ModuleInstance
...because of the contained Rc it's otherwise
just a shallow clone, not a deep.
2019-06-25 15:04:58 +02:00
Michael Mueller 327d93c785
Add constructor for ModuleRef 2019-06-25 15:04:57 +02:00
2 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "wasmi"
version = "0.4.5"
version = "0.4.6"
authors = ["Nikolay Volf <nikvolf@gmail.com>", "Svyatoslav Nikolsky <svyatonik@yandex.ru>", "Sergey Pepyakin <s.pepyakin@gmail.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"

View File

@ -37,6 +37,13 @@ use {Error, MemoryInstance, Module, RuntimeValue, Signature, TableInstance};
#[derive(Clone, Debug)]
pub struct ModuleRef(pub(crate) Rc<ModuleInstance>);
impl ModuleRef {
/// Creates a new `ModuleRef` from a `ModuleInstance`.
pub fn new(instance: ModuleInstance) -> ModuleRef {
ModuleRef(Rc::new(instance))
}
}
impl ::core::ops::Deref for ModuleRef {
type Target = ModuleInstance;
fn deref(&self) -> &ModuleInstance {
@ -162,6 +169,31 @@ pub struct ModuleInstance {
exports: RefCell<BTreeMap<String, ExternVal>>,
}
impl Clone for ModuleInstance {
fn clone(&self) -> Self {
let signatures = self.signatures.borrow();
let vec = &(*signatures);
let signatures = vec
.iter()
.map(|inner_rc| {
let signature = &**inner_rc;
let signature_clone = signature.clone();
Rc::new(signature_clone)
})
.collect();
let signatures = RefCell::new(signatures);
ModuleInstance {
signatures,
tables: self.tables.clone(),
funcs: self.funcs.clone(),
memories: self.memories.clone(),
globals: self.globals.clone(),
exports: self.exports.clone(),
}
}
}
impl ModuleInstance {
fn default() -> Self {
ModuleInstance {