Skip to content

Commit 646ebc5

Browse files
committed
rename
1 parent f1257a2 commit 646ebc5

File tree

11 files changed

+27
-21
lines changed

11 files changed

+27
-21
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ See docs/process.md for more on how version tagging works.
2020

2121
Current Trunk
2222
-------------
23+
- The WebAssembly memory used by emscripten programs is now, by default, created
24+
in the wasm file and exported to JavaScript. Previously we could create the
25+
memory in JavaScript and import it into the wasm file. The new
26+
`IMPORTED_MEMORY` setting can be used to revert to the old behaviour. This
27+
can be useful, for example, if the wasm memory needs to be created at runtime
28+
before wasm instantiation.
2329

2430
2.0.9: 11/16/2020
2531
-----------------

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ def include_and_export(name):
17401740
shared.Settings.LEGALIZE_JS_FFI = 0
17411741

17421742
if shared.Settings.USE_PTHREADS or shared.Settings.RELOCATABLE or shared.Settings.ASYNCIFY_LAZY_LOAD_CODE:
1743-
shared.Settings.EXTERNAL_MEMORY = 1
1743+
shared.Settings.IMPORTED_MEMORY = 1
17441744

17451745
if shared.Settings.WASM_BIGINT:
17461746
shared.Settings.LEGALIZE_JS_FFI = 0

emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def create_em_js(forwarded_json, metadata):
536536

537537

538538
def add_standard_wasm_imports(send_items_map):
539-
if shared.Settings.EXTERNAL_MEMORY:
539+
if shared.Settings.IMPORTED_MEMORY:
540540
memory_import = 'wasmMemory'
541541
if shared.Settings.MODULARIZE and shared.Settings.USE_PTHREADS:
542542
# Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the

src/postamble_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
208208
assert(wasmTable);
209209
#endif
210210

211-
#if !EXTERNAL_MEMORY
211+
#if !IMPORTED_MEMORY
212212
wasmMemory = asm['memory'];
213213
#if ASSERTIONS
214214
assert(wasmMemory);

src/preamble.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,16 @@ if (typeof SharedArrayBuffer === 'undefined' || typeof Atomics === 'undefined')
325325
#endif
326326
#endif
327327

328-
#if EXTERNAL_MEMORY
328+
#if IMPORTED_MEMORY
329329
// In non-standalone/normal mode, we create the memory here.
330330
#include "runtime_init_memory.js"
331-
#else // EXTERNAL_MEMORY
331+
#else // IMPORTED_MEMORY
332332
#if ASSERTIONS
333333
// If memory is defined in wasm, the user can't provide it.
334-
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -s EXTERNAL_MEMORY to define wasmMemory externally');
335-
assert(INITIAL_MEMORY == {{{INITIAL_MEMORY}}}, 'Detected runtime INITIAL_MEMORY setting. Use -s EXTERNAL_MEMORY to define wasmMemory dynamically');
334+
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -s IMPORTED_MEMORY to define wasmMemory externally');
335+
assert(INITIAL_MEMORY == {{{INITIAL_MEMORY}}}, 'Detected runtime INITIAL_MEMORY setting. Use -s IMPORTED_MEMORY to define wasmMemory dynamically');
336336
#endif // ASSERTIONS
337-
#endif // EXTERNAL_MEMORY
337+
#endif // IMPORTED_MEMORY
338338

