aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-09-11 19:28:48 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-09-11 19:28:48 -0700
commitafa818a5cbc78bb862f0cae8b305c8033a5b0fc3 (patch)
tree7a96bfc921999e177f2d3e997df58a72cf410b9a /src
parent24e61522f29d3796c0a1d2736d6008006b2e4ad6 (diff)
parentb37876be6ebf3da38b657e413c80fc6d69560b76 (diff)
Merge branch 'incoming'
Diffstat (limited to 'src')
-rw-r--r--src/library.js8
-rw-r--r--src/library_browser.js21
-rw-r--r--src/parseTools.js3
-rw-r--r--src/preamble.js19
-rw-r--r--src/settings.js4
5 files changed, 25 insertions, 30 deletions
diff --git a/src/library.js b/src/library.js
index d2d61867..798a6f58 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2802,9 +2802,9 @@ LibraryManager.library = {
});
} else if (next == 's'.charCodeAt(0)) {
// String.
- var arg = getNextArg('i8*') || 0; // 0 holds '(null)'
+ var arg = getNextArg('i8*') || nullString;
var argLength = String_len(arg);
- if (precisionSet) argLength = Math.min(String_len(arg), precision);
+ if (precisionSet) argLength = Math.min(argLength, precision);
if (!flagLeftAlign) {
while (argLength < width--) {
ret.push(' '.charCodeAt(0));
@@ -3578,7 +3578,9 @@ LibraryManager.library = {
}
if (!whole && !fraction) {
- {{{ makeSetValue('endptr', 0, 'origin', '*') }}}
+ if (endptr) {
+ {{{ makeSetValue('endptr', 0, 'origin', '*') }}}
+ }
return 0;
}
diff --git a/src/library_browser.js b/src/library_browser.js
index bf235493..43732e5b 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -379,12 +379,6 @@ mergeInto(LibraryManager.library, {
emscripten_set_main_loop: function(func, fps) {
Module['noExitRuntime'] = true;
-#if PROFILE_MAIN_LOOP
- Module['totalTime'] = 0;
- Module['iterations'] = 0;
- Module['maxTime'] = 0;
-#endif
-
var jsFunc = FUNCTION_TABLE[func];
Browser.mainLoop.runner = function() {
if (Browser.mainLoop.queue.length > 0) {
@@ -414,18 +408,15 @@ mergeInto(LibraryManager.library, {
return;
}
-#if PROFILE_MAIN_LOOP
- var start = performance.now();
-#endif
+ if (Module['preMainLoop']) {
+ Module['preMainLoop']();
+ }
jsFunc();
-#if PROFILE_MAIN_LOOP
- var time = performance.now() - start;
- Module['totalTime'] += time;
- Module['iterations']++;
- Module['maxTime'] = Math.max(Module['maxTime'], time);
-#endif
+ if (Module['postMainLoop']) {
+ Module['postMainLoop']();
+ }
if (Browser.mainLoop.shouldPause) {
// catch pauses from the main loop itself
diff --git a/src/parseTools.js b/src/parseTools.js
index e37f3a99..80ba269b 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1265,6 +1265,9 @@ function makePointer(slab, pos, allocator, type) {
de = dedup(evaled);
if (de.length === 1 && de[0] === 0) {
slab = types.length;
+ if (USE_TYPED_ARRAYS == 2) {
+ types = ['i8']; // if data is zeros, we don't need type info
+ }
}
// TODO: if not all zeros, at least filter out items with type === 0. requires cleverness to know how to skip at runtime though. also
// be careful of structure padding
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;
diff --git a/src/settings.js b/src/settings.js
index 9f63622d..fe532bda 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -104,7 +104,9 @@ var CATCH_EXIT_CODE = 0; // If set, causes exit() to throw an exception object w
// terminated with an error message.
// Generated code debugging options
-var SAFE_HEAP = 0; // Check each write to the heap against a list of blocked addresses
+var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give a clear
+ // error on what would be segfaults in a native build (like deferencing
+ // 0). See preamble.js for the actual checks performed.
// If equal to 2, done on a line-by-line basis according to
// SAFE_HEAP_LINES, checking only the specified lines.
// If equal to 3, checking all *but* the specified lines. Note