[lightbeam] replace asserts by Errors in module.rs / translate_only (#713)
* replace assert by Errors * add better errors message module.rs
This commit is contained in:
committed by
Dan Gohman
parent
cc4be18119
commit
d1866f0e09
@@ -7,7 +7,7 @@ use cranelift_codegen::{
|
|||||||
isa,
|
isa,
|
||||||
};
|
};
|
||||||
use memoffset::offset_of;
|
use memoffset::offset_of;
|
||||||
use more_asserts::assert_le;
|
|
||||||
use std::{convert::TryInto, mem};
|
use std::{convert::TryInto, mem};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
||||||
@@ -563,15 +563,19 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
|
|||||||
let memories = section.get_memory_section_reader()?;
|
let memories = section.get_memory_section_reader()?;
|
||||||
let mem = translate_sections::memory(memories)?;
|
let mem = translate_sections::memory(memories)?;
|
||||||
|
|
||||||
assert_le!(
|
if mem.len() > 1 {
|
||||||
mem.len(),
|
return Err(Error::Input(
|
||||||
1,
|
"Multiple memory sections not yet implemented".to_string(),
|
||||||
"Multiple memory sections not yet unimplemented"
|
));
|
||||||
);
|
}
|
||||||
|
|
||||||
if !mem.is_empty() {
|
if !mem.is_empty() {
|
||||||
let mem = mem[0];
|
let mem = mem[0];
|
||||||
assert_eq!(Some(mem.limits.initial), mem.limits.maximum);
|
if Some(mem.limits.initial) != mem.limits.maximum {
|
||||||
|
return Err(Error::Input(
|
||||||
|
"Custom memory limits not supported in lightbeam".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
output.memory = Some(mem);
|
output.memory = Some(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,7 +646,11 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
|
|||||||
translate_sections::data(data)?;
|
translate_sections::data(data)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(reader.eof());
|
if !reader.eof() {
|
||||||
|
return Err(Error::Input(
|
||||||
|
"Unexpected data found after the end of the module".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user