diff options
Diffstat (limited to 'src/preamble.js')
-rw-r--r-- | src/preamble.js | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/preamble.js b/src/preamble.js index a8f19d64..b3cfca85 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -24,6 +24,8 @@ var ACCEPTABLE_SAFE_HEAP_ERRORS = 0; function SAFE_HEAP_ACCESS(dest, type, store, ignore) { //if (dest === A_NUMBER) Module.print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging + assert(dest >= STACK_ROOT, 'segmentation fault: null pointer, or below normal memory'); + #if USE_TYPED_ARRAYS // When using typed arrays, reads over the top of TOTAL_MEMORY will fail silently, so we must // correct that by growing TOTAL_MEMORY as needed. Without typed arrays, memory is a normal @@ -639,13 +641,6 @@ var FAST_MEMORY = Module['FAST_MEMORY'] || {{{ FAST_MEMORY }}}; } #endif -var base = intArrayFromString('(null)'); // So printing %s of NULL gives '(null)' - // Also this ensures we leave 0 as an invalid address, 'NULL' -STATICTOP = base.length; -for (var i = 0; i < base.length; i++) { - {{{ makeSetValue(0, 'i', 'base[i]', 'i8') }}} -} - Module['HEAP'] = HEAP; #if USE_TYPED_ARRAYS == 1 Module['IHEAP'] = IHEAP; @@ -664,7 +659,7 @@ Module['HEAPF32'] = HEAPF32; Module['HEAPF64'] = HEAPF64; #endif -STACK_ROOT = STACKTOP = Runtime.alignMemory(STATICTOP); +STACK_ROOT = STACKTOP = Runtime.alignMemory(1); STACK_MAX = STACK_ROOT + TOTAL_STACK; #if USE_TYPED_ARRAYS == 2 @@ -694,6 +689,8 @@ STACK_MAX = tempDoublePtr + 8; STATICTOP = alignMemoryPage(STACK_MAX); +var nullString = allocate(intArrayFromString('(null)'), 'i8', ALLOC_STATIC); + function callRuntimeCallbacks(callbacks) { while(callbacks.length > 0) { var callback = callbacks.shift(); @@ -723,9 +720,9 @@ function exitRuntime() { } function String_len(ptr) { - var i = 0; - while ({{{ makeGetValue('ptr', 'i', 'i8') }}}) i++; // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds - return i; + var i = ptr; + while ({{{ makeGetValue('i++', '0', 'i8') }}}) {}; // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds + return i - ptr - 1; } Module['String_len'] = String_len; |