diff --git a/emcc.py b/emcc.py index f0ef4e95b2664..8b254b9fe3fbc 100755 --- a/emcc.py +++ b/emcc.py @@ -2492,6 +2492,10 @@ def check_memory_setting(setting): # MINIMAL_RUNTIME only needs callRuntimeCallbacks in certain cases, but the normal runtime # always does. settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$callRuntimeCallbacks'] + if settings.EXIT_RUNTIME or settings.USE_PTHREADS: + # Use by callMain + # TODO(sbc): have callMain use callUserCallback instead. + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$runtimeKeepalivePush', '$runtimeKeepalivePop'] if settings.EXIT_RUNTIME and not settings.STANDALONE_WASM: # Internal function implemented in musl that calls any functions registered diff --git a/src/postamble.js b/src/postamble.js index 777164c4af134..5ad5f24b5f9c8 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -167,7 +167,9 @@ function callMain(args) { // that if we get here main returned zero. var ret = 0; #else + {{{ runtimeKeepalivePush() }}} var ret = entryFunction(argc, argv); + {{{ runtimeKeepalivePop() }}} #endif // STANDALONE_WASM #if BENCHMARK diff --git a/tests/browser/test_glfw3.c b/tests/browser/test_glfw3.c index 41da337dc7425..75e79fb3f21f1 100644 --- a/tests/browser/test_glfw3.c +++ b/tests/browser/test_glfw3.c @@ -41,8 +41,14 @@ assert(glfwSet##Function(Value) == Value); /* The previously set callback */ assert(glfwSet##Function(Window, Value) == NULL); /* Default value (no callback was set) */ \ assert(glfwSet##Function(Window, Value) == Value); /* The previously set callback */ -int main() -{ +static int exited = 0; + +__attribute__((destructor)) +void onExit() { + exited = 1; +} + +int main() { GLFWwindow *window; char *userptr = "userptr"; @@ -121,9 +127,11 @@ int main() glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); + assert(exited == 0); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); + assert(exited == 0); // XXX: not implemented // glfwIconifyWindow(window); @@ -210,9 +218,6 @@ int main() #endif glfwTerminate(); - -#ifdef REPORT_RESULT - REPORT_RESULT(1); -#endif + printf("done\n"); return 0; } diff --git a/tests/test_browser.py b/tests/test_browser.py index cf7d3289889bb..9855dbfdb196c 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -2881,7 +2881,7 @@ def in_html(expected): def test_glfw3(self, args): for opts in [[], ['-sLEGACY_GL_EMULATION'], ['-Os', '--closure=1']]: print(opts) - self.btest(test_file('browser/test_glfw3.c'), args=['-sUSE_GLFW=3', '-lglfw', '-lGL'] + args + opts, expected='1') + self.btest_exit(test_file('browser/test_glfw3.c'), args=['-sUSE_GLFW=3', '-lglfw', '-lGL'] + args + opts) @requires_graphics_hardware def test_glfw_events(self):