pass NO_EXIT_RUNTIME flag to fastcomp and add test

This commit is contained in:
Alon Zakai 2014-02-25 18:31:05 -08:00
Родитель e2d05d569d
Коммит 01efb0bfc5
2 изменённых файлов: 41 добавлений и 1 удалений

5
emcc
Просмотреть файл

@ -1180,7 +1180,10 @@ try:
logging.warning('jcache is deprecated and not supported in fastcomp (you should not need it anyhow), disabling')
jcache = False
fastcomp_opts = ['-pnacl-abi-simplify-preopt', '-pnacl-abi-simplify-postopt']
fastcomp_opts = []
if shared.Settings.NO_EXIT_RUNTIME:
fastcomp_opts += ['-emscripten-no-exit-runtime', '-globaldce']
fastcomp_opts += ['-pnacl-abi-simplify-preopt', '-pnacl-abi-simplify-postopt']
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
fastcomp_opts += ['-enable-emscripten-cxx-exceptions']
if len(shared.Settings.EXCEPTION_CATCHING_WHITELIST) > 0:

Просмотреть файл

@ -2391,3 +2391,40 @@ int main() {
assert 'emcc: warning: unaligned store' in output[1]
assert '@line 9 "src.cpp"' in output[1]
def test_no_exit_runtime(self):
open('code.cpp', 'w').write(r'''
#include <stdio.h>
template<int x>
struct Waste {
Waste() {
printf("coming around %d\n", x);
}
~Waste() {
printf("going away %d\n", x);
}
};
Waste<1> w1;
Waste<2> w2;
Waste<3> w3;
Waste<4> w4;
Waste<5> w5;
int main(int argc, char **argv) {
return 0;
}
''')
for no_exit in [0, 1]:
for opts in [0, 1]:
print no_exit, opts
Popen([PYTHON, EMCC, '-O' + str(opts), 'code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate()
output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
src = open('a.out.js').read()
exit = 1-no_exit
assert 'coming around' in output
assert ('going away' in output) == exit, 'destructors should not run if no exit'
assert ('_ZN5WasteILi2EED1Ev' in src) == exit, 'destructors should not appear if no exit'
assert ('atexit(' in src) == exit, 'atexit should not appear or be called'