Merge pull request #71 from NikVolf/import_external_global

global import breaks with Function("missing exports with name STACKTOP")
This commit is contained in:
Nikolay Volf 2017-07-25 15:41:12 +03:00 committed by GitHub
commit b831ff783a
3 changed files with 38 additions and 28 deletions

View File

@ -81,7 +81,8 @@ pub struct EnvModuleInstance {
impl EnvModuleInstance {
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
let instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
let mut instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
instance.instantiate(false, None)?;
Ok(EnvModuleInstance {
_params: params,

View File

@ -235,7 +235,6 @@ impl ModuleInstance {
}
// validate export section
if is_user_module { // TODO: env module exports STACKTOP global, which is mutable => check is failed
if let Some(export_section) = self.module.export_section() {
for export in export_section.entries() {
match export.internal() {
@ -245,7 +244,7 @@ impl ModuleInstance {
},
&Internal::Global(global_index) => {
self.global(ItemIndex::IndexSpace(global_index), None)
.and_then(|g| if g.is_mutable() {
.and_then(|g| if g.is_mutable() && is_user_module {
Err(Error::Validation(format!("trying to export mutable global {}", export.field())))
} else {
Ok(())
@ -263,7 +262,6 @@ impl ModuleInstance {
}
}
}
}
// validate import section
if let Some(import_section) = self.module.import_section() {

View File

@ -210,6 +210,17 @@ fn single_program_different_modules() {
assert_eq!(executor.values, vec![7, 57, 42]);
}
#[test]
fn import_env_mutable_global() {
let program = ProgramInstance::new().unwrap();
let module = module()
.with_import(ImportEntry::new("env".into(), "STACKTOP".into(), External::Global(GlobalType::new(ValueType::I32, false))))
.build();
program.add_module("main", module, None).unwrap();
}
#[test]
fn env_native_export_entry_type_check() {
let program = ProgramInstance::new().unwrap();