--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'm assuming you don't want to use postRun for a function named wasm_init? Of those hooks, you'd probably want to use preRun, which when I try it doesn't work with "Assertion failed: invalid handle for stdin (1)".My understanding of why printf doesn't work there is because postRun is ran after main returns, so the wasm runtime doesn't flush the written buffer, and preRun is called before the runtime is initialized.Looking at the timings in the run function (that calls Module['_main']) here: https://github.com/kripken/emscripten/blob/incoming/src/postamble.js#L222 , we want to run static initializers (that can print, at least) before we call main, but after the runtime is initialized. It looks like preMain is the right timing, but how to put callbacks there?We have a function, addOnPreMain, that does the trick: https://github.com/kripken/emscripten/blob/incoming/src/preamble.js#L1693 . So to do that, we create a post-script file, shell_post.js, with the contents:addOnPreMain(function() { Module.ccall('wasm_init', null, []); });Then we compile withemcc hello.c -s WASM=1 -o hello.html --shell-file shell.html --post-js shell_post.jsAnd our output is:printf wasm_initModule.print wasm_initprintf mainModule.print main
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.
On Tue, Aug 1, 2017 at 11:44 AM, Alon Zakai <alon...@gmail.com> wrote:
Yeah, I think the problem here is that the runtime is shut down (libc io streams are flushed and closed, etc.) after main() exits. If you build with -s NO_EXIT_RUNTIME=1 then it does print that out.We have assertions on calling into the runtime after it was shut down, and those aren't being hit here, sadly - they should have shown an error message with how to fix things. Looks like the bug is that wasm async compilation goes around those assertions, which we should fix. I'll look into it.
On Tue, Aug 1, 2017 at 11:41 AM, 'Jacob Gravelle' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
I'm assuming you don't want to use postRun for a function named wasm_init? Of those hooks, you'd probably want to use preRun, which when I try it doesn't work with "Assertion failed: invalid handle for stdin (1)".My understanding of why printf doesn't work there is because postRun is ran after main returns, so the wasm runtime doesn't flush the written buffer, and preRun is called before the runtime is initialized.Looking at the timings in the run function (that calls Module['_main']) here: https://github.com/kripken/emscripten/blob/incoming/src/postamble.js#L222 , we want to run static initializers (that can print, at least) before we call main, but after the runtime is initialized. It looks like preMain is the right timing, but how to put callbacks there?We have a function, addOnPreMain, that does the trick: https://github.com/kripken/emscripten/blob/incoming/src/preamble.js#L1693 . So to do that, we create a post-script file, shell_post.js, with the contents:addOnPreMain(function() { Module.ccall('wasm_init', null, []); });Then we compile withemcc hello.c -s WASM=1 -o hello.html --shell-file shell.html --post-js shell_post.jsAnd our output is:printf wasm_initModule.print wasm_initprintf mainModule.print main
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.