Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Update indices of functions in name section while injecting gas function #146

Closed
wants to merge 6 commits into from
15 changes: 15 additions & 0 deletions src/gas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod validation;

use crate::std::cmp::min;
use crate::std::mem;
use crate::std::string::String;
use crate::std::vec::Vec;

use parity_wasm::{elements, elements::ValueType, builder};
Expand Down Expand Up @@ -501,6 +502,20 @@ pub fn inject_gas_counter<R: Rules>(
elements::Section::Start(start_idx) => {
if *start_idx >= gas_func { *start_idx += 1}
},
elements::Section::Name(section) => {
if let Some(funcs) = section.functions_mut() {
let mut new_names = elements::IndexMap::<String>::default();
for (idx, func) in funcs.names().iter() {
if idx > gas_func {
new_names.insert(idx + 1, String::from(func));
} else {
new_names.insert(idx, String::from(func));
}
}

*funcs.names_mut() = new_names;
}
}
_ => { }
}
}
Expand Down