339339
#include "runtime_init_table.js"
340340
#include "runtime_stack_check.js"
@@ -834,11 +834,11 @@ function createWasm() {
834834

835835
Module['asm'] = exports;
836836

837-
#if !EXTERNAL_MEMORY
837+
#if !IMPORTED_MEMORY
838838
wasmMemory = Module['asm']['memory'];
839839
#if ASSERTIONS
840840
assert(wasmMemory);
841-
// This asserting doesn't hold went emscripten is run in --post-link
841+
// This assertion doesn't hold when emscripten is run in --post-link
842842
// mode.
843843
// TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
844844
//assert(wasmMemory.buffer.byteLength === {{{ INITIAL_MEMORY }}});

src/preamble_minimal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function updateGlobalBufferAndViews(b) {
7373
HEAPF64 = new Float64Array(b);
7474
}
7575

76-
#if EXTERNAL_MEMORY
76+
#if IMPORTED_MEMORY
7777
if (!ENVIRONMENT_IS_PTHREAD) {
7878
#if ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
7979
var wasmMaximumMemory = {{{ MAXIMUM_MEMORY >>> 16 }}};
@@ -98,7 +98,7 @@ if (ENVIRONMENT_IS_WORKER) {
9898
#else
9999
updateGlobalBufferAndViews(wasmMemory.buffer);
100100
#endif
101-
#endif // EXTERNAL_MEMORY
101+
#endif // IMPORTED_MEMORY
102102

103103
#include "runtime_stack_check.js"
104104
#include "runtime_assertions.js"

src/runtime_init_memory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
// Create the wasm memory. (Note: this only applies if EXTERNAL_MEMORY is defined)
8-
#if !EXTERNAL_MEMORY
9-
assert(false, "should be be included when EXTERNAL_MEMORY is set");
7+
// Create the wasm memory. (Note: this only applies if IMPORTED_MEMORY is defined)
8+
#if !IMPORTED_MEMORY
9+
{{{ throw "this file should not be be included when IMPORTED_MEMORY is set"; }}}
1010
#endif
1111

1212
#if USE_PTHREADS

src/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ var PURE_WASI = 0;
16381638
// - USE_PTHREADS
16391639
// - RELOCATABLE
16401640
// - ASYNCIFY_LAZY_LOAD_CODE
1641-
var EXTERNAL_MEMORY = 0;
1641+
var IMPORTED_MEMORY = 0;
16421642

16431643
//===========================================
16441644
// Internal, used for testing only, from here

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ def test_aborting_new(self, args):
20872087
@no_asan('ASan alters the memory size')
20882088
def test_module_wasm_memory(self):
20892089
self.emcc_args += ['--pre-js', path_from_root('tests', 'core', 'test_module_wasm_memory.js')]
2090-
self.set_setting('EXTERNAL_MEMORY')
2090+
self.set_setting('IMPORTED_MEMORY')
20912091
self.do_runf(path_from_root('tests', 'core', 'test_module_wasm_memory.c'), 'success')
20922092

20932093
def test_ssr(self): # struct self-ref

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6477,13 +6477,13 @@ def test_binaryen_warn_mem(self):
64776477
# if user changes INITIAL_MEMORY at runtime, the wasm module may not accept the memory import if
64786478
# it is too big/small
64796479
create_test_file('pre.js', 'var Module = { INITIAL_MEMORY: 50 * 1024 * 1024 };\n')
6480-
self.run_process([EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', 'INITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-s', 'WASM_ASYNC_COMPILATION=0', '-s', 'EXTERNAL_MEMORY'])
6480+
self.run_process([EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', 'INITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-s', 'WASM_ASYNC_COMPILATION=0', '-s', 'IMPORTED_MEMORY'])
64816481
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
64826482
self.assertContained('LinkError', out)
64836483
self.assertContained('Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time).', out)
64846484
self.assertNotContained('hello, world!', out)
64856485
# and with memory growth, all should be good
6486-
self.run_process([EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', 'INITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'WASM_ASYNC_COMPILATION=0', '-s', 'EXTERNAL_MEMORY'])
6486+
self.run_process([EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', 'INITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'WASM_ASYNC_COMPILATION=0', '-s', 'IMPORTED_MEMORY'])
64876487
self.assertContained('hello, world!', self.run_js('a.out.js'))
64886488

64896489
def test_binaryen_mem(self):

tools/building.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def lld_flags_for_executable(external_symbol_list):
478478
else:
479479
cmd.append('--allow-undefined')
480480

481-
if Settings.EXTERNAL_MEMORY:
481+
if Settings.IMPORTED_MEMORY:
482482
cmd.append('--import-memory')
483483

484484
if Settings.USE_PTHREADS:
@@ -1138,7 +1138,7 @@ def metadce(js_file, wasm_file, minify_whitespace, debug_info):
11381138
if export in user_requested_exports or Settings.EXPORT_ALL:
11391139
item['root'] = True
11401140
# in standalone wasm, always export the memory
1141-
if not Settings.EXTERNAL_MEMORY:
1141+
if not Settings.IMPORTED_MEMORY:
11421142
graph.append({
11431143
'export': 'memory',
11441144
'name': 'emcc$export$memory',

0 commit comments

Comments
 (0)