Skip to content

Commit

Permalink
Refactor memory variable declarations for clarity in wasm_loader.c
Browse files Browse the repository at this point in the history
  • Loading branch information
lum1n0us committed Jan 10, 2025
1 parent 99b78f0 commit cd9c8f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 60 deletions.
13 changes: 6 additions & 7 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6156,9 +6156,6 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}

if (!module->possible_memory_grow) {
WASMMemoryImport *memory_import;
WASMMemory *memory;

#if WASM_ENABLE_SHRUNK_MEMORY != 0
if (aux_data_end_global && aux_heap_base_global
&& aux_stack_top_global) {
Expand All @@ -6169,7 +6166,8 @@ load_from_sections(WASMModule *module, WASMSection *sections,
* valid range of uint32 */
if (shrunk_memory_size <= UINT32_MAX) {
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
WASMMemoryImport *memory_import =
&module->import_memories[0].u.memory;
init_memory_size =
(uint64)memory_import->mem_type.num_bytes_per_page
* memory_import->mem_type.init_page_count;
Expand All @@ -6184,7 +6182,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}

if (module->memory_count) {
memory = &module->memories[0];
WASMMemory *memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
Expand All @@ -6201,7 +6199,8 @@ load_from_sections(WASMModule *module, WASMSection *sections,

#if WASM_ENABLE_MULTI_MODULE == 0
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
WASMMemoryImport *memory_import =
&module->import_memories[0].u.memory;
/* Only resize the memory to one big page if num_bytes_per_page is
* in valid range of uint32 */
if (memory_import->mem_type.init_page_count < DEFAULT_MAX_PAGES) {
Expand All @@ -6217,7 +6216,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}
}
if (module->memory_count) {
memory = &module->memories[0];
WASMMemory *memory = &module->memories[0];
/* Only resize(shrunk) the memory size if num_bytes_per_page is in
* valid range of uint32 */
if (memory->init_page_count < DEFAULT_MAX_PAGES) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
diff --git a/test/core/imports.wast b/test/core/imports.wast
index 0cc07cb..4e8367a 100644
--- a/test/core/imports.wast
+++ b/test/core/imports.wast
@@ -86,7 +86,7 @@
(assert_return (invoke "print64" (i64.const 24)))

(assert_invalid
- (module
+ (module
(type (func (result i32)))
(import "test" "func" (func (type 1)))
)
@@ -578,6 +578,7 @@
(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
(assert_return (invoke "grow" (i32.const 0)) (i32.const 2))

+(;
(module $Mgm
(memory (export "memory") 1) ;; initial size is 1
(func (export "grow") (result i32) (memory.grow (i32.const 1)))
@@ -586,7 +587,7 @@
(assert_return (invoke $Mgm "grow") (i32.const 1)) ;; now size is 2
(module $Mgim1
;; imported memory limits should match, because external memory size is 2 now
- (memory (export "memory") (import "grown-memory" "memory") 2)
+ (memory (export "memory") (import "grown-memory" "memory") 2)
(func (export "grow") (result i32) (memory.grow (i32.const 1)))
)
(register "grown-imported-memory" $Mgim1)
@@ -597,7 +598,7 @@
(func (export "size") (result i32) (memory.size))
)
(assert_return (invoke $Mgim2 "size") (i32.const 3))
-
+;)

;; Syntax errors

@@ -669,6 +670,7 @@
"import after memory"
)

+(;
;; This module is required to validate, regardless of whether it can be
;; linked. Overloading is not possible in wasm itself, but it is possible
;; in modules from which wasm can import.
@@ -695,3 +697,4 @@
)
"unknown import"
)
+;)
\ No newline at end of file
diff --git a/test/core/linking.wast b/test/core/linking.wast
index 994e0f4..8fbcc02 100644
--- a/test/core/linking.wast
Expand Down

0 comments on commit cd9c8f6

Please sign in to comment.