I think creating a new C method to call multiple times is best. The C standard just doesn't expect main() to be called more than once, and this has effects on things like initialization, atexit, etc.
On Thu, Feb 25, 2016 at 1:48 PM, Marcos Scriven <[email protected]> wrote: > I've compiled a command line utility that takes a file as an argument, and > can print out a little report to stdout. It works fine for a single call. > > Because I'd like the utility to work on the same file for multiple calls, > I've tried setting 'noExitRuntime:true', and 'noInitialRun: true', which > had seemed to have the desired effect. > > However, the second time I call Module['callMain']([]);, the program > errors out, saying the file is not a vaild file that it would expect > (that's to say output you'd expect from the native program to stderr when > the file you passed in was not the type it expected). > > I even tried simply calling the main method twice in succession (in case > something was going wrong with setting up the file a second time), but the > error was the same. > > I note looking through the Emscripten-generated Javascript that callMain > allocates argv every time - should I be avoiding this as an entry point? > > I'd rather not have to create a simple C main method, to compile to > Javascript just to wrap the original main method. > > (Incidentally, 'noInitialRun' is a little confusion - 'noInitialMainCall' > would be closer so far as I understand it?) > > Cut-down snippet of my worker code: > > var Module = { > noExitRuntime: true, > noInitialRun: true, > ... > } > > importScripts("emscripten-compiled.js"); > > > onmessage = function(e) { > console.log("Run main."); > FS.createDataFile('/', filename, e.data.romFile, true, false); > > // First call works > Module['callMain']([filename, "print"]); > > // Second call works, but program see the file as corrupt > Module['callMain']([filename, "print"]); > }; > > > -- > 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 [email protected]. > 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
