aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc8
-rw-r--r--src/postamble.js11
-rw-r--r--tests/cmake/target_js/CMakeLists.txt4
-rw-r--r--tests/hello_malloc.cpp2
-rw-r--r--tests/hello_world.c2
-rw-r--r--tests/hello_world.cpp2
-rw-r--r--tests/hello_world.ll2
-rw-r--r--tests/hello_world_loop.cpp2
-rw-r--r--tests/hello_world_loop_malloc.cpp2
-rw-r--r--tests/test_core.py12
-rw-r--r--tests/test_other.py10
-rw-r--r--tests/twopart_main.cpp2
12 files changed, 39 insertions, 20 deletions
diff --git a/emcc b/emcc
index 773490fa..32f21def 100755
--- a/emcc
+++ b/emcc
@@ -310,6 +310,14 @@ Options that are modified or new in %s include:
optimization, so it will be minified
properly if closure compiler is run.
+ Note that the post js will typically run after
+ main() completes (unless there is something
+ async). In that case, main() will exit and
+ the post js will not be reached (just as if
+ you call exit() in C code). If you want to
+ prevent that, you can build with
+ -s NO_EXIT_RUNTIME=1
+
--embed-file <file> A file to embed inside the generated
JavaScript. The compiled code will be able
to access the file in the current directory
diff --git a/src/postamble.js b/src/postamble.js
index d4bd6514..eabb308e 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -84,9 +84,7 @@ Module['callMain'] = Module.callMain = function callMain(args) {
#endif
// if we're not running an evented main loop, it's time to exit
- if (!Module['noExitRuntime']) {
- exit(ret);
- }
+ exit(ret);
}
catch(e) {
if (e instanceof ExitStatus) {
@@ -159,6 +157,13 @@ function run(args) {
Module['run'] = Module.run = run;
function exit(status) {
+ if (Module['noExitRuntime']) {
+#if ASSERTIONS
+ Module.printErr('exit(' + status + ') called, but noExitRuntime, so not exiting');
+#endif
+ return;
+ }
+
ABORT = true;
EXITSTATUS = status;
STACKTOP = initialStackTop;
diff --git a/tests/cmake/target_js/CMakeLists.txt b/tests/cmake/target_js/CMakeLists.txt
index 244cc70a..a1b44ee1 100644
--- a/tests/cmake/target_js/CMakeLists.txt
+++ b/tests/cmake/target_js/CMakeLists.txt
@@ -9,9 +9,9 @@ file(GLOB postJsFiles post*.js)
file(GLOB libraryJsFiles jslibrary*.js)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
- SET(linkFlags "-g4")
+ SET(linkFlags "-g4 -s NO_EXIT_RUNTIME=1")
else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled.
- SET(linkFlags "-O2")
+ SET(linkFlags "-O2 -s NO_EXIT_RUNTIME=1")
endif()
SET(CMAKE_EXECUTABLE_SUFFIX ".js")
diff --git a/tests/hello_malloc.cpp b/tests/hello_malloc.cpp
index d3774f70..d4398c3b 100644
--- a/tests/hello_malloc.cpp
+++ b/tests/hello_malloc.cpp
@@ -13,6 +13,6 @@ int main() {
void *another = malloc(1024);
assert(another == allocs[0]);
printf("hello, world!\n");
- return 1;
+ return 0;
}
diff --git a/tests/hello_world.c b/tests/hello_world.c
index cad52a2c..eb47ea81 100644
--- a/tests/hello_world.c
+++ b/tests/hello_world.c
@@ -2,6 +2,6 @@
int main() {
printf("hello, world!\n");
- return 1;
+ return 0;
}
diff --git a/tests/hello_world.cpp b/tests/hello_world.cpp
index 441d892b..c5f69b9e 100644
--- a/tests/hello_world.cpp
+++ b/tests/hello_world.cpp
@@ -4,6 +4,6 @@ class Test {}; // This will fail in C mode
int main() {
printf("hello, world!\n");
- return 1;
+ return 0;
}
diff --git a/tests/hello_world.ll b/tests/hello_world.ll
index 7090b732..7bab7361 100644
--- a/tests/hello_world.ll
+++ b/tests/hello_world.ll
@@ -9,7 +9,7 @@ entry:
%retval = alloca i32, align 4
store i32 0, i32* %retval
%call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0))
- ret i32 1
+ ret i32 0
}
declare i32 @printf(i8*, ...)
diff --git a/tests/hello_world_loop.cpp b/tests/hello_world_loop.cpp
index 46ec9f23..17a85aac 100644
--- a/tests/hello_world_loop.cpp
+++ b/tests/hello_world_loop.cpp
@@ -16,6 +16,6 @@ int main() {
}
copy[strlen(copy)+1] = (int)&original; // force original to be on the stack
dump(copy);
- return 1;
+ return 0;
}
diff --git a/tests/hello_world_loop_malloc.cpp b/tests/hello_world_loop_malloc.cpp
index b9361834..dd95660c 100644
--- a/tests/hello_world_loop_malloc.cpp
+++ b/tests/hello_world_loop_malloc.cpp
@@ -16,6 +16,6 @@ int main() {
}
copy[strlen(copy)+1] = (int)&original; // force original to be on the stack
dump(copy);
- return 1;
+ return 0;
}
diff --git a/tests/test_core.py b/tests/test_core.py
index 747f656c..5b5e72e0 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1460,6 +1460,7 @@ too many setjmps in a function call, build with a higher value for MAX_SETJMPS''
if Settings.ASM_JS: return self.skip('uses report_stack without exporting')
Settings.INLINING_LIMIT = 50
+ Settings.NO_EXIT_RUNTIME = 1
src = r'''
#include <stdio.h>
@@ -1501,7 +1502,7 @@ too many setjmps in a function call, build with a higher value for MAX_SETJMPS''
''')
self.emcc_args += ['--pre-js', 'pre.js']
- self.do_run(src, '''reported\nExit Status: 1\npostRun\nok.\n''')
+ self.do_run(src, '''reported\n*0*\nExit Status: 0\npostRun\nok.\n''')
def test_class(self):
test_path = path_from_root('tests', 'core', 'test_class')
@@ -5155,6 +5156,7 @@ def process(filename):
Settings.CORRECT_OVERFLOWS = 1
Settings.CORRECT_SIGNS = 1
+ Settings.NO_EXIT_RUNTIME = 1
Building.COMPILER_TEST_OPTS += [
'-I' + path_from_root('tests', 'freetype', 'include'),
@@ -5281,6 +5283,8 @@ def process(filename):
self.emcc_args += ['--minify', '0'] # to compare the versions
+ Settings.NO_EXIT_RUNTIME = 1
+
def do_test():
self.do_run(open(path_from_root('tests', 'openjpeg', 'codec', 'j2k_to_image.c'), 'r').read(),
'Successfully generated', # The real test for valid output is in image_compare
@@ -6174,6 +6178,8 @@ def process(filename):
if self.emcc_args is not None and self.emcc_args != []: return self.skip('full LLVM opts optimize out all the code that uses the type')
Settings.RUNTIME_TYPE_INFO = 1
+ Settings.NO_EXIT_RUNTIME = 1
+ Settings.ASSERTIONS = 0
if Settings.QUANTUM_SIZE != 4: return self.skip('We assume normal sizes in the output here')
src = '''
@@ -6215,8 +6221,8 @@ def process(filename):
'''
self.do_run(src,
- '*ok:5*\n|i32,i8,i16|0,4,6|\n|0,4,8,10,12|\n|{"__size__":8,"x":0,"y":4,"z":6}|',
- post_build=post)
+ '*ok:5*\n|i32,i8,i16|0,4,6|\n|0,4,8,10,12|\n|{"__size__":8,"x":0,"y":4,"z":6}|',
+ post_build=post)
# Make sure that without the setting, we don't spam the .js with the type info
Settings.RUNTIME_TYPE_INFO = 0
diff --git a/tests/test_other.py b/tests/test_other.py
index 1236b51b..d982145f 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1594,7 +1594,7 @@ This pointer might make sense in another type signature: i: 0
Module.print(MESSAGE);
''')
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'before.js', '--post-js', 'after.js']).communicate()
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'before.js', '--post-js', 'after.js', '-s', 'NO_EXIT_RUNTIME=1']).communicate()
self.assertContained('hello from main\nhello from js\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
def test_sdl_endianness(self):
@@ -1738,7 +1738,7 @@ This pointer might make sense in another type signature: i: 0
};
''')
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js']).communicate()
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js', '-s', 'NO_EXIT_RUNTIME=1']).communicate()
self.assertContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
# never run, so no preRun or postRun
@@ -1749,7 +1749,7 @@ This pointer might make sense in another type signature: i: 0
# noInitialRun prevents run
for no_initial_run, run_dep in [(0, 0), (1, 0), (0, 1)]:
print no_initial_run, run_dep
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')]).communicate()
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-s', 'NO_EXIT_RUNTIME=1']).communicate()
src = 'var Module = { noInitialRun: %d };\n' % no_initial_run + open(os.path.join(self.get_dir(), 'a.out.js')).read()
if run_dep:
src = src.replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\naddRunDependency("test");') \
@@ -1772,7 +1772,7 @@ This pointer might make sense in another type signature: i: 0
preInit: function() { Module.print('pre-init') }
};
''')
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js']).communicate()
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js', '-s', 'NO_EXIT_RUNTIME=1']).communicate()
self.assertContained('pre-init\npre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
def test_prepost2(self):
@@ -1791,7 +1791,7 @@ This pointer might make sense in another type signature: i: 0
open(os.path.join(self.get_dir(), 'pre2.js'), 'w').write('''
Module.postRun = function() { Module.print('post-run') };
''')
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js', '--pre-js', 'pre2.js']).communicate()
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js', '--pre-js', 'pre2.js', '-s', 'NO_EXIT_RUNTIME=1']).communicate()
self.assertContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
def test_prepre(self):
diff --git a/tests/twopart_main.cpp b/tests/twopart_main.cpp
index 6fac53c6..d4e73a86 100644
--- a/tests/twopart_main.cpp
+++ b/tests/twopart_main.cpp
@@ -3,6 +3,6 @@ extern void theFunc(char *str);
int main() {
theFunc("hello from main");
- return 1;
+ return 0;
}