diff --git a/core/runtime/binaryen/memory_impl.cpp b/core/runtime/binaryen/memory_impl.cpp index ff6f7c5a72..e73ff2feb3 100644 --- a/core/runtime/binaryen/memory_impl.cpp +++ b/core/runtime/binaryen/memory_impl.cpp @@ -13,10 +13,9 @@ namespace kagome::runtime::binaryen { MemoryImpl::MemoryImpl(RuntimeExternalInterface::InternalMemory *memory, std::unique_ptr &&allocator) : memory_{memory}, - size_{kInitialMemorySize}, allocator_{std::move(allocator)}, logger_{log::createLogger("Binaryen Memory", "binaryen")} { - resize(size_); + resize(kInitialMemorySize); } MemoryImpl::MemoryImpl(RuntimeExternalInterface::InternalMemory *memory, @@ -26,7 +25,7 @@ namespace kagome::runtime::binaryen { std::make_unique( MemoryAllocator::MemoryHandle{ [this](auto new_size) { return resize(new_size); }, - [this]() { return size_; }, + [this]() { return size(); }, [this](auto addr, uint32_t value) { memory_->set(addr, value); }, @@ -80,13 +79,13 @@ namespace kagome::runtime::binaryen { common::BufferView MemoryImpl::loadN(kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize n) const { - BOOST_ASSERT(size_ > addr and size_ - addr >= n); + BOOST_ASSERT(size() > addr and size() - addr >= n); return common::BufferView{memory_->getBuffer(addr, n)}; } std::string MemoryImpl::loadStr(kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize length) const { - BOOST_ASSERT(size_ > addr and size_ - addr >= length); + BOOST_ASSERT(size() > addr and size() - addr >= length); std::string res; res.reserve(length); for (auto i = addr; i < addr + length; i++) { diff --git a/core/runtime/binaryen/memory_impl.hpp b/core/runtime/binaryen/memory_impl.hpp index f888646525..881ef8bdab 100644 --- a/core/runtime/binaryen/memory_impl.hpp +++ b/core/runtime/binaryen/memory_impl.hpp @@ -81,22 +81,21 @@ namespace kagome::runtime::binaryen { * We use this condition to avoid * deallocated_ pointers fixup */ - if (new_size >= size_) { + if (new_size >= size()) { if (auto mod = new_size % kMemoryPageSize) { new_size += kMemoryPageSize - mod; } - size_ = new_size; memory_->resize(new_size); } } WasmSize size() const override { - return size_; + BOOST_ASSERT(memory_ != nullptr); + return memory_->getSize(); } private: RuntimeExternalInterface::InternalMemory *memory_; - WasmSize size_; std::unique_ptr allocator_; log::Logger logger_;