Skip to content

Commit f070262

Browse files
committed
update memory growth code, and ensure replace_memory is on the top in fastcomp
1 parent c40c7c2 commit f070262

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

emscripten.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,8 @@ def access_quote(prop):
11771177
# calculate exports
11781178
exported_implemented_functions = list(exported_implemented_functions) + metadata['initializers']
11791179
exported_implemented_functions.append('runPostSets')
1180+
if settings['ALLOW_MEMORY_GROWTH']:
1181+
exported_implemented_functions.append('_emscripten_replace_memory')
11801182
exports = []
11811183
for export in exported_implemented_functions + asm_runtime_funcs + function_tables:
11821184
exports.append(quote(export) + ": " + export)
@@ -1287,7 +1289,21 @@ def math_fix(g):
12871289
var nan = +env.NaN, inf = +env.Infinity;
12881290
var tempInt = 0, tempBigInt = 0, tempBigIntP = 0, tempBigIntS = 0, tempBigIntR = 0.0, tempBigIntI = 0, tempBigIntD = 0, tempValue = 0, tempDouble = 0.0;
12891291
''' + ''.join(['''
1290-
var tempRet%d = 0;''' % i for i in range(10)]) + '\n' + asm_global_funcs] + [' var tempFloat = %s;\n' % ('Math_fround(0)' if settings.get('PRECISE_F32') else '0.0')] + ([' const f0 = Math_fround(0);\n'] if settings.get('PRECISE_F32') else []) + ['''
1292+
var tempRet%d = 0;''' % i for i in range(10)]) + '\n' + asm_global_funcs] + [' var tempFloat = %s;\n' % ('Math_fround(0)' if settings.get('PRECISE_F32') else '0.0')] + ([' const f0 = Math_fround(0);\n'] if settings.get('PRECISE_F32') else []) + ['' if not settings['ALLOW_MEMORY_GROWTH'] else '''
1293+
function _emscripten_replace_memory(newBuffer) {
1294+
if ((byteLength(newBuffer) & 0xffffff || byteLength(newBuffer) <= 0xffffff)) return false;
1295+
HEAP8 = new Int8View(newBuffer);
1296+
HEAP16 = new Int16View(newBuffer);
1297+
HEAP32 = new Int32View(newBuffer);
1298+
HEAPU8 = new Uint8View(newBuffer);
1299+
HEAPU16 = new Uint16View(newBuffer);
1300+
HEAPU32 = new Uint32View(newBuffer);
1301+
HEAPF32 = new Float32View(newBuffer);
1302+
HEAPF64 = new Float64View(newBuffer);
1303+
buffer = newBuffer;
1304+
return true;
1305+
}
1306+
'''] + ['''
12911307
// EMSCRIPTEN_START_FUNCS
12921308
function stackAlloc(size) {
12931309
size = size|0;

src/library.js

+2
Original file line numberDiff line numberDiff line change
@@ -8766,6 +8766,7 @@ LibraryManager.library = {
87668766
return cache[fullname] = allocate(intArrayFromString(ret + ''), 'i8', ALLOC_NORMAL);
87678767
},
87688768

8769+
#if RUNNING_FASTCOMP == 0
87698770
#if ASM_JS
87708771
#if ALLOW_MEMORY_GROWTH
87718772
emscripten_replace_memory__asm: true, // this is used inside the asm module
@@ -8788,6 +8789,7 @@ LibraryManager.library = {
87888789
// but should not declare itself as validating (which is prevented in ASM_JS == 2).
87898790
{{{ (assert(ASM_JS === 2), DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('emscripten_replace_memory'), '') }}}
87908791
#endif
8792+
#endif
87918793
#endif
87928794

87938795
emscripten_debugger: function() {

0 commit comments

Comments
 (0)