From 775330a1e5d2b039e643a587d6629141200ed88c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 4 Apr 2024 21:57:48 +0900 Subject: [PATCH] Reverts the public Memory.Pages API (#2174) Signed-off-by: Takeshi Yoneda --- api/wasm.go | 9 ++------- internal/wasm/memory_test.go | 5 +++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/wasm.go b/api/wasm.go index cca01a1a..c66b582f 100644 --- a/api/wasm.go +++ b/api/wasm.go @@ -565,17 +565,12 @@ type Memory interface { // # Notes // // - This overflows (returns zero) if the memory has the maximum 65536 pages. - // - Use Pages() to handle this corner case. + // As a workaround until wazero v2 to fix the return type, use Grow(0) to obtain the current pages and + // multiply by 65536. // // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefsyntax-instr-memorymathsfmemorysize%E2%91%A0 Size() uint32 - // Pages returns the number of pages in the memory. 1 Page corresponds to 65536 bytes, - // which is called "Page Size" in WebAssembly. - // - // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instances%E2%91%A0 - Pages() (pages uint32) - // Grow increases memory by the delta in pages (65536 bytes per page). // The return val is the previous memory size in pages, or false if the // delta was ignored as it exceeds MemoryDefinition.Max. diff --git a/internal/wasm/memory_test.go b/internal/wasm/memory_test.go index d3550b94..2aed432f 100644 --- a/internal/wasm/memory_test.go +++ b/internal/wasm/memory_test.go @@ -68,6 +68,11 @@ func TestMemoryInstance_Grow_Size(t *testing.T) { require.Equal(t, uint32(5), res) require.Equal(t, uint32(9), m.Pages()) + res, ok = m.Grow(0) + require.True(t, ok) + require.Equal(t, uint32(9), res) + require.Equal(t, uint32(9), m.Pages()) + // At this point, the page size equal 9, // so trying to grow two pages should result in failure. _, ok = m.Grow(2)