mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-06-01 17:11:22 +00:00
ensure here that module has the DataSection
This commit is contained in:
parent
7d185f25dc
commit
a77ca2a974
13
src/pack.rs
13
src/pack.rs
@ -1,6 +1,6 @@
|
||||
use std::fmt;
|
||||
use parity_wasm::elements::{
|
||||
self, Section, Opcode, DataSegment, InitExpr, Internal, External,
|
||||
self, Section, DataSection, Opcode, DataSegment, InitExpr, Internal, External,
|
||||
ImportCountType,
|
||||
};
|
||||
use parity_wasm::builder;
|
||||
@ -146,12 +146,21 @@ pub fn pack_instance(raw_module: Vec<u8>, mut ctor_module: elements::Module) ->
|
||||
// If new function is put in ctor module, it will have this callable index
|
||||
let last_function_index = ctor_module.functions_space();
|
||||
|
||||
// We ensure here that module has the DataSection
|
||||
if ctor_module
|
||||
.sections()
|
||||
.iter()
|
||||
.find(|section| match **section { Section::Data(ref _d) => true, _ => false })
|
||||
.is_none() {
|
||||
// DataSection has to be the last non-custom section according the to the spec
|
||||
ctor_module.sections_mut().push(Section::Data(DataSection::with_entries(vec![])));
|
||||
}
|
||||
|
||||
// Code data address is an address where we put the contract's code (raw_module)
|
||||
let mut code_data_address = 0i32;
|
||||
|
||||
for section in ctor_module.sections_mut() {
|
||||
match section {
|
||||
// TODO: add data section is there no one
|
||||
&mut Section::Data(ref mut data_section) => {
|
||||
let (index, offset) = if let Some(ref entry) = data_section.entries().iter().last() {
|
||||
if let Opcode::I32Const(offst) = entry.offset().code()[0] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user