Skip to content

Commit

Permalink
Address some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jun 18, 2020
1 parent 04857ec commit 5a45609
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion crates/wasmparser/src/binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'a> BinaryReader<'a> {
})
}

fn read_export_types(&mut self) -> Result<Vec<ExportType<'a>>> {
fn read_export_types(&mut self) -> Result<Box<[ExportType<'a>]>> {
let pos = self.original_position();
let exports_len = self.read_var_u32()? as usize;
if exports_len > MAX_WASM_EXPORTS {
Expand All @@ -304,13 +304,19 @@ impl<'a> BinaryReader<'a> {

pub(crate) fn read_import(&mut self) -> Result<Import<'a>> {
let module = self.read_string()?;

// For the `field`, figure out if we're the experimental encoding of
// single-level imports for the module linking proposal (a single-byte
// string which is 0xc0, which is invalid utf-8) or if we have a second
// level of import.
let mut clone = self.clone();
let field = if clone.read_var_u32()? == 1 && clone.read_u8()? == 0xc0 {
*self = clone;
None
} else {
Some(self.read_string()?)
};

let ty = self.read_import_desc()?;
Ok(Import { module, field, ty })
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmparser/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ pub struct FuncType {

#[derive(Debug, Clone)]
pub struct InstanceType<'a> {
pub exports: Vec<ExportType<'a>>,
pub exports: Box<[ExportType<'a>]>,
}

#[derive(Debug, Clone)]
pub struct ModuleType<'a> {
pub imports: Vec<crate::Import<'a>>,
pub exports: Vec<ExportType<'a>>,
pub imports: Box<[crate::Import<'a>]>,
pub exports: Box<[ExportType<'a>]>,
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ impl<'a> ValidatingParser<'a> {
if expected.imports.len() != actual.imports.len() {
return self.create_error("mismatched number of module imports");
}
for (expected, actual) in expected.imports.iter().zip(&actual.imports) {
for (expected, actual) in expected.imports.iter().zip(actual.imports.iter()) {
self.check_imports_match(&expected.ty, &actual.ty)?;
}
self.check_export_sets_match(&expected.exports, &actual.exports)?;
Expand Down

0 comments on commit 5a45609

Please sign in to comment.