Skip to content

Commit cb5af84

Browse files
authored
Make emscripten_resize_heap compatible with PURE_WASI (#22217)
Previously, using PURE_WASI was incompatible with EMSCRIPTEN_MEMORY_GROWTH flag, and was not documented. Now, using EMSCRIPTEN_MEMORY_GROWTH with PURE_WASI is possible. It will not require the host to export emscripten_notify_memory_growth and will grow the memory as expected from EMSCRIPTEN_MEMORY_GROWTH. Fixes #22211
1 parent 3b2372c commit cb5af84

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

system/lib/standalone/standalone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ size_t emscripten_get_heap_max() {
152152
}
153153

154154
int emscripten_resize_heap(size_t size) {
155-
#if defined(EMSCRIPTEN_MEMORY_GROWTH) && !defined(EMSCRIPTEN_PURE_WASI)
155+
#if defined(EMSCRIPTEN_MEMORY_GROWTH)
156156
size_t old_size = __builtin_wasm_memory_size(0) * WASM_PAGE_SIZE;
157157
assert(old_size < size);
158158
ssize_t diff = (size - old_size + WASM_PAGE_SIZE - 1) / WASM_PAGE_SIZE;
159159
size_t result = __builtin_wasm_memory_grow(0, diff);
160160
if (result != (size_t)-1) {
161+
#if !defined(EMSCRIPTEN_PURE_WASI)
161162
// Success, update JS (see https://github.com/WebAssembly/WASI/issues/82)
162163
emscripten_notify_memory_growth(0);
164+
#endif
163165
return 1;
164166
}
165167
#endif

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ def test_memorygrowth_3(self):
20872087
self.set_setting('SAFE_HEAP')
20882088
self.do_core_test('test_memorygrowth_3.c')
20892089

2090-
@also_with_standalone_wasm(impure=True)
2090+
@also_with_standalone_wasm()
20912091
@no_4gb('depends on INITIAL_MEMORY')
20922092
@no_2gb('depends on INITIAL_MEMORY')
20932093
def test_memorygrowth_MAXIMUM_MEMORY(self):

0 commit comments

Comments
 (0)