-
Notifications
You must be signed in to change notification settings - Fork 3.5k
NO_EXIT_RUNTIME by default #5878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 34 commits
17ef4e3
f3eb364
1106aed
05f07be
3d623eb
7ca10a1
ac6a066
fa0f631
9e299c5
890c5ea
bc3abe8
1655df2
268a781
1da0890
b80bdf7
0f6e8fa
2672778
49a5234
b8daf47
ce7b4f4
15a7083
1af3ea8
04ce11d
6ac52fb
748f2eb
d2c4f19
0611661
096f7ec
e040af1
39ef944
e6e1bc4
f04b0cd
5e81d11
43401c9
72e7255
4dc9381
6bf8d53
195a99c
04c3a9a
be26e6b
f6167e7
f8dadc6
9821ad7
9aa1ddb
66345ff
7d5e86c
83059d2
4299787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,17 +311,58 @@ function run(args) { | |
| Module['run'] = run; | ||
|
|
||
| function exit(status, implicit) { | ||
| if (implicit && Module['noExitRuntime']) { | ||
| #if ASSERTIONS | ||
| Module.printErr('exit(' + status + ') implicitly called by end of main(), but noExitRuntime, so not exiting the runtime (you can use emscripten_force_exit, if you want to force a true shutdown)'); | ||
| #if NO_EXIT_RUNTIME == 1 | ||
| // compiler settings do not allow exiting the runtime, so flushing | ||
| // the streams is not possible. but in ASSERTIONS mode we check | ||
| // if there was something to flush, and if so tell the user they | ||
| // should request that the runtime be exitable. | ||
| // how we flush the streams depends on whether we are in NO_FILESYSTEM | ||
| // mode (which has its own special function for this; otherwise, all | ||
| // the code is inside libc) | ||
| #if NO_FILESYSTEM | ||
| var flush = {{{ '$flush_NO_FILESYSTEM' in addedLibraryItems ? 'flush_NO_FILESYSTEM' : 'null' }}}; | ||
| #else | ||
| var flush = {{{ '$FS' in addedLibraryItems ? 'FS.quit' : "Module['_fflush']" }}}; | ||
| #endif | ||
| if (flush) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite understand why we are doing this dance with module.print. If it's ok to just call the users's
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't normally even include I can add more of an explanation to the code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading that again it does seem less than obvious, good point. Added a comment. |
||
| var print = Module['print']; | ||
| var printErr = Module['printErr']; | ||
| var has = false; | ||
| Module['print'] = Module['printErr'] = function(x) { | ||
| has = true; | ||
| } | ||
| try { // it doesn't matter if it fails | ||
| flush(0); | ||
| } catch(e) {} | ||
| Module['print'] = print; | ||
| Module['printErr'] = printErr; | ||
| if (has) { | ||
| Runtime.warnOnce('stdio streams had content in them that was not flushed. you should set NO_EXIT_RUNTIME to 0'); | ||
| } | ||
| } | ||
| #endif // NO_EXIT_RUNTIME | ||
| #endif // ASSERTIONS | ||
|
|
||
| // if this is just main exit-ing implicitly, and the status is 0, then we | ||
| // don't need to do anything here and can just leave. if the status is | ||
| // non-zero, though, then we need to report it. | ||
| // (we may have warned about this earlier, if a situation justifies doing so) | ||
| if (implicit && Module['noExitRuntime'] && status === 0) { | ||
| return; | ||
| } | ||
|
|
||
| if (Module['noExitRuntime']) { | ||
| #if ASSERTIONS | ||
| Module.printErr('exit(' + status + ') called, but noExitRuntime, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)'); | ||
| #endif | ||
| // if exit() was called, we may warn the user if the runtime isn't actually being shut down | ||
| if (!implicit) { | ||
| #if NO_EXIT_RUNTIME | ||
| Module.printErr('exit(' + status + ') called, but compiled with NO_EXIT_RUNTIME, so halting execution but not exiting the runtime or preventing further async execution (build with NO_EXIT_RUNTIME=0, if you want a true shutdown)'); | ||
| #else | ||
| Module.printErr('exit(' + status + ') called, but noExitRuntime, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)'); | ||
|
||
| #endif // NO_EXIT_RUNTIME | ||
| } | ||
| #endif // ASSERTIONS | ||
| } else { | ||
| #if USE_PTHREADS | ||
| PThread.terminateAllThreads(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably use some more detail or a link to a doc. Also in C++, if the user has any static objects with destructors, then those destructors get registered with atexit under the hood. so the doc or message should probably mention that case explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, added a FAQ entry about that, and mentioned the FAQ in those messages